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