8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / hal / hal_btcoex.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2013 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #define __HAL_BTCOEX_C__
21
22 #ifdef CONFIG_BT_COEXIST
23
24 #include <hal_data.h>
25 #include <hal_btcoex.h>
26 #include <Mp_Precomp.h>
27
28 //====================================
29 //              Global variables
30 //====================================
31 const char *const BtProfileString[] =
32 {
33         "NONE",
34         "A2DP",
35         "PAN",
36         "HID",
37         "SCO",
38 };
39
40 const char *const BtSpecString[] =
41 {
42         "1.0b",
43         "1.1",
44         "1.2",
45         "2.0+EDR",
46         "2.1+EDR",
47         "3.0+HS",
48         "4.0",
49 };
50
51 const char *const BtLinkRoleString[] =
52 {
53         "Master",
54         "Slave",
55 };
56
57 const char *const h2cStaString[] =
58 {
59         "successful",
60         "h2c busy",
61         "rf off",
62         "fw not read",
63 };
64
65 const char *const ioStaString[] =
66 {
67         "success",
68         "can not IO",
69         "rf off",
70         "fw not read",
71         "wait io timeout",
72         "invalid len",
73         "idle Q empty",
74         "insert waitQ fail",
75         "unknown fail",
76         "wrong level",
77         "h2c stopped",
78 };
79
80 const char *const GLBtcWifiBwString[]={
81         "11bg",
82         "HT20",
83         "HT40",
84         "HT80",
85         "HT160"
86 };
87
88 const char *const GLBtcWifiFreqString[]={
89         "2.4G",
90         "5G"
91 };
92
93 const char *const GLBtcIotPeerString[] = {
94         "UNKNOWN",
95         "REALTEK",
96         "REALTEK_92SE",
97         "BROADCOM",
98         "RALINK",
99         "ATHEROS",
100         "CISCO",
101         "MERU", 
102         "MARVELL",
103         "REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
104         "SELF_SOFTAP", /* Self is SoftAP */
105         "AIRGO",
106         "INTEL", 
107         "RTK_APCLIENT", 
108         "REALTEK_81XX", 
109         "REALTEK_WOW",
110         "REALTEK_JAGUAR_BCUTAP",
111         "REALTEK_JAGUAR_CCUTAP"
112 };
113
114 #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS       8000
115
116 BTC_COEXIST GLBtCoexist;
117 u8 GLBtcWiFiInScanState;
118 u8 GLBtcWiFiInIQKState;
119 u8 GLBtcWiFiInIPS;
120 u8 GLBtcWiFiInLPS;
121 u8 GLBtcBtCoexAliveRegistered;
122
123 u32 GLBtcDbgType[COMP_MAX];
124 u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
125
126 typedef struct _btcoexdbginfo
127 {
128         u8 *info;
129         u32 size; // buffer total size
130         u32 len; // now used length
131 } BTCDBGINFO, *PBTCDBGINFO;
132
133 BTCDBGINFO GLBtcDbgInfo;
134
135 #define BT_Operation(Adapter)                                           _FALSE
136
137 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
138 {
139         if (NULL == pinfo) return;
140
141         _rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
142
143         if (pbuf && size) {
144                 pinfo->info = pbuf;
145                 pinfo->size = size;
146         }
147 }
148
149 void DBG_BT_INFO(u8 *dbgmsg)
150 {
151         PBTCDBGINFO pinfo;
152         u32 msglen, buflen;
153         u8 *pbuf;
154
155
156         pinfo = &GLBtcDbgInfo;
157
158         if (NULL == pinfo->info)
159                 return;
160
161         msglen = strlen(dbgmsg);
162         if (pinfo->len + msglen > pinfo->size)
163                 return;
164
165         pbuf = pinfo->info + pinfo->len;
166         _rtw_memcpy(pbuf, dbgmsg, msglen);
167         pinfo->len += msglen;
168 }
169
170 //====================================
171 //              Debug related function
172 //====================================
173 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
174 {
175         if (!pBtCoexist->bBinded ||
176                 NULL == pBtCoexist->Adapter)
177         {
178                 return _FALSE;
179         }
180         return _TRUE;
181 }
182
183 static void halbtcoutsrc_DbgInit(void)
184 {
185         u8      i;
186
187         for (i = 0; i < COMP_MAX; i++)
188                 GLBtcDbgType[i] = 0;
189 }
190
191 static u8 halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)
192 {
193         if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
194                 || pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
195         ){
196                 return _TRUE;
197         }
198         return _FALSE;
199 }
200
201 static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
202 {
203         if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
204                 || pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
205         ){
206                 return _FALSE;
207         }
208         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
209         {
210                 return _FALSE;
211         }
212         else
213                 return _TRUE;
214 }
215
216 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
217 {
218         PADAPTER padapter;
219
220
221         padapter = pBtCoexist->Adapter;
222
223         pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
224         pBtCoexist->btInfo.bBtLpsOn = _FALSE;
225
226         rtw_btcoex_LPS_Leave(padapter);
227 }
228
229 void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
230 {
231         PADAPTER padapter;
232
233
234         padapter = pBtCoexist->Adapter;
235
236         pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
237         pBtCoexist->btInfo.bBtLpsOn = _TRUE;
238
239         rtw_btcoex_LPS_Enter(padapter);
240 }
241
242 void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
243 {
244         PADAPTER padapter;
245
246
247         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Normal LPS behavior!!!\n"));
248
249         padapter = pBtCoexist->Adapter;
250
251         if (pBtCoexist->btInfo.bBtCtrlLps)
252         {
253                 pBtCoexist->btInfo.bBtLpsOn = _FALSE;
254                 rtw_btcoex_LPS_Leave(padapter);
255                 pBtCoexist->btInfo.bBtCtrlLps = _FALSE;
256
257                 // recover the LPS state to the original
258 #if 0
259                 padapter->HalFunc.UpdateLPSStatusHandler(
260                         padapter,
261                         pPSC->RegLeisurePsMode,
262                         pPSC->RegPowerSaveMode);
263 #endif
264         }
265 }
266
267 /*
268  *  Constraint:
269  *         1. this function will request pwrctrl->lock
270  */
271 void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
272 {
273 #ifdef CONFIG_LPS_LCLK
274         PADAPTER padapter;
275         PHAL_DATA_TYPE pHalData;
276         struct pwrctrl_priv *pwrctrl;
277         s32 ready;
278         u32 stime;
279         s32 utime;
280         u32 timeout; // unit: ms
281
282
283         padapter = pBtCoexist->Adapter;
284         pHalData = GET_HAL_DATA(padapter);
285         pwrctrl = adapter_to_pwrctl(padapter);
286         ready = _FAIL;
287 #ifdef LPS_RPWM_WAIT_MS
288         timeout = LPS_RPWM_WAIT_MS;
289 #else // !LPS_RPWM_WAIT_MS
290         timeout = 30;
291 #endif // !LPS_RPWM_WAIT_MS
292
293         if (GLBtcBtCoexAliveRegistered == _TRUE)
294                 return;
295
296         stime = rtw_get_current_time();
297         do {
298                 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
299                 if (_SUCCESS == ready)
300                         break;
301
302                 utime = rtw_get_passing_time_ms(stime);
303                 if (utime > timeout)
304                         break;
305
306                 rtw_msleep_os(1);
307         } while (1);
308
309         GLBtcBtCoexAliveRegistered = _TRUE;
310 #endif // CONFIG_LPS_LCLK
311 }
312
313 /*
314  *  Constraint:
315  *         1. this function will request pwrctrl->lock
316  */
317 void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
318 {
319 #ifdef CONFIG_LPS_LCLK
320         PADAPTER padapter;
321
322         if (GLBtcBtCoexAliveRegistered == _FALSE)
323                 return;
324
325         padapter = pBtCoexist->Adapter;
326         rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
327
328         GLBtcBtCoexAliveRegistered = _FALSE;
329 #endif // CONFIG_LPS_LCLK
330 }
331
332 void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
333 {
334         pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
335         if (bLowPwrDisable)
336                 halbtcoutsrc_LeaveLowPower(pBtCoexist);         // leave 32k low power.
337         else
338                 halbtcoutsrc_NormalLowPower(pBtCoexist);        // original 32k low power behavior.
339 }
340
341 void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
342 {
343         PADAPTER padapter;
344         BOOLEAN bNeedToAct = _FALSE;
345         static u32 preTime = 0;
346         u32 curTime = 0;
347
348         padapter = pBtCoexist->Adapter;
349
350         //=====================================
351         // To void continuous deleteBA=>addBA=>deleteBA=>addBA
352         // This function is not allowed to continuous called.
353         // It can only be called after 8 seconds.
354         //=====================================
355
356         curTime = rtw_systime_to_ms(rtw_get_current_time());
357         if((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS)     // over 8 seconds you can execute this function again.
358         {
359                 return;
360         }
361         else
362         {
363                 preTime = curTime;
364         }
365
366         if (pBtCoexist->btInfo.bRejectAggPkt)
367         {
368                 bNeedToAct = _TRUE;
369                 pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
370         }
371         else
372         {
373                 if(pBtCoexist->btInfo.bPreRejectAggPkt)
374                 {
375                         bNeedToAct = _TRUE;
376                         pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
377                 }
378                 
379                 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
380                         pBtCoexist->btInfo.bBtCtrlAggBufSize)
381                 {
382                         bNeedToAct = _TRUE;
383                         pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
384                 }
385
386                 if (pBtCoexist->btInfo.bBtCtrlAggBufSize)
387                 {
388                         if (pBtCoexist->btInfo.preAggBufSize !=
389                                 pBtCoexist->btInfo.aggBufSize)
390                         {
391                                 bNeedToAct = _TRUE;
392                         }
393                         pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
394                 }
395         }
396
397         if (bNeedToAct)
398                 rtw_btcoex_rx_ampdu_apply(padapter);
399 }
400
401 u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
402 {
403         struct mlme_priv *pmlmepriv;
404
405
406         pmlmepriv = &padapter->mlmepriv;
407
408         if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
409         {
410                 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
411                         return _TRUE;
412                 if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
413                         return _TRUE;
414         }
415
416 #if defined(CONFIG_CONCURRENT_MODE)
417         pmlmepriv = &padapter->pbuddy_adapter->mlmepriv;
418
419         if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
420         {
421                 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
422                         return _TRUE;
423                 if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
424                         return _TRUE;
425         }
426 #endif
427
428         return _FALSE;
429 }
430
431 static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
432 {
433         struct mlme_priv *pmlmepriv;
434         u8 bp2p;
435         u32 portConnectedStatus;
436
437
438         pmlmepriv = &padapter->mlmepriv;
439         bp2p = _FALSE;
440         portConnectedStatus = 0;
441
442 #ifdef CONFIG_P2P
443         if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
444                 bp2p = _TRUE;
445 #endif // CONFIG_P2P
446
447         if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
448         {
449                 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
450                 {
451                         if (_TRUE == bp2p)
452                                 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
453                         else
454                                 portConnectedStatus |= WIFI_AP_CONNECTED;
455                 }
456                 else
457                 {
458                         if (_TRUE == bp2p)
459                                 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
460                         else
461                                 portConnectedStatus |= WIFI_STA_CONNECTED;
462                 }
463         }
464
465         return portConnectedStatus;
466 }
467
468 u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
469 {
470         //=================================
471         // return value:
472         // [31:16]=> connected port number
473         // [15:0]=> port connected bit define
474         //================================
475
476         PADAPTER padapter;
477         u32 retVal;
478         u32 portConnectedStatus, numOfConnectedPort;
479
480
481         padapter = pBtCoexist->Adapter;
482         retVal = 0;
483         portConnectedStatus = 0;
484         numOfConnectedPort = 0;
485
486         retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
487         if (retVal)
488         {
489                 portConnectedStatus |= retVal;
490                 numOfConnectedPort++;
491         }
492
493 #ifdef CONFIG_CONCURRENT_MODE
494         if (padapter->pbuddy_adapter)
495         {
496                 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter->pbuddy_adapter);
497                 if (retVal)
498                 {
499                         portConnectedStatus |= retVal;
500                         numOfConnectedPort++;
501                 }
502         }
503 #endif // CONFIG_CONCURRENT_MODE
504
505         retVal = (numOfConnectedPort << 16) | portConnectedStatus;
506         
507         return retVal;
508 }
509
510 u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
511 {
512         u16 btRealFwVer = 0x0;
513         u8 btFwVer = 0x0;
514         u8 cnt = 0;
515
516 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
517         if (!pBtCoexist->btInfo.btRealFwVer && cnt<=5)
518         {
519 #if 0
520                 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist))
521                 {       // mailbox exists, through mailbox
522                         if (NDBG_GetBtFwVersion(pBtCoexist->Adapter, &btRealFwVer, &btFwVer))
523                         {
524                                 pBtCoexist->btInfo.btRealFwVer = btRealFwVer;
525                                 pBtCoexist->btInfo.btFwVer = btFwVer;
526                         }
527                         else
528                         {
529                                 pBtCoexist->btInfo.btRealFwVer = 0x0;
530                                 pBtCoexist->btInfo.btFwVer = 0x0;
531                         }
532                 }
533                 else    // no mailbox, query bt patch version through stack.
534 #endif
535                 // query bt patch version through socket.
536                 {
537                         u1Byte  dataLen=2;
538                         u1Byte  buf[4] = {0};
539                         buf[0] = 0x0;   // OP_Code
540                         buf[1] = 0x0;   // OP_Code_Length
541                         BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
542                 }
543                 cnt++;
544         }
545 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
546         return pBtCoexist->btInfo.btRealFwVer;
547 }
548
549 s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
550 {
551         PHAL_DATA_TYPE pHalData;
552         s32 UndecoratedSmoothedPWDB = 0;
553
554         pHalData = GET_HAL_DATA(padapter);
555
556         UndecoratedSmoothedPWDB = pHalData->EntryMinUndecoratedSmoothedPWDB;
557
558         return UndecoratedSmoothedPWDB;
559 }
560
561 static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
562 {
563         struct mlme_priv *pmlmepriv;
564         struct mlme_ext_priv *pmlmeext;
565         static u8 scan_AP_num = 0;
566
567
568         pmlmepriv = &padapter->mlmepriv;
569         pmlmeext = &padapter->mlmeextpriv;
570
571         if (GLBtcWiFiInScanState == _FALSE) {
572                 if (pmlmepriv->num_of_scanned > 0xFF)
573                         scan_AP_num = 0xFF;
574                 else
575                         scan_AP_num = (u8)pmlmepriv->num_of_scanned;
576         }
577
578         return scan_AP_num;
579 }
580
581 u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
582 {
583         PBTC_COEXIST pBtCoexist;
584         PADAPTER padapter;
585         PHAL_DATA_TYPE pHalData;
586         struct mlme_ext_priv *mlmeext;
587         u8 bSoftApExist, bVwifiExist;
588         u8 *pu8;
589         s32 *pS4Tmp;
590         u32 *pU4Tmp;
591         u8 *pU1Tmp;
592         u8 ret;
593
594
595         pBtCoexist = (PBTC_COEXIST)pBtcContext;
596         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
597                 return _FALSE;
598
599         padapter = pBtCoexist->Adapter;
600         pHalData = GET_HAL_DATA(padapter);
601         mlmeext = &padapter->mlmeextpriv;
602         bSoftApExist = _FALSE;
603         bVwifiExist = _FALSE;
604         pu8 = (u8*)pOutBuf;
605         pS4Tmp = (s32*)pOutBuf;
606         pU4Tmp = (u32*)pOutBuf;
607         pU1Tmp = (u8*)pOutBuf;
608         ret = _TRUE;
609
610         switch (getType)
611         {
612                 case BTC_GET_BL_HS_OPERATION:
613                         *pu8 = _FALSE;
614                         ret = _FALSE;
615                         break;
616
617                 case BTC_GET_BL_HS_CONNECTING:
618                         *pu8 = _FALSE;
619                         ret = _FALSE;
620                         break;
621
622                 case BTC_GET_BL_WIFI_CONNECTED:
623                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
624 #ifdef CONFIG_CONCURRENT_MODE
625                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
626                         {
627                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_ASOC_STATE);
628                         }
629 #endif // CONFIG_CONCURRENT_MODE
630                         break;
631
632                 case BTC_GET_BL_WIFI_BUSY:
633                         *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
634                         break;
635
636                 case BTC_GET_BL_WIFI_SCAN:
637 #if 0                   
638                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_SITE_MONITOR);
639 #ifdef CONFIG_CONCURRENT_MODE
640                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
641                         {
642                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_SITE_MONITOR);
643                         }
644 #endif // CONFIG_CONCURRENT_MODE
645 #else           
646                         /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag 
647                                 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
648                         *pu8 = GLBtcWiFiInScanState;
649 #endif
650                         break;
651
652                 case BTC_GET_BL_WIFI_LINK:
653                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
654 #ifdef CONFIG_CONCURRENT_MODE
655                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
656                         {
657                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
658                         }
659 #endif // CONFIG_CONCURRENT_MODE
660                         break;
661
662                 case BTC_GET_BL_WIFI_ROAM:
663                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
664 #ifdef CONFIG_CONCURRENT_MODE
665                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
666                         {
667                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
668                         }
669 #endif // CONFIG_CONCURRENT_MODE
670                         break;
671
672                 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
673                         *pu8 = _FALSE;
674                         break;
675
676                 case BTC_GET_BL_WIFI_UNDER_5G:
677                         *pu8 = (pHalData->CurrentBandType == 1)? _TRUE : _FALSE;
678                         break;
679
680                 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
681                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
682 #ifdef CONFIG_CONCURRENT_MODE
683                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
684                         {
685                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_AP_STATE);
686                         }
687 #endif // CONFIG_CONCURRENT_MODE
688                         break;
689
690                 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
691                         *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0? _FALSE: _TRUE;
692                         break;
693
694                 case BTC_GET_BL_WIFI_UNDER_B_MODE:
695                         if (mlmeext->cur_wireless_mode == WIRELESS_11B)
696                                 *pu8 = _TRUE;
697                         else
698                                 *pu8 = _FALSE;
699                         break;
700
701                 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
702                         if (padapter->registrypriv.mp_mode == 0)
703                         {
704                                 *pu8 = _FALSE;
705                         }
706                         else
707                         {
708                                 *pu8 = _TRUE;
709                         }
710                         break;
711
712                 case BTC_GET_BL_EXT_SWITCH:
713                         *pu8 = _FALSE;
714                         break;
715                 case BTC_GET_BL_IS_ASUS_8723B:
716                         /* Always return FALSE in linux driver since this case is added only for windows driver */
717                         *pu8 = _FALSE;
718                         break;
719
720                 case BTC_GET_S4_WIFI_RSSI:
721                         *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
722                         break;
723
724                 case BTC_GET_S4_HS_RSSI:
725                         *pS4Tmp = 0;
726                         ret = _FALSE;
727                         break;
728
729                 case BTC_GET_U4_WIFI_BW:
730                         if (IsLegacyOnly(mlmeext->cur_wireless_mode))
731                                 *pU4Tmp = BTC_WIFI_BW_LEGACY;
732                         else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
733                                 *pU4Tmp = BTC_WIFI_BW_HT20;
734                         else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
735                                 *pU4Tmp = BTC_WIFI_BW_HT40;
736                         else
737                                 *pU4Tmp = BTC_WIFI_BW_HT40; /* todo */
738                         break;
739
740                 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
741                         {
742                                 PRT_LINK_DETECT_T plinkinfo;
743                                 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
744
745                                 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
746                                         *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
747                                 else
748                                         *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
749                         }
750                         break;
751
752                 case BTC_GET_U4_WIFI_FW_VER:
753                         *pU4Tmp = pHalData->FirmwareVersion << 16;
754                         *pU4Tmp |= pHalData->FirmwareSubVersion;
755                         break;
756
757                 case BTC_GET_U4_WIFI_LINK_STATUS:
758                         *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
759                         break;
760
761                 case BTC_GET_U4_BT_PATCH_VER:
762                         *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
763                         break;
764
765                 case BTC_GET_U1_WIFI_DOT11_CHNL:
766                         *pU1Tmp = padapter->mlmeextpriv.cur_channel;
767                         break;
768
769                 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
770                         *pU1Tmp = pHalData->CurrentChannel;
771                         break;
772
773                 case BTC_GET_U1_WIFI_HS_CHNL:
774                         *pU1Tmp = 0;
775                         ret = _FALSE;
776                         break;
777
778                 case BTC_GET_U1_MAC_PHY_MODE:
779 //                      *pU1Tmp = BTC_SMSP;
780 //                      *pU1Tmp = BTC_DMSP;
781 //                      *pU1Tmp = BTC_DMDP;
782 //                      *pU1Tmp = BTC_MP_UNKNOWN;
783                         break;
784
785                 case BTC_GET_U1_AP_NUM:
786                         *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
787                         break;
788                 case BTC_GET_U1_ANT_TYPE:
789                         switch(pHalData->bt_coexist.btAntisolation)
790                         {
791                                 case 0:
792                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_0;
793                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_0;
794                                         break;
795                                 case 1:
796                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_1;
797                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_1;
798                                         break;
799                                 case 2:
800                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_2;
801                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_2;
802                                         break;
803                                 case 3:
804                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_3;
805                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_3;
806                                         break;
807                                 case 4:
808                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_4;
809                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_4;
810                                         break;
811                         }
812                         break;
813                 case BTC_GET_U1_IOT_PEER:
814                         *pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
815                         break;
816
817                 //=======1Ant===========
818                 case BTC_GET_U1_LPS_MODE:
819                         *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
820                         break;
821
822                 default:
823                         ret = _FALSE;
824                         break;
825         }
826
827         return ret;
828 }
829
830 u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
831 {
832         PBTC_COEXIST pBtCoexist;
833         PADAPTER padapter;
834         PHAL_DATA_TYPE pHalData;
835         u8 *pu8;
836         u8 *pU1Tmp;
837         u32     *pU4Tmp;
838         u8 ret;
839
840
841         pBtCoexist = (PBTC_COEXIST)pBtcContext;
842         padapter = pBtCoexist->Adapter;
843         pHalData = GET_HAL_DATA(padapter);
844         pu8 = (u8*)pInBuf;
845         pU1Tmp = (u8*)pInBuf;
846         pU4Tmp = (u32*)pInBuf;
847         ret = _TRUE;
848
849         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
850                 return _FALSE;
851
852         switch (setType)
853         {
854                 // set some u8 type variables.
855                 case BTC_SET_BL_BT_DISABLE:
856                         pBtCoexist->btInfo.bBtDisabled = *pu8;
857                         break;
858
859                 case BTC_SET_BL_BT_TRAFFIC_BUSY:
860                         pBtCoexist->btInfo.bBtBusy = *pu8;
861                         break;
862
863                 case BTC_SET_BL_BT_LIMITED_DIG:
864                         pBtCoexist->btInfo.bLimitedDig = *pu8;
865                         break;
866
867                 case BTC_SET_BL_FORCE_TO_ROAM:
868                         pBtCoexist->btInfo.bForceToRoam = *pu8;
869                         break;
870
871                 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
872                         pBtCoexist->btInfo.bRejectAggPkt = *pu8;
873                         break;
874
875                 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
876                         pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
877                         break;
878
879                 case BTC_SET_BL_INC_SCAN_DEV_NUM:
880                         pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
881                         break;
882
883                 case BTC_SET_BL_BT_TX_RX_MASK:
884                         pBtCoexist->btInfo.bBtTxRxMask = *pu8;
885                         break;
886
887                 case BTC_SET_BL_MIRACAST_PLUS_BT:
888                         pBtCoexist->btInfo.bMiracastPlusBt = *pu8;
889                         break;
890
891                 // set some u8 type variables.
892                 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
893                         pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pU1Tmp;
894                         break;
895
896                 case BTC_SET_U1_AGG_BUF_SIZE:
897                         pBtCoexist->btInfo.aggBufSize = *pU1Tmp;
898                         break;
899
900                 // the following are some action which will be triggered
901                 case BTC_SET_ACT_GET_BT_RSSI:
902 #if 0
903                         BT_SendGetBtRssiEvent(padapter);
904 #else
905                         ret = _FALSE;
906 #endif
907                         break;
908
909                 case BTC_SET_ACT_AGGREGATE_CTRL:
910                         halbtcoutsrc_AggregationCheck(pBtCoexist);
911                         break;
912
913                 //=======1Ant===========
914                 // set some u8 type variables.
915                 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
916                         pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pU1Tmp;
917                         break;
918
919                 case BTC_SET_U1_LPS_VAL:
920                         pBtCoexist->btInfo.lpsVal = *pU1Tmp;
921                         break;
922
923                 case BTC_SET_U1_RPWM_VAL:
924                         pBtCoexist->btInfo.rpwmVal = *pU1Tmp;
925                         break;
926
927                 // the following are some action which will be triggered
928                 case BTC_SET_ACT_LEAVE_LPS:
929                         halbtcoutsrc_LeaveLps(pBtCoexist);
930                         break;
931
932                 case BTC_SET_ACT_ENTER_LPS:
933                         halbtcoutsrc_EnterLps(pBtCoexist);
934                         break;
935
936                 case BTC_SET_ACT_NORMAL_LPS:
937                         halbtcoutsrc_NormalLps(pBtCoexist);
938                         break;
939
940                 case BTC_SET_ACT_DISABLE_LOW_POWER:
941                         halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
942                         break;
943
944                 case BTC_SET_ACT_UPDATE_RAMASK:
945                         pBtCoexist->btInfo.raMask = *pU4Tmp;
946
947                         if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE)
948                         {
949                                 struct sta_info *psta;
950                                 PWLAN_BSSID_EX cur_network;
951
952                                 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
953                                 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
954                                 rtw_hal_update_ra_mask(psta, 0);
955                         }
956                         break;
957
958                 case BTC_SET_ACT_SEND_MIMO_PS:
959                         {
960                                 u8 newMimoPsMode = 3;
961                                 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
962                                 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
963
964                                 /* *pU1Tmp = 0 use SM_PS static type */
965                                 /* *pU1Tmp = 1 disable SM_PS */
966                                 if (*pU1Tmp == 0)
967                                         newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
968                                 else if (*pU1Tmp == 1)
969                                         newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
970                                                                                                   
971                                 if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {
972                                         /* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */
973                                         issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);
974                                 }
975                         }
976                         break;
977
978                 case BTC_SET_ACT_CTRL_BT_INFO:
979 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
980                         {
981                                 u8 dataLen = *pU1Tmp;
982                                 u8 tmpBuf[20];
983                                 if (dataLen)
984                                 {
985                                         _rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
986                                 }
987                                 BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
988                         }
989 #else //!CONFIG_BT_COEXIST_SOCKET_TRX
990                         ret = _FALSE;
991 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
992                         break;
993
994                 case BTC_SET_ACT_CTRL_BT_COEX:
995 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
996                         {
997                                 u8 dataLen = *pU1Tmp;
998                                 u8 tmpBuf[20];
999                                 if (dataLen)
1000                                 {
1001                                         _rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
1002                                 }
1003                                 BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
1004                         }
1005 #else //!CONFIG_BT_COEXIST_SOCKET_TRX
1006                         ret = _FALSE;
1007 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
1008                         break;
1009                 case BTC_SET_ACT_CTRL_8723B_ANT:
1010 #if 0
1011                         {
1012                                 u1Byte  dataLen=*pU1Tmp;
1013                                 u1Byte  tmpBuf[20];
1014                                 if(dataLen)
1015                                 {
1016                                         PlatformMoveMemory(&tmpBuf[0], pU1Tmp+1, dataLen);
1017                                 }
1018                                 BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
1019                         }
1020 #else
1021                         ret = _FALSE;
1022 #endif
1023                         break;
1024                 //=====================
1025                 default:
1026                         ret = _FALSE;
1027                         break;
1028         }
1029
1030         return ret;
1031 }
1032
1033 u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
1034 {
1035         PADAPTER padapter;
1036         struct pwrctrl_priv *pwrpriv;
1037         u8 bMacPwrCtrlOn;
1038
1039         padapter = pBtCoexist->Adapter;
1040         pwrpriv = &padapter->dvobj->pwrctl_priv;
1041         bMacPwrCtrlOn = _FALSE;
1042
1043         if ((_TRUE == pwrpriv->bips_processing)
1044                 && (IPS_NONE != pwrpriv->ips_mode_req)
1045                 )
1046         {
1047                 return _TRUE;
1048         }
1049
1050         if (rf_off == pwrpriv->rf_pwrstate)
1051         {
1052                 return _TRUE;
1053         }
1054
1055         rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1056         if (_FALSE == bMacPwrCtrlOn)
1057         {
1058                 return _TRUE;
1059         }
1060
1061         return _FALSE;
1062 }
1063
1064 u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
1065 {
1066         return GLBtcWiFiInLPS;
1067 }
1068
1069 u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
1070 {
1071         /* todo: the method to check whether wifi is under 32K or not */
1072         return _FALSE;
1073 }
1074
1075 void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
1076 {
1077 #if 0
1078         PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1079         PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1080         PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1081         u8 *cliBuf = pBtCoexist->cliBuf;
1082         u8 i;
1083
1084         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
1085         CL_PRINTF(cliBuf);
1086
1087 #if (H2C_USE_IO_THREAD != 1)
1088         for(i=0; i<H2C_STATUS_MAX; i++)
1089         {
1090                 if (pHalData->h2cStatistics[i])
1091                 {
1092                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1093                                 h2cStaString[i], pHalData->h2cStatistics[i]);
1094                         CL_PRINTF(cliBuf);
1095                 }
1096         }
1097 #else
1098                 for(i=0; i<IO_STATUS_MAX; i++)
1099                 {
1100                         if(Adapter->ioComStr.ioH2cStatistics[i])
1101                         {
1102                                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1103                                         ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
1104                                 CL_PRINTF(cliBuf);
1105                         }
1106                 }
1107 #endif
1108 #if 0
1109         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
1110                 pHalData->LastHMEBoxNum);
1111         CL_PRINTF(cliBuf);
1112         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
1113                 pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
1114         CL_PRINTF(cliBuf);
1115
1116         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
1117                 pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
1118                 DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
1119         CL_PRINTF(cliBuf);
1120
1121         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
1122                 DBG_Var.c2hPacketCnt);
1123         CL_PRINTF(cliBuf);
1124 #endif
1125         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
1126                 pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
1127         CL_PRINTF(cliBuf);
1128         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
1129                 pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
1130                 pBtCoexist->statistics.cntRfStatusNotify);
1131         CL_PRINTF(cliBuf);
1132         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
1133                 pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
1134                 pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
1135                 pBtCoexist->statistics.cntMediaStatusNotify);
1136         CL_PRINTF(cliBuf);
1137         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind", 
1138                 pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,
1139                 pBtCoexist->statistics.cntBind);
1140         CL_PRINTF(cliBuf);
1141 #endif
1142 }
1143
1144 void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
1145 {
1146 #if 0
1147         PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1148         PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1149         u8 *cliBuf = pBtCoexist->cliBuf;
1150         u8 i;
1151
1152
1153         if (pBtCoexist->stackInfo.bProfileNotified)
1154         {
1155                 for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
1156                 {
1157                         if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1)
1158                         {
1159                                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
1160                                         BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1161                                         BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
1162                                         BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
1163                                 CL_PRINTF(cliBuf);                              }
1164                         else
1165                         {
1166                                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
1167                                         BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1168                                         BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
1169                                 CL_PRINTF(cliBuf);
1170                         }
1171                 }
1172         }
1173 #endif
1174 }
1175
1176 void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
1177 {
1178         PADAPTER        padapter = pBtCoexist->Adapter;
1179         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1180         u8*                     cliBuf=pBtCoexist->cliBuf;
1181         s32                     wifiRssi=0, btHsRssi=0;
1182         BOOLEAN bScan=_FALSE, bLink=_FALSE, bRoam=_FALSE, bWifiBusy=_FALSE, bWifiUnderBMode=_FALSE;
1183         u32                     wifiBw=BTC_WIFI_BW_HT20, wifiTrafficDir=BTC_WIFI_TRAFFIC_TX, wifiFreq=BTC_FREQ_2_4G;
1184         u32                     wifiLinkStatus=0x0;
1185         BOOLEAN bBtHsOn=_FALSE, bLowPower=_FALSE;
1186         u8                      wifiChnl=0, wifiHsChnl=0, nScanAPNum = 0, FwPSState;
1187
1188         wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
1189         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc", \
1190                 ((wifiLinkStatus&WIFI_STA_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_AP_CONNECTED)? 1:0), 
1191                 ((wifiLinkStatus&WIFI_HS_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_P2P_GO_CONNECTED)? 1:0), 
1192                 ((wifiLinkStatus&WIFI_P2P_GC_CONNECTED)? 1:0) );
1193         CL_PRINTF(cliBuf);
1194
1195         if (wifiLinkStatus&WIFI_STA_CONNECTED) {
1196                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]);
1197                 CL_PRINTF(cliBuf);
1198         }
1199
1200         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1201         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiChnl);
1202         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)", \
1203                 wifiChnl, wifiHsChnl, bBtHsOn);
1204         CL_PRINTF(cliBuf);
1205
1206         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
1207         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);
1208         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \
1209                 wifiRssi-100, btHsRssi-100);
1210         CL_PRINTF(cliBuf);
1211
1212
1213         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1214         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1215         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1216         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \
1217                 bLink, bRoam, bScan);
1218         CL_PRINTF(cliBuf);
1219
1220         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifiFreq);
1221         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1222         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1223         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1224         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
1225         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
1226         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ AP=%d ", "Wifi freq/ bw/ traffic", \
1227                 GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode)? "11b": GLBtcWifiBwString[wifiBw]),
1228                 ((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX==wifiTrafficDir)? "uplink":"downlink")), 
1229                 nScanAPNum);
1230         CL_PRINTF(cliBuf);
1231
1232         // power status
1233         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
1234                 ((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE)? "IPS ON":"IPS OFF"),
1235                 ((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE)? ", LPS ON":", LPS OFF"), 
1236                 ((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE)? ", 32k":""));
1237         CL_PRINTF(cliBuf);
1238
1239         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)", \
1240                 pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
1241                 pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
1242                 pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
1243                 pBtCoexist->btInfo.lpsVal, 
1244                 pBtCoexist->btInfo.rpwmVal);
1245         CL_PRINTF(cliBuf);
1246 }
1247
1248 void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
1249 {
1250         PBTC_COEXIST pBtCoexist;
1251
1252
1253         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1254         switch(dispType)
1255         {
1256                 case BTC_DBG_DISP_COEX_STATISTICS:
1257                         halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
1258                         break;
1259                 case BTC_DBG_DISP_BT_LINK_INFO:
1260                         halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
1261                         break;
1262                 case BTC_DBG_DISP_WIFI_STATUS:
1263                         halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
1264                         break;
1265                 default:
1266                         break;
1267         }
1268 }
1269
1270 //====================================
1271 //              IO related function
1272 //====================================
1273 u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
1274 {
1275         PBTC_COEXIST pBtCoexist;
1276         PADAPTER padapter;
1277
1278
1279         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1280         padapter = pBtCoexist->Adapter;
1281
1282         return rtw_read8(padapter, RegAddr);
1283 }
1284
1285 u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
1286 {
1287         PBTC_COEXIST pBtCoexist;
1288         PADAPTER padapter;
1289
1290
1291         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1292         padapter = pBtCoexist->Adapter;
1293
1294         return  rtw_read16(padapter, RegAddr);
1295 }
1296
1297 u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
1298 {
1299         PBTC_COEXIST pBtCoexist;
1300         PADAPTER padapter;
1301
1302
1303         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1304         padapter = pBtCoexist->Adapter;
1305
1306         return  rtw_read32(padapter, RegAddr);
1307 }
1308
1309 void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1310 {
1311         PBTC_COEXIST pBtCoexist;
1312         PADAPTER padapter;
1313
1314
1315         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1316         padapter = pBtCoexist->Adapter;
1317
1318         rtw_write8(padapter, RegAddr, Data);
1319 }
1320
1321 void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
1322 {
1323         PBTC_COEXIST pBtCoexist;
1324         PADAPTER padapter;
1325         u8 originalValue, bitShift;
1326         u8 i;
1327
1328
1329         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1330         padapter = pBtCoexist->Adapter;
1331         originalValue = 0;
1332         bitShift = 0;
1333
1334         if(bitMask != 0xff)
1335         {
1336                 originalValue = rtw_read8(padapter, regAddr);
1337
1338                 for (i=0; i<=7; i++)
1339                 {
1340                         if ((bitMask>>i)&0x1)
1341                                 break;
1342                 }
1343                 bitShift = i;
1344
1345                 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
1346         }
1347
1348         rtw_write8(padapter, regAddr, data1b);
1349 }
1350
1351 void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
1352 {
1353         PBTC_COEXIST pBtCoexist;
1354         PADAPTER padapter;
1355
1356
1357         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1358         padapter = pBtCoexist->Adapter;
1359
1360         rtw_write16(padapter, RegAddr, Data);
1361 }
1362
1363 void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
1364 {
1365         PBTC_COEXIST pBtCoexist;
1366         PADAPTER padapter;
1367
1368
1369         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1370         padapter = pBtCoexist->Adapter;
1371
1372         rtw_write32(padapter, RegAddr, Data);
1373 }
1374
1375 void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1376 {
1377         PBTC_COEXIST            pBtCoexist=(PBTC_COEXIST)pBtcContext;
1378         PADAPTER                        Adapter=pBtCoexist->Adapter;
1379
1380         if(BTC_INTF_SDIO == pBtCoexist->chipInterface)
1381         {
1382                 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
1383         }
1384         else
1385         {
1386                 rtw_write8(Adapter, RegAddr, Data);
1387         }
1388 }
1389
1390 void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
1391 {
1392         PBTC_COEXIST pBtCoexist;
1393         PADAPTER padapter;
1394
1395
1396         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1397         padapter = pBtCoexist->Adapter;
1398
1399         PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
1400 }
1401
1402
1403 u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
1404 {
1405         PBTC_COEXIST pBtCoexist;
1406         PADAPTER padapter;
1407
1408
1409         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1410         padapter = pBtCoexist->Adapter;
1411
1412         return PHY_QueryBBReg(padapter, RegAddr, BitMask);
1413 }
1414
1415 void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
1416 {
1417         PBTC_COEXIST pBtCoexist;
1418         PADAPTER padapter;
1419
1420
1421         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1422         padapter = pBtCoexist->Adapter;
1423
1424         PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
1425 }
1426
1427 u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
1428 {
1429         PBTC_COEXIST pBtCoexist;
1430         PADAPTER padapter;
1431
1432
1433         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1434         padapter = pBtCoexist->Adapter;
1435
1436         return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
1437 }
1438
1439 void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
1440 {
1441         PBTC_COEXIST pBtCoexist;
1442         PADAPTER padapter;
1443         u8 CmdBuffer1[4] = {0};
1444         u8 CmdBuffer2[4] = {0};
1445         u8* AddrToSet = (u8*)&RegAddr;
1446         u8* ValueToSet = (u8*)&Data;    
1447         u8 OperVer = 0;
1448         u8 ReqNum = 0;
1449
1450         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1451         padapter = pBtCoexist->Adapter;
1452
1453         if (IS_HARDWARE_TYPE_8723B(padapter))
1454         {
1455                 CmdBuffer1[0] |= (OperVer & 0x0f);                                              /* Set OperVer */
1456                 CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0);                                /* Set ReqNum */
1457                 CmdBuffer1[1] = 0x0d;                                                                   /* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */
1458                 CmdBuffer1[2] = ValueToSet[0];                                                  /* Set WriteRegValue */
1459                 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
1460
1461                 rtw_msleep_os(200);
1462                 ReqNum++;
1463
1464                 CmdBuffer2[0] |= (OperVer & 0x0f);                                              /* Set OperVer */
1465                 CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0);                                /* Set ReqNum */
1466                 CmdBuffer2[1] = 0x0c;                                                                   /* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */
1467                 CmdBuffer2[3] = AddrToSet[0];                                                   /* Set WriteRegAddr */
1468                 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
1469         }
1470 }
1471
1472 u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
1473 {
1474 /* Always return _FALSE since we don't implement this yet */    
1475 #if 0   
1476         PBTC_COEXIST            pBtCoexist = (PBTC_COEXIST)pBtcContext;
1477         PADAPTER                        Adapter = pBtCoexist->Adapter;
1478         u1Byte                          btCanTx = 0;
1479         BOOLEAN                 bStatus = FALSE;
1480
1481         bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
1482         if (bStatus && btCanTx)
1483                 return _TRUE;
1484         else
1485                 return _FALSE;
1486 #else
1487         return _FALSE;
1488 #endif
1489 }
1490
1491 u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
1492 {
1493         /* To be implemented. Always return 0 temporarily */
1494         return 0;
1495 }
1496
1497 void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
1498 {
1499         PBTC_COEXIST pBtCoexist;
1500         PADAPTER padapter;
1501
1502
1503         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1504         padapter = pBtCoexist->Adapter;
1505
1506         rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
1507 }
1508
1509 //====================================
1510 //              Extern functions called by other module
1511 //====================================
1512 u8 EXhalbtcoutsrc_IsTfbgaPackageType(PADAPTER padapter)
1513 {
1514         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(padapter);
1515
1516 #ifdef CONFIG_RTL8723B
1517         if ((pHalData->PackageType == PACKAGE_TFBGA79) || (pHalData->PackageType == PACKAGE_TFBGA80)
1518                 || (pHalData->PackageType == PACKAGE_TFBGA90)) {
1519                 return _TRUE;
1520         }               
1521 #endif
1522
1523         return _FALSE;
1524 }
1525
1526 u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
1527 {
1528         PBTC_COEXIST            pBtCoexist=&GLBtCoexist;
1529         u1Byte  antNum=2, chipType;
1530         
1531         if(pBtCoexist->bBinded)
1532                 return _FALSE;
1533         else
1534                 pBtCoexist->bBinded = _TRUE;
1535
1536         pBtCoexist->statistics.cntBind++;
1537         
1538         pBtCoexist->Adapter = padapter;
1539         
1540         pBtCoexist->stackInfo.bProfileNotified = _FALSE;
1541
1542         pBtCoexist->btInfo.bBtCtrlAggBufSize = _FALSE;
1543         pBtCoexist->btInfo.aggBufSize = 5;
1544
1545         pBtCoexist->btInfo.bIncreaseScanDevNum = _FALSE;
1546         pBtCoexist->btInfo.bMiracastPlusBt = _FALSE;
1547
1548 #if 0
1549         chipType = HALBT_GetBtChipType(Adapter);
1550         EXhalbtcoutsrc_SetChipType(chipType);
1551         antNum = HALBT_GetPgAntNum(Adapter);
1552         EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1553 #endif
1554         // set default antenna position to main  port
1555         pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;    
1556
1557         pBtCoexist->boardInfo.btdmAntDetFinish = _FALSE;
1558         pBtCoexist->boardInfo.btdmAntNumByAntDet = 1;
1559
1560         pBtCoexist->boardInfo.bTfbgaPackage = EXhalbtcoutsrc_IsTfbgaPackageType((PADAPTER)padapter);
1561
1562         if (pBtCoexist->boardInfo.bTfbgaPackage)
1563                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Package Type = TFBGA\n"));
1564         else
1565                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Package Type = Non-TFBGA\n"));
1566         
1567         return _TRUE;
1568 }
1569
1570 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
1571 {
1572         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
1573
1574         //pBtCoexist->statistics.cntBind++;
1575
1576         halbtcoutsrc_DbgInit();
1577
1578 #ifdef CONFIG_PCI_HCI
1579         pBtCoexist->chipInterface = BTC_INTF_PCI;
1580 #elif defined(CONFIG_USB_HCI)
1581         pBtCoexist->chipInterface = BTC_INTF_USB;
1582 #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
1583         pBtCoexist->chipInterface = BTC_INTF_SDIO;
1584 #else
1585         pBtCoexist->chipInterface = BTC_INTF_UNKNOWN;
1586 #endif
1587
1588         EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
1589
1590         pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
1591         pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
1592         pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
1593         pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
1594         pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
1595         pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
1596         pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
1597         pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
1598
1599         pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
1600         pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
1601
1602         pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
1603         pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
1604
1605         pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
1606         pBtCoexist->fBtcDispDbgMsg = halbtcoutsrc_DisplayDbgMsg;
1607
1608         pBtCoexist->fBtcGet = halbtcoutsrc_Get;
1609         pBtCoexist->fBtcSet = halbtcoutsrc_Set;
1610         pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
1611         pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
1612         pBtCoexist->fBtcSetBtAntDetection = halbtcoutsrc_SetBtAntDetection;
1613
1614         pBtCoexist->cliBuf = &GLBtcDbgBuf[0];
1615
1616         pBtCoexist->boardInfo.singleAntPath = 0;
1617         
1618         GLBtcWiFiInScanState = _FALSE;
1619
1620         GLBtcWiFiInIQKState = _FALSE;
1621
1622         GLBtcWiFiInIPS = _FALSE;
1623
1624         GLBtcWiFiInLPS = _FALSE;
1625
1626         GLBtcBtCoexAliveRegistered = _FALSE;
1627
1628         return _TRUE;
1629 }
1630
1631 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
1632 {
1633         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1634                 return;
1635
1636         /* Power on setting function is only added in 8723B currently */
1637         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1638         {
1639                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1640                         EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
1641                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1642                         EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
1643         }
1644 }
1645
1646 void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
1647 {
1648         if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1649                 return;
1650         
1651         pBtCoexist->statistics.cntPreLoadFirmware++;
1652
1653         if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1654         {
1655                 if(pBtCoexist->boardInfo.btdmAntNum == 2)
1656                         EXhalbtc8723b2ant_PreLoadFirmware(pBtCoexist);
1657                 else if(pBtCoexist->boardInfo.btdmAntNum == 1)
1658                         EXhalbtc8723b1ant_PreLoadFirmware(pBtCoexist);
1659         }
1660 }
1661
1662 void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
1663 {
1664         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1665                 return;
1666
1667         pBtCoexist->statistics.cntInitHwConfig++;
1668
1669         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1670         {
1671                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1672                         EXhalbtc8821aCsr2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1673                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1674                         EXhalbtc8821a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1675                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1676                         EXhalbtc8821a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1677         }
1678         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1679         {
1680                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1681                         EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1682                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1683                         EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1684         }
1685         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1686         {
1687                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1688                         EXhalbtc8192e2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1689                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1690                         EXhalbtc8192e1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1691         }
1692         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1693         {
1694                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1695                         EXhalbtc8812a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1696                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1697                         EXhalbtc8812a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1698         }
1699 }
1700
1701 void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist)
1702 {
1703         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1704                 return;
1705
1706         pBtCoexist->statistics.cntInitCoexDm++;
1707
1708         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1709         {
1710                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1711                         EXhalbtc8821aCsr2ant_InitCoexDm(pBtCoexist);
1712                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1713                         EXhalbtc8821a2ant_InitCoexDm(pBtCoexist);
1714                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1715                         EXhalbtc8821a1ant_InitCoexDm(pBtCoexist);
1716         }
1717         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1718         {
1719                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1720                         EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
1721                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1722                         EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
1723         }
1724         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1725         {
1726                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1727                         EXhalbtc8192e2ant_InitCoexDm(pBtCoexist);
1728                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1729                         EXhalbtc8192e1ant_InitCoexDm(pBtCoexist);
1730         }
1731         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1732         {
1733                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1734                         EXhalbtc8812a2ant_InitCoexDm(pBtCoexist);
1735                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1736                         EXhalbtc8812a1ant_InitCoexDm(pBtCoexist);
1737         }
1738
1739         pBtCoexist->bInitilized = _TRUE;
1740 }
1741
1742 void EXhalbtcoutsrc_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1743 {
1744         u8      ipsType;
1745
1746         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1747                 return;
1748
1749         pBtCoexist->statistics.cntIpsNotify++;
1750         if (pBtCoexist->bManualControl)
1751                 return;
1752
1753         if (IPS_NONE == type)
1754         {
1755                 ipsType = BTC_IPS_LEAVE;
1756                 GLBtcWiFiInIPS = _FALSE;
1757         }
1758         else
1759         {
1760                 ipsType = BTC_IPS_ENTER;
1761                 GLBtcWiFiInIPS = _TRUE;
1762         }
1763         
1764         // All notify is called in cmd thread, don't need to leave low power again
1765 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
1766
1767         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1768         {
1769                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1770                         EXhalbtc8821aCsr2ant_IpsNotify(pBtCoexist, ipsType);
1771                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1772                         EXhalbtc8821a2ant_IpsNotify(pBtCoexist, ipsType);
1773                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1774                         EXhalbtc8821a1ant_IpsNotify(pBtCoexist, ipsType);
1775         }
1776         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1777         {
1778                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1779                         EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
1780                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1781                         EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
1782         }
1783         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1784         {
1785                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1786                         EXhalbtc8192e2ant_IpsNotify(pBtCoexist, ipsType);
1787                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1788                         EXhalbtc8192e1ant_IpsNotify(pBtCoexist, ipsType);
1789         }
1790         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1791         {
1792                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1793                         EXhalbtc8812a2ant_IpsNotify(pBtCoexist, ipsType);
1794                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1795                         EXhalbtc8812a1ant_IpsNotify(pBtCoexist, ipsType);
1796         }
1797
1798 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
1799 }
1800
1801 void EXhalbtcoutsrc_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1802 {
1803         u8 lpsType;
1804
1805
1806         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1807                 return;
1808
1809         pBtCoexist->statistics.cntLpsNotify++;
1810         if (pBtCoexist->bManualControl)
1811                 return;
1812
1813         if (PS_MODE_ACTIVE == type)
1814         {
1815                 lpsType = BTC_LPS_DISABLE;
1816                 GLBtcWiFiInLPS = _FALSE;
1817         }
1818         else
1819         {
1820                 lpsType = BTC_LPS_ENABLE;
1821                 GLBtcWiFiInLPS = _TRUE;
1822         }
1823         
1824         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1825         {
1826                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1827                         EXhalbtc8821aCsr2ant_LpsNotify(pBtCoexist, lpsType);
1828                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1829                         EXhalbtc8821a2ant_LpsNotify(pBtCoexist, lpsType);
1830                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1831                         EXhalbtc8821a1ant_LpsNotify(pBtCoexist, lpsType);
1832         }
1833         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1834         {
1835                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1836                         EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
1837                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1838                         EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
1839         }
1840         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1841         {
1842                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1843                         EXhalbtc8192e2ant_LpsNotify(pBtCoexist, lpsType);
1844                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1845                         EXhalbtc8192e1ant_LpsNotify(pBtCoexist, lpsType);
1846         }
1847         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1848         {
1849                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1850                         EXhalbtc8812a2ant_LpsNotify(pBtCoexist, lpsType);
1851                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1852                         EXhalbtc8812a1ant_LpsNotify(pBtCoexist, lpsType);
1853         }
1854 }
1855
1856 void EXhalbtcoutsrc_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
1857 {
1858         u8      scanType;
1859
1860         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1861                 return;
1862         pBtCoexist->statistics.cntScanNotify++;
1863         if (pBtCoexist->bManualControl)
1864                 return;
1865
1866         if (type)
1867         {
1868                 scanType = BTC_SCAN_START;
1869                 GLBtcWiFiInScanState = _TRUE;
1870         }
1871         else
1872         {
1873                 scanType = BTC_SCAN_FINISH;
1874                 GLBtcWiFiInScanState = _FALSE;
1875         }
1876
1877         // All notify is called in cmd thread, don't need to leave low power again
1878 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
1879
1880         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1881         {
1882                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1883                         EXhalbtc8821aCsr2ant_ScanNotify(pBtCoexist, scanType);
1884                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1885                         EXhalbtc8821a2ant_ScanNotify(pBtCoexist, scanType);
1886                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1887                         EXhalbtc8821a1ant_ScanNotify(pBtCoexist, scanType);
1888         }
1889         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1890         {
1891                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1892                         EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
1893                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1894                         EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
1895         }
1896         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1897         {
1898                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1899                         EXhalbtc8192e2ant_ScanNotify(pBtCoexist, scanType);
1900                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1901                         EXhalbtc8192e1ant_ScanNotify(pBtCoexist, scanType);
1902         }
1903         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1904         {
1905                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1906                         EXhalbtc8812a2ant_ScanNotify(pBtCoexist, scanType);
1907                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1908                         EXhalbtc8812a1ant_ScanNotify(pBtCoexist, scanType);
1909         }
1910
1911 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
1912 }
1913
1914 void EXhalbtcoutsrc_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 action)
1915 {
1916         u8      assoType;
1917
1918         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1919                 return;
1920         pBtCoexist->statistics.cntConnectNotify++;
1921         if (pBtCoexist->bManualControl)
1922                 return;
1923
1924         if (action)
1925                 assoType = BTC_ASSOCIATE_START;
1926         else
1927                 assoType = BTC_ASSOCIATE_FINISH;
1928
1929         // All notify is called in cmd thread, don't need to leave low power again
1930 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
1931
1932         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1933         {
1934                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1935                         EXhalbtc8821aCsr2ant_ConnectNotify(pBtCoexist, assoType);
1936                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1937                         EXhalbtc8821a2ant_ConnectNotify(pBtCoexist, assoType);
1938                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1939                         EXhalbtc8821a1ant_ConnectNotify(pBtCoexist, assoType);
1940         }
1941         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1942         {
1943                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1944                         EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
1945                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1946                         EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
1947         }
1948         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1949         {
1950                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1951                         EXhalbtc8192e2ant_ConnectNotify(pBtCoexist, assoType);
1952                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1953                         EXhalbtc8192e1ant_ConnectNotify(pBtCoexist, assoType);
1954         }
1955         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1956         {
1957                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1958                         EXhalbtc8812a2ant_ConnectNotify(pBtCoexist, assoType);
1959                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1960                         EXhalbtc8812a1ant_ConnectNotify(pBtCoexist, assoType);
1961         }
1962
1963 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
1964 }
1965
1966 void EXhalbtcoutsrc_MediaStatusNotify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
1967 {
1968         u8 mStatus;
1969
1970         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1971                 return;
1972
1973         pBtCoexist->statistics.cntMediaStatusNotify++;
1974         if (pBtCoexist->bManualControl)
1975                 return;
1976
1977         if (RT_MEDIA_CONNECT == mediaStatus)
1978                 mStatus = BTC_MEDIA_CONNECT;
1979         else
1980                 mStatus = BTC_MEDIA_DISCONNECT;
1981
1982         // All notify is called in cmd thread, don't need to leave low power again
1983 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
1984
1985         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1986         {
1987                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1988                         EXhalbtc8821aCsr2ant_MediaStatusNotify(pBtCoexist, mStatus);
1989                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1990                         EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, mStatus);
1991                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1992                         EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, mStatus);
1993         }
1994         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1995         {
1996                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1997                         EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
1998                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1999                         EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
2000         }
2001         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2002         {
2003                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2004                         EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, mStatus);
2005                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2006                         EXhalbtc8192e1ant_MediaStatusNotify(pBtCoexist, mStatus);
2007         }
2008         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2009         {
2010                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2011                         EXhalbtc8812a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2012                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2013                         EXhalbtc8812a1ant_MediaStatusNotify(pBtCoexist, mStatus);
2014         }
2015
2016 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2017 }
2018
2019 void EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 pktType)
2020 {
2021         u8      packetType;
2022
2023         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2024                 return;
2025         pBtCoexist->statistics.cntSpecialPacketNotify++;
2026         if (pBtCoexist->bManualControl)
2027                 return;
2028
2029         if (PACKET_DHCP == pktType)
2030                 packetType = BTC_PACKET_DHCP;
2031         else if (PACKET_EAPOL == pktType)
2032                 packetType = BTC_PACKET_EAPOL;
2033         else if (PACKET_ARP == pktType)
2034                 packetType = BTC_PACKET_ARP;
2035         else
2036         {
2037                 packetType = BTC_PACKET_UNKNOWN;
2038                 return;
2039         }
2040
2041         // All notify is called in cmd thread, don't need to leave low power again
2042 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2043
2044         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2045         {
2046                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2047                         EXhalbtc8821aCsr2ant_SpecialPacketNotify(pBtCoexist, packetType);
2048                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2049                         EXhalbtc8821a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2050                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2051                         EXhalbtc8821a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2052         }
2053         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2054         {
2055                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2056                         EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
2057                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2058                         EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
2059         }
2060         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2061         {
2062                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2063                         EXhalbtc8192e2ant_SpecialPacketNotify(pBtCoexist, packetType);
2064                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2065                         EXhalbtc8192e1ant_SpecialPacketNotify(pBtCoexist, packetType);
2066         }
2067         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2068         {
2069                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2070                         EXhalbtc8812a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2071                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2072                         EXhalbtc8812a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2073         }
2074
2075 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2076 }
2077
2078 void EXhalbtcoutsrc_BtInfoNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
2079 {
2080         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2081                 return;
2082
2083         pBtCoexist->statistics.cntBtInfoNotify++;
2084
2085         // All notify is called in cmd thread, don't need to leave low power again
2086 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2087
2088         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2089         {
2090                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2091                         EXhalbtc8821aCsr2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2092                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2093                         EXhalbtc8821a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2094                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2095                         EXhalbtc8821a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2096         }
2097         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2098         {
2099                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2100                         EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2101                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2102                         EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2103         }
2104         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2105         {
2106                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2107                         EXhalbtc8192e2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2108                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2109                         EXhalbtc8192e1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2110         }
2111         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2112         {
2113                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2114                         EXhalbtc8812a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2115                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2116                         EXhalbtc8812a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2117         }
2118
2119 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2120 }
2121
2122 VOID
2123 EXhalbtcoutsrc_RfStatusNotify(
2124         IN      PBTC_COEXIST            pBtCoexist,
2125         IN      u1Byte                          type
2126         )
2127 {
2128         if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2129                 return;
2130         pBtCoexist->statistics.cntRfStatusNotify++;
2131         
2132         if(IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2133         {
2134         }
2135         else if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2136         {
2137                 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2138                         EXhalbtc8723b1ant_RfStatusNotify(pBtCoexist, type);
2139         }       
2140         else if(IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2141         {
2142         }
2143         else if(IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2144         {
2145         }
2146 }
2147
2148 void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
2149 {
2150 #if 0
2151         u8      stackOpType;
2152
2153         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2154                 return;
2155         pBtCoexist->statistics.cntStackOperationNotify++;
2156         if (pBtCoexist->bManualControl)
2157                 return;
2158
2159         if ((HCI_BT_OP_INQUIRY_START == type) ||
2160                 (HCI_BT_OP_PAGING_START == type) ||
2161                 (HCI_BT_OP_PAIRING_START == type))
2162         {
2163                 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;
2164         }
2165         else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||
2166                 (HCI_BT_OP_PAGING_SUCCESS == type) ||
2167                 (HCI_BT_OP_PAGING_UNSUCCESS == type) ||
2168                 (HCI_BT_OP_PAIRING_FINISH == type) )
2169         {
2170                 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
2171         }
2172         else
2173         {
2174                 stackOpType = BTC_STACK_OP_NONE;
2175         }
2176
2177 #endif
2178 }
2179
2180 void EXhalbtcoutsrc_HaltNotify(PBTC_COEXIST pBtCoexist)
2181 {
2182         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2183                 return;
2184
2185         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2186         {
2187                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2188                         EXhalbtc8821aCsr2ant_HaltNotify(pBtCoexist);
2189                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2190                         EXhalbtc8821a2ant_HaltNotify(pBtCoexist);
2191                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2192                         EXhalbtc8821a1ant_HaltNotify(pBtCoexist);
2193         }
2194         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2195         {
2196                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2197                         EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
2198                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2199                         EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
2200         }
2201         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2202         {
2203                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2204                         EXhalbtc8192e2ant_HaltNotify(pBtCoexist);
2205                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2206                         EXhalbtc8192e1ant_HaltNotify(pBtCoexist);
2207         }
2208         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2209         {
2210                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2211                         EXhalbtc8812a2ant_HaltNotify(pBtCoexist);
2212                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2213                         EXhalbtc8812a1ant_HaltNotify(pBtCoexist);
2214         }
2215
2216         pBtCoexist->bBinded = FALSE;
2217 }
2218
2219 void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
2220 {
2221         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2222         {
2223                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2224                 {
2225                         halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); //BT goto standby while GNT_BT 1-->0
2226                 }
2227                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2228                 {
2229                         halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0
2230                 }
2231         }
2232 }
2233
2234 void EXhalbtcoutsrc_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
2235 {
2236         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2237                 return;
2238
2239         //
2240         // currently only 1ant we have to do the notification,
2241         // once pnp is notified to sleep state, we have to leave LPS that we can sleep normally.
2242         //
2243
2244         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2245         {
2246                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2247                         EXhalbtc8723b1ant_PnpNotify(pBtCoexist,pnpState);
2248                 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2249                         EXhalbtc8723b2ant_PnpNotify(pBtCoexist,pnpState);
2250         }
2251         else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2252         {
2253                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2254                         EXhalbtc8821aCsr2ant_PnpNotify(pBtCoexist, pnpState);
2255                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2256                         EXhalbtc8821a1ant_PnpNotify(pBtCoexist,pnpState);
2257                 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2258                         EXhalbtc8821a2ant_PnpNotify(pBtCoexist,pnpState);
2259         }
2260         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2261         {
2262                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2263                         EXhalbtc8192e1ant_PnpNotify(pBtCoexist, pnpState);
2264         }
2265         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2266         {
2267                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2268                         EXhalbtc8812a1ant_PnpNotify(pBtCoexist, pnpState);
2269         }
2270 }
2271
2272 void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
2273 {
2274         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2275                 return;
2276         pBtCoexist->statistics.cntCoexDmSwitch++;
2277
2278         halbtcoutsrc_LeaveLowPower(pBtCoexist);
2279
2280         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2281         {
2282                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2283                 {
2284                         pBtCoexist->bStopCoexDm = TRUE;
2285                         EXhalbtc8723b1ant_CoexDmReset(pBtCoexist);
2286                         EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
2287                         EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, FALSE);
2288                         EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
2289                         pBtCoexist->bStopCoexDm = FALSE;
2290                 }
2291         }
2292
2293         halbtcoutsrc_NormalLowPower(pBtCoexist);
2294 }
2295
2296 void EXhalbtcoutsrc_Periodical(PBTC_COEXIST pBtCoexist)
2297 {
2298         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2299                 return;
2300         pBtCoexist->statistics.cntPeriodical++;
2301
2302         // Periodical should be called in cmd thread,
2303         // don't need to leave low power again
2304 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2305
2306         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2307         {
2308                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2309                         EXhalbtc8821aCsr2ant_Periodical(pBtCoexist);
2310                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2311                         EXhalbtc8821a2ant_Periodical(pBtCoexist);
2312                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2313                 {
2314                         if (!halbtcoutsrc_UnderIps(pBtCoexist))
2315                         {
2316                                 EXhalbtc8821a1ant_Periodical(pBtCoexist);
2317                         }
2318                 }
2319         }
2320         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2321         {
2322                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2323                         EXhalbtc8723b2ant_Periodical(pBtCoexist);
2324                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2325                         EXhalbtc8723b1ant_Periodical(pBtCoexist);
2326         }
2327         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2328         {
2329                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2330                         EXhalbtc8192e2ant_Periodical(pBtCoexist);
2331                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2332                         EXhalbtc8192e1ant_Periodical(pBtCoexist);
2333         }
2334         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2335         {
2336                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2337                         EXhalbtc8812a2ant_Periodical(pBtCoexist);
2338                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2339                         EXhalbtc8812a1ant_Periodical(pBtCoexist);
2340         }
2341
2342 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2343 }
2344
2345 void EXhalbtcoutsrc_DbgControl(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
2346 {
2347         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2348                 return;
2349
2350         pBtCoexist->statistics.cntDbgCtrl++;
2351
2352         // This function doesn't be called yet,
2353         // default no need to leave low power to avoid deadlock
2354 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2355
2356         if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2357         {
2358                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2359                         EXhalbtc8192e1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2360         }
2361         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2362         {
2363                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2364                         EXhalbtc8812a2ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2365                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2366                         EXhalbtc8812a1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2367         }
2368
2369 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2370 }
2371
2372 #if 0
2373 VOID
2374 EXhalbtcoutsrc_AntennaDetection(
2375         IN      PBTC_COEXIST                    pBtCoexist,
2376         IN      u4Byte                                  centFreq,
2377         IN      u4Byte                                  offset,
2378         IN      u4Byte                                  span,
2379         IN      u4Byte                                  seconds
2380         )
2381 {
2382         if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2383                 return;
2384
2385         /* Need to refine the following power save operations to enable this function in the future */  
2386 #if 0
2387         IPSDisable(pBtCoexist->Adapter, FALSE, 0);
2388         LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
2389 #endif
2390
2391         if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2392         {
2393                 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2394                         EXhalbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);
2395         }
2396
2397         //IPSReturn(pBtCoexist->Adapter, 0xff);
2398 }
2399 #endif
2400
2401 void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
2402 {
2403 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
2404         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2405         PADAPTER padapter = (PADAPTER)GLBtCoexist.Adapter;
2406         PBT_MGNT pBtMgnt = &padapter->coex_info.BtMgnt;
2407         u8 i;
2408
2409         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2410                 return;
2411
2412         pBtCoexist->stackInfo.bProfileNotified = _TRUE;
2413
2414         pBtCoexist->stackInfo.numOfLink =
2415                 pBtMgnt->ExtConfig.NumberOfACL+pBtMgnt->ExtConfig.NumberOfSCO;
2416
2417         // reset first
2418         pBtCoexist->stackInfo.bBtLinkExist = _FALSE;
2419         pBtCoexist->stackInfo.bScoExist = _FALSE;
2420         pBtCoexist->stackInfo.bAclExist = _FALSE;
2421         pBtCoexist->stackInfo.bA2dpExist = _FALSE;
2422         pBtCoexist->stackInfo.bHidExist = _FALSE;
2423         pBtCoexist->stackInfo.numOfHid = 0;
2424         pBtCoexist->stackInfo.bPanExist = _FALSE;
2425
2426         if (!pBtMgnt->ExtConfig.NumberOfACL)
2427                 pBtCoexist->stackInfo.minBtRssi = 0;
2428
2429         if (pBtCoexist->stackInfo.numOfLink)
2430         {
2431                 pBtCoexist->stackInfo.bBtLinkExist = _TRUE;
2432                 if (pBtMgnt->ExtConfig.NumberOfSCO)
2433                         pBtCoexist->stackInfo.bScoExist = _TRUE;
2434                 if (pBtMgnt->ExtConfig.NumberOfACL)
2435                         pBtCoexist->stackInfo.bAclExist = _TRUE;
2436         }
2437
2438         for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
2439         {
2440                 if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2441                 {
2442                         pBtCoexist->stackInfo.bA2dpExist = _TRUE;
2443                 }
2444                 else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2445                 {
2446                         pBtCoexist->stackInfo.bPanExist = _TRUE;
2447                 }
2448                 else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2449                 {
2450                         pBtCoexist->stackInfo.bHidExist = _TRUE;
2451                         pBtCoexist->stackInfo.numOfHid++;
2452                 }
2453                 else
2454                 {
2455                         pBtCoexist->stackInfo.bUnknownAclExist = _TRUE;
2456                 }
2457         }
2458 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
2459 }
2460
2461 void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
2462 {
2463         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2464
2465         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2466                 return;
2467
2468         pBtCoexist->stackInfo.minBtRssi = btRssi;
2469 }
2470
2471 void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
2472 {
2473         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2474
2475         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2476                 return;
2477
2478         pBtCoexist->stackInfo.hciVersion = hciVersion;
2479 }
2480
2481 void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
2482 {
2483         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2484
2485         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2486                 return;
2487
2488         pBtCoexist->btInfo.btRealFwVer = btPatchVersion;
2489         pBtCoexist->btInfo.btHciVer = btHciVersion;
2490 }
2491
2492 #if 0
2493 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
2494 {
2495         GLBtCoexist.boardInfo.bBtExist = bBtExist;
2496 }
2497 #endif
2498 void EXhalbtcoutsrc_SetChipType(u8 chipType)
2499 {
2500         switch(chipType)
2501         {
2502                 default:
2503                 case BT_2WIRE:
2504                 case BT_ISSC_3WIRE:
2505                 case BT_ACCEL:
2506                 case BT_RTL8756:
2507                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_UNDEF;
2508                         break;
2509                 case BT_CSR_BC4:
2510                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC4;
2511                         break;
2512                 case BT_CSR_BC8:
2513                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC8;
2514                         break;
2515                 case BT_RTL8723A:
2516                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723A;
2517                         break;
2518                 case BT_RTL8821:
2519                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8821;
2520                         break;
2521                 case BT_RTL8723B:
2522                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
2523                         break;
2524         }
2525 }
2526
2527 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
2528 {
2529         if (BT_COEX_ANT_TYPE_PG == type)
2530         {
2531                 GLBtCoexist.boardInfo.pgAntNum = antNum;
2532                 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2533 #if 0
2534                 //The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1
2535                 //The antenna position should be determined by auto-detect mechanism
2536                 // The following is assumed to main, and those must be modified if y auto-detect mechanism is ready
2537                 if ((GLBtCoexist.boardInfo.pgAntNum == 2) && (GLBtCoexist.boardInfo.btdmAntNum == 1) )
2538                         GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2539                 else
2540                         GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2541 #endif
2542         }
2543         else if (BT_COEX_ANT_TYPE_ANTDIV == type)
2544         {
2545                 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2546                 //GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;  
2547         }
2548         else if (BT_COEX_ANT_TYPE_DETECTED == type)
2549         {
2550                 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2551                 //GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2552         }
2553 }
2554
2555 //
2556 // Currently used by 8723b only, S0 or S1
2557 //
2558 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
2559 {
2560         GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
2561 }
2562
2563 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
2564 {
2565         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2566                 return;
2567
2568         halbtcoutsrc_LeaveLowPower(pBtCoexist);
2569
2570         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2571         {
2572                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2573                         EXhalbtc8821aCsr2ant_DisplayCoexInfo(pBtCoexist);
2574                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2575                         EXhalbtc8821a2ant_DisplayCoexInfo(pBtCoexist);
2576                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2577                         EXhalbtc8821a1ant_DisplayCoexInfo(pBtCoexist);
2578         }
2579         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2580         {
2581                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2582                         EXhalbtc8723b2ant_DisplayCoexInfo(pBtCoexist);
2583                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2584                         EXhalbtc8723b1ant_DisplayCoexInfo(pBtCoexist);
2585         }
2586         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2587         {
2588                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2589                         EXhalbtc8192e2ant_DisplayCoexInfo(pBtCoexist);
2590                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2591                         EXhalbtc8192e1ant_DisplayCoexInfo(pBtCoexist);
2592         }
2593         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2594         {
2595                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2596                         EXhalbtc8812a2ant_DisplayCoexInfo(pBtCoexist);
2597                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2598                         EXhalbtc8812a1ant_DisplayCoexInfo(pBtCoexist);
2599         }
2600
2601         halbtcoutsrc_NormalLowPower(pBtCoexist);
2602 }
2603
2604 void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)
2605 {
2606         if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2607                 return;
2608
2609         halbtcoutsrc_LeaveLowPower(pBtCoexist);
2610
2611         if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2612         {
2613                 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2614                         EXhalbtc8723b1ant_DisplayAntDetection(pBtCoexist);
2615         }
2616         
2617         halbtcoutsrc_NormalLowPower(pBtCoexist);
2618 }
2619
2620 static void halbt_InitHwConfig92C(PADAPTER padapter)
2621 {
2622         PHAL_DATA_TYPE pHalData;
2623         u8 u1Tmp;
2624
2625
2626         pHalData = GET_HAL_DATA(padapter);
2627         if( (pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2628                 (pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2629         {
2630                 if (pHalData->rf_type == RF_1T1R)
2631                 {
2632                         // Config to 1T1R
2633                         u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2634                         u1Tmp &= ~BIT(1);
2635                         rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2636                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2637
2638                         u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2639                         u1Tmp &= ~BIT(1);
2640                         rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2641                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2642                 }
2643         }
2644 }
2645
2646 static void halbt_InitHwConfig92D(PADAPTER padapter)
2647 {
2648         PHAL_DATA_TYPE pHalData;
2649         u8 u1Tmp;
2650
2651         pHalData = GET_HAL_DATA(padapter);
2652         if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2653                 (pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2654         {
2655                 if (pHalData->rf_type == RF_1T1R)
2656                 {
2657                         // Config to 1T1R
2658                         u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2659                         u1Tmp &= ~BIT(1);
2660                         rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2661                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2662
2663                         u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2664                         u1Tmp &= ~BIT(1);
2665                         rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2666                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2667                 }
2668         }
2669 }
2670
2671 /*
2672  * Description:
2673  *      Run BT-Coexist mechansim or not
2674  *
2675  */
2676 void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
2677 {
2678         PHAL_DATA_TYPE  pHalData;
2679
2680
2681         pHalData = GET_HAL_DATA(padapter);
2682         pHalData->bt_coexist.bBtExist = bBtExist;
2683
2684         //EXhalbtcoutsrc_SetBtExist(bBtExist);
2685 }
2686
2687 /*
2688  * Dewcription:
2689  *      Check is co-exist mechanism enabled or not
2690  *
2691  * Return:
2692  *      _TRUE   Enable BT co-exist mechanism
2693  *      _FALSE  Disable BT co-exist mechanism
2694  */
2695 u8 hal_btcoex_IsBtExist(PADAPTER padapter)
2696 {
2697         PHAL_DATA_TYPE  pHalData;
2698
2699
2700         pHalData = GET_HAL_DATA(padapter);
2701         return pHalData->bt_coexist.bBtExist;
2702 }
2703
2704 u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
2705 {
2706         if (!hal_btcoex_IsBtExist(padapter))
2707                 return _TRUE;
2708
2709         if (GLBtCoexist.btInfo.bBtDisabled)
2710                 return _TRUE;
2711         else
2712                 return _FALSE;
2713 }
2714
2715 void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
2716 {
2717         PHAL_DATA_TYPE  pHalData;
2718
2719
2720         pHalData = GET_HAL_DATA(padapter);
2721         pHalData->bt_coexist.btChipType = chipType;
2722
2723         EXhalbtcoutsrc_SetChipType(chipType);
2724 }
2725
2726 u8 hal_btcoex_GetChipType(PADAPTER padapter)
2727 {
2728         PHAL_DATA_TYPE  pHalData;
2729
2730
2731         pHalData = GET_HAL_DATA(padapter);
2732         return pHalData->bt_coexist.btChipType;
2733 }
2734
2735 void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
2736 {
2737         PHAL_DATA_TYPE  pHalData;
2738
2739
2740         pHalData = GET_HAL_DATA(padapter);
2741
2742         pHalData->bt_coexist.btTotalAntNum = antNum;
2743         EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
2744 }
2745
2746 u8 hal_btcoex_GetPgAntNum(PADAPTER padapter)
2747 {
2748         PHAL_DATA_TYPE pHalData;
2749
2750
2751         pHalData = GET_HAL_DATA(padapter);
2752
2753         return pHalData->bt_coexist.btTotalAntNum;
2754 }
2755
2756 void hal_btcoex_SetSingleAntPath(PADAPTER padapter, u8 singleAntPath)
2757 {
2758         EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
2759 }
2760
2761 u8 hal_btcoex_Initialize(PADAPTER padapter)
2762 {
2763         u8 ret1;
2764         u8 ret2;
2765
2766
2767         _rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
2768         ret1 = EXhalbtcoutsrc_InitlizeVariables((void*)padapter);
2769         ret2 = (ret1==_TRUE) ? _TRUE : _FALSE;
2770
2771         return ret2;
2772 }
2773
2774 void hal_btcoex_PowerOnSetting(PADAPTER padapter)
2775 {
2776         EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
2777 }
2778
2779 void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
2780 {
2781         EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
2782 }
2783
2784 void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
2785 {
2786         if (!hal_btcoex_IsBtExist(padapter))
2787                 return;
2788
2789         EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
2790         EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
2791 }
2792
2793 void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
2794 {
2795         EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
2796 }
2797
2798 void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
2799 {
2800         EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
2801 }
2802
2803 void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
2804 {
2805         EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
2806 }
2807
2808 void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
2809 {
2810         EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
2811 }
2812
2813 void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
2814 {
2815         EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
2816 }
2817
2818 void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
2819 {
2820         EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
2821 }
2822
2823 void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
2824 {
2825         GLBtcWiFiInIQKState = state;
2826 }
2827
2828 void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
2829 {
2830         if (GLBtcWiFiInIQKState == _TRUE)
2831                 return;
2832         
2833         EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
2834 }
2835
2836 void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
2837 {
2838         if (state == 1)
2839                 state = BTC_WIFI_PNP_SLEEP;
2840         else
2841                 state = BTC_WIFI_PNP_WAKE_UP;
2842
2843         EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
2844 }
2845
2846 void hal_btcoex_HaltNotify(PADAPTER padapter)
2847 {
2848         EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
2849 }
2850
2851 void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
2852 {
2853         EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
2854 }
2855
2856 void hal_btcoex_Hanlder(PADAPTER padapter)
2857 {
2858         EXhalbtcoutsrc_Periodical(&GLBtCoexist);
2859 }
2860
2861 s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
2862 {
2863         return (s32)GLBtCoexist.btInfo.bRejectAggPkt;
2864 }
2865
2866 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
2867 {
2868         return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
2869 }
2870
2871 u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
2872 {
2873         return (u32)GLBtCoexist.btInfo.aggBufSize;
2874 }
2875
2876 void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
2877 {
2878         GLBtCoexist.bManualControl = bmanual;
2879 }
2880
2881 u8 hal_btcoex_1Ant(PADAPTER padapter)
2882 {
2883         if (hal_btcoex_IsBtExist(padapter) == _FALSE)
2884                 return _FALSE;
2885
2886         if (GLBtCoexist.boardInfo.btdmAntNum == 1)
2887                 return _TRUE;
2888
2889         return _FALSE;
2890 }
2891
2892 u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
2893 {
2894         if (hal_btcoex_IsBtExist(padapter) == _FALSE)
2895                 return _FALSE;
2896
2897         if (GLBtCoexist.btInfo.bBtDisabled)
2898                 return _FALSE;
2899
2900         if (GLBtCoexist.btInfo.bBtCtrlLps)
2901                 return _TRUE;
2902
2903         return _FALSE;
2904 }
2905
2906 u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
2907 {
2908         if (hal_btcoex_IsBtExist(padapter) == _FALSE)
2909                 return _FALSE;
2910
2911         if (GLBtCoexist.btInfo.bBtDisabled)
2912                 return _FALSE;
2913
2914         if (GLBtCoexist.btInfo.bBtLpsOn)
2915                 return _TRUE;
2916
2917         return _FALSE;
2918 }
2919
2920 u8 hal_btcoex_RpwmVal(PADAPTER padapter)
2921 {
2922         return GLBtCoexist.btInfo.rpwmVal;
2923 }
2924
2925 u8 hal_btcoex_LpsVal(PADAPTER padapter)
2926 {
2927         return GLBtCoexist.btInfo.lpsVal;
2928 }
2929
2930 u32 hal_btcoex_GetRaMask(PADAPTER padapter)
2931 {
2932         if (!hal_btcoex_IsBtExist(padapter))
2933                 return 0;
2934
2935         if (GLBtCoexist.btInfo.bBtDisabled)
2936                 return 0;
2937
2938                 /* Modify by YiWei , suggest by Cosa and Jenyu
2939                  * Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.
2940                  */
2941         /*if (GLBtCoexist.boardInfo.btdmAntNum != 1)
2942                 return 0;*/
2943
2944         return GLBtCoexist.btInfo.raMask;
2945 }
2946
2947 void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
2948 {
2949         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW write pwrModeCmd=0x%04x%08x\n",
2950                 pCmdBuf[0]<<8|pCmdBuf[1],
2951                 pCmdBuf[2]<<24|pCmdBuf[3]<<16|pCmdBuf[4]<<8|pCmdBuf[5]));
2952
2953         _rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
2954 }
2955
2956 void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
2957 {
2958         PBTCDBGINFO pinfo;
2959
2960
2961         pinfo = &GLBtcDbgInfo;
2962         DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
2963         EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
2964         DBG_BT_INFO_INIT(pinfo, NULL, 0);
2965 }
2966
2967 void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
2968 {
2969         u32 i;
2970
2971
2972         if (NULL == pDbgModule)
2973                 return;
2974
2975         for (i = 0; i < COMP_MAX; i++)
2976                 GLBtcDbgType[i] = pDbgModule[i];
2977 }
2978
2979 u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
2980 {
2981         s32 count;
2982         u8 *pstr;
2983         u32 leftSize;
2984
2985
2986         if ((NULL == pStrBuf) || (0 == bufSize))
2987                 return 0;
2988
2989         count = 0;
2990         pstr = pStrBuf;
2991         leftSize = bufSize;
2992 //      DBG_871X(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize);
2993
2994         count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
2995         if ((count < 0) || (count >= leftSize))
2996                 goto exit;
2997         pstr += count;
2998         leftSize -= count;
2999
3000         count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
3001         if ((count < 0) || (count >= leftSize))
3002                 goto exit;
3003         pstr += count;
3004         leftSize -= count;
3005
3006         count = rtw_sprintf(pstr, leftSize,
3007                 "COMP_COEX: 0x%08X\n\n",
3008                 GLBtcDbgType[COMP_COEX]);
3009         if ((count < 0) || (count >= leftSize))
3010                 goto exit;
3011         pstr += count;
3012         leftSize -= count;
3013
3014 #if 0
3015         count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
3016         if ((count < 0) || (count >= leftSize))
3017                 goto exit;
3018         pstr += count;
3019         leftSize -= count;
3020         count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
3021                 GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_INIT?1:0);
3022         if ((count < 0) || (count >= leftSize))
3023                 goto exit;
3024         pstr += count;
3025         leftSize -= count;
3026         count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
3027                 GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_NOTIFY?1:0);
3028         if ((count < 0) || (count >= leftSize))
3029                 goto exit;
3030         pstr += count;
3031         leftSize -= count;
3032         
3033         count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
3034         if ((count < 0) || (count >= leftSize))
3035                 goto exit;
3036         pstr += count;
3037         leftSize -= count;
3038         count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
3039                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_RSSI_STATE?1:0);
3040         if ((count < 0) || (count >= leftSize))
3041                 goto exit;
3042         pstr += count;
3043         leftSize -= count;
3044         count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
3045                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_WIFI_RSSI_STATE?1:0);
3046         if ((count < 0) || (count >= leftSize))
3047                 goto exit;
3048         pstr += count;
3049         leftSize -= count;
3050         count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
3051                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_MONITOR?1:0);
3052         if ((count < 0) || (count >= leftSize))
3053                 goto exit;
3054         pstr += count;
3055         leftSize -= count;
3056         count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
3057                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE?1:0);
3058         if ((count < 0) || (count >= leftSize))
3059                 goto exit;
3060         pstr += count;
3061         leftSize -= count;
3062         count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
3063                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW?1:0);
3064         if ((count < 0) || (count >= leftSize))
3065                 goto exit;
3066         pstr += count;
3067         leftSize -= count;
3068         count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
3069                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_DETAIL?1:0);
3070         if ((count < 0) || (count >= leftSize))
3071                 goto exit;
3072         pstr += count;
3073         leftSize -= count;
3074         count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
3075                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_EXEC?1:0);
3076         if ((count < 0) || (count >= leftSize))
3077                 goto exit;
3078         pstr += count;
3079         leftSize -= count;
3080         count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
3081                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW?1:0);
3082         if ((count < 0) || (count >= leftSize))
3083                 goto exit;
3084         pstr += count;
3085         leftSize -= count;
3086         count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
3087                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_DETAIL?1:0);
3088         if ((count < 0) || (count >= leftSize))
3089                 goto exit;
3090         pstr += count;
3091         leftSize -= count;
3092         count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
3093                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_EXEC?1:0);
3094         if ((count < 0) || (count >= leftSize))
3095                 goto exit;
3096         pstr += count;
3097         leftSize -= count;
3098 #endif
3099
3100 exit:
3101         count = pstr - pStrBuf;
3102 //      DBG_871X(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count);
3103
3104         return count;
3105 }
3106
3107 u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
3108 {
3109         if (!hal_btcoex_IsBtExist(padapter))
3110                 return _FALSE;
3111
3112         if (GLBtCoexist.btInfo.bIncreaseScanDevNum)
3113                 return _TRUE;
3114
3115         return _FALSE;
3116 }
3117
3118 u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
3119 {
3120         if (GLBtCoexist.btLinkInfo.bBtLinkExist)
3121                 return _TRUE;
3122
3123         return _FALSE;
3124 }
3125
3126 void hal_btcoex_SetBtPatchVersion(PADAPTER padapter,u16 btHciVer,u16 btPatchVer)
3127 {
3128         EXhalbtcoutsrc_SetBtPatchVersion(btHciVer,btPatchVer);
3129 }
3130
3131 void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
3132 {
3133         EXhalbtcoutsrc_SetHciVersion(hciVersion);
3134 }
3135
3136 void hal_btcoex_StackUpdateProfileInfo(void)
3137 {
3138         EXhalbtcoutsrc_StackUpdateProfileInfo();
3139 }
3140
3141 /*
3142  *      Description:
3143  *      Setting BT coex antenna isolation type .
3144  *      coex mechanisn/ spital stream/ best throughput
3145  *      anttype = 0     ,       PSTDMA  /       2SS     /       0.5T    ,       bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna
3146  *      anttype = 1     ,       PSTDMA  /       1SS     /       0.5T    ,       normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna
3147  *      anttype = 2     ,       TDMA    /       2SS     /       T ,             normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna
3148  *      anttype = 3     ,       no TDMA /       1SS     /       0.5T    ,       good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna
3149  *      anttype = 4     ,       no TDMA /       2SS     /       T ,             good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna
3150  *      wifi only throughput ~ T
3151  *      wifi/BT share one antenna with SPDT
3152  */
3153 void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
3154 {
3155                 PHAL_DATA_TYPE pHalData;
3156                 PBTC_COEXIST    pBtCoexist = &GLBtCoexist;
3157
3158                 /*DBG_871X("####%s , anttype = %d  , %d\n" , __func__ , anttype , __LINE__); */
3159                 pHalData = GET_HAL_DATA(padapter);
3160
3161
3162                 pHalData->bt_coexist.btAntisolation = anttype;
3163
3164                 switch (pHalData->bt_coexist.btAntisolation) {
3165                 case 0:
3166                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_0;
3167                                 break;
3168                 case 1:
3169                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_1;
3170                                 break;
3171                 case 2:
3172                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_2;
3173                                 break;
3174                 case 3:
3175                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_3;
3176                                 break;
3177                 case 4:
3178                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_4;
3179                                 break;
3180                 }
3181
3182 }
3183
3184 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
3185 int
3186 hal_btcoex_ParseAntIsolationConfigFile(
3187   PADAPTER              Adapter,
3188   char*                 buffer
3189 )
3190 {
3191         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(Adapter);
3192         u32     i = 0 , j = 0;
3193         char    *szLine , *ptmp;
3194         int rtStatus = _SUCCESS;
3195         char param_value_string[10];
3196         u8 param_value;
3197         u8 anttype = 4;
3198         
3199         u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1; 
3200         
3201         typedef struct ant_isolation {
3202                 char *param_name;  /* antenna isolation config parameter name */ 
3203                 u8 *value; /* antenna isolation config parameter value */
3204         } ANT_ISOLATION;
3205
3206         ANT_ISOLATION ant_isolation_param[] = {
3207                                                                                                 {"ANT_NUMBER" , &ant_num},
3208                                                                                                 {"ANT_DISTANCE" , &ant_distance},
3209                                                                                                 {"RFE_TYPE" , &rfe_type},                                                                                               
3210                                                                                                 {NULL , 0}
3211                                                                                 };
3212
3213
3214         
3215         /* DBG_871X("===>Hal_ParseAntIsolationConfigFile()\n" ); */
3216                         
3217         ptmp = buffer;
3218         for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
3219                 /* skip comment */ 
3220                 if (IsCommentString(szLine))
3221                         continue;        
3222
3223                 /* DBG_871X("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/
3224                 for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) {
3225                         if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) {
3226                                 i = 0;
3227                                 while (i < strlen(szLine)) {
3228                                         if (szLine[i] != '"')
3229                                                 ++i;
3230                                         else {
3231                                                 /* skip only has one " */
3232                                                 if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {
3233                                                         DBG_871X("Fail to parse parameters , format error!\n");
3234                                                         break;
3235                                                 }
3236                                                 _rtw_memset((PVOID)param_value_string , 0 , 10);
3237                                                 if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) {
3238                                                         DBG_871X("Fail to parse parameters\n");
3239                                                         return _FAIL;
3240                                                 } else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value)) 
3241                                                         DBG_871X("Fail to GetU1ByteIntegerFromStringInDecimal\n");
3242
3243                                                 break;
3244                                         }
3245                                 }
3246                         }
3247                 }
3248         } 
3249
3250         /* YiWei 20140716 , for BT coex antenna isolation control */
3251         /* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */
3252         if (ant_num == 3 && ant_distance >= 50) 
3253                 anttype = 3;
3254         else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)
3255                 anttype = 2;
3256         else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)
3257                 anttype = 2;
3258         else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)
3259                 anttype = 2;
3260         else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))
3261                 anttype = 1;
3262         else if (ant_num == 2 && rfe_type == 0)
3263                 anttype = 0;
3264         else 
3265                 anttype = 0;
3266
3267         hal_btcoex_SetAntIsolationType(Adapter, anttype); 
3268                                                 
3269         DBG_871X("%s : ant_num = %d\n" , __func__ , ant_num);
3270         DBG_871X("%s : ant_distance = %d\n" , __func__ , ant_distance);
3271         DBG_871X("%s : rfe_type = %d\n" , __func__ , rfe_type);
3272         /* DBG_871X("<===Hal_ParseAntIsolationConfigFile()\n"); */
3273         return rtStatus;        
3274 }
3275
3276
3277 int
3278 hal_btcoex_AntIsolationConfig_ParaFile(
3279         IN      PADAPTER        Adapter,
3280         IN      char*           pFileName
3281 )
3282 {
3283         HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
3284         int     rlen = 0 , rtStatus = _FAIL;
3285
3286         _rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);
3287
3288
3289         rtw_merge_string(file_path, PATH_LENGTH_MAX, rtw_phy_file_path, pFileName);
3290
3291         if (rtw_is_file_readable(file_path) == _TRUE)
3292         {
3293                 rlen = rtw_retrive_from_file(file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
3294                 if (rlen > 0)
3295                 {
3296                         rtStatus = _SUCCESS;
3297                 }
3298         }
3299
3300
3301         if (rtStatus == _SUCCESS) {
3302                 /*DBG_871X("%s(): read %s ok\n", __func__ , pFileName);*/
3303                 rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);
3304         } else {
3305                 DBG_871X("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);
3306         }
3307
3308         return rtStatus;
3309 }
3310 #endif // CONFIG_LOAD_PHY_PARA_FROM_FILE
3311 #endif // CONFIG_BT_COEXIST
3312