1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 *published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
15 #include <drv_types.h>
16 #include <rtl8723a_hal.h>
17 #include <usb_ops_linux.h>
21 u32 BTCoexDbgLevel = _bt_dbg_off_;
23 #define RTPRINT(_Comp, _Level, Fmt)\
25 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
30 #define RTPRINT_ADDR(dbgtype, dbgflag, printstr, _Ptr)\
31 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
33 u8 *ptr = (u8 *)_Ptr; \
36 for (__i = 0; __i < 6; __i++) \
37 printk("%02X%s", ptr[__i], (__i == 5)?"":"-"); \
40 #define RTPRINT_DATA(dbgtype, dbgflag, _TitleString, _HexData, _HexDataLen)\
41 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
43 u8 *ptr = (u8 *)_HexData; \
44 printk(_TitleString); \
45 for (__i = 0; __i < (u32)_HexDataLen; __i++) { \
46 printk("%02X%s", ptr[__i], (((__i + 1) % 4) == 0)?" ":" ");\
47 if (((__i + 1) % 16) == 0) \
52 /* Added by Annie, 2005-11-22. */
53 #define MAX_STR_LEN 64
54 /* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. */
55 #define PRINTABLE(_ch) (_ch >= ' ' && _ch <= '~')
56 #define RT_PRINT_STR(_Comp, _Level, _TitleString, _Ptr, _Len) \
59 u8 buffer[MAX_STR_LEN]; \
60 u32 length = (_Len < MAX_STR_LEN) ? _Len : (MAX_STR_LEN-1);\
61 memset(buffer, 0, MAX_STR_LEN); \
62 memcpy(buffer, (u8 *)_Ptr, length); \
63 for (__i = 0; __i < length; __i++) { \
64 if (!PRINTABLE(buffer[__i])) \
67 buffer[length] = '\0'; \
68 printk(_TitleString); \
69 printk(": %d, <%s>\n", _Len, buffer); \
72 #define DCMD_Printf(...)
73 #define RT_ASSERT(...)
76 #define GetDefaultAdapter(padapter) padapter
78 #define PlatformZeroMemory(ptr, sz) memset(ptr, 0, sz)
80 #define GET_UNDECORATED_AVERAGE_RSSI(padapter) \
81 (GET_HAL_DATA(padapter)->dmpriv.EntryMinUndecoratedSmoothedPWDB)
82 #define RT_RF_CHANGE_SOURCE u32
93 /* ===== Below this line is sync from SD7 driver COMMOM/BT.c ===== */
95 static u8 BT_Operation(struct rtw_adapter *padapter)
97 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
98 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
100 if (pBtMgnt->BtOperationOn)
106 static u8 BT_IsLegalChannel(struct rtw_adapter *padapter, u8 channel)
108 struct rt_channel_info *pChanneList = NULL;
111 pChanneList = padapter->mlmeextpriv.channel_set;
112 channelLen = padapter->mlmeextpriv.max_chan_nums;
114 for (i = 0; i < channelLen; i++) {
115 RTPRINT(FIOCTL, IOCTL_STATE,
116 ("Check if chnl(%d) in channel plan contains bt target chnl(%d) for BT connection\n",
117 pChanneList[i].ChannelNum, channel));
118 if ((channel == pChanneList[i].ChannelNum) ||
119 (channel == pChanneList[i].ChannelNum + 2))
125 void BT_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
127 BTDM_SignalCompensation(padapter, rssi_wifi, rssi_bt);
130 void rtl8723a_BT_wifiscan_notify(struct rtw_adapter *padapter, u8 scanType)
132 BTHCI_WifiScanNotify(padapter, scanType);
133 BTDM_CheckAntSelMode(padapter);
134 BTDM_WifiScanNotify(padapter, scanType);
137 void rtl8723a_BT_wifiassociate_notify(struct rtw_adapter *padapter, u8 action)
140 /* true = associate start */
141 /* false = associate finished */
143 BTDM_CheckAntSelMode(padapter);
145 BTDM_WifiAssociateNotify(padapter, action);
148 void BT_HaltProcess(struct rtw_adapter *padapter)
150 BTDM_ForHalt(padapter);
153 /* ===== End of sync from SD7 driver COMMOM/BT.c ===== */
156 #define UINT64_C(v) (v)
158 #define FillOctetString(_os, _octet, _len) \
159 (_os).Octet = (u8 *)(_octet); \
160 (_os).Length = (_len);
162 static enum rt_status PlatformIndicateBTEvent(
163 struct rtw_adapter *padapter,
168 enum rt_status rt_status = RT_STATUS_FAILURE;
170 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event start, %d bytes data to Transferred!!\n", dataLen));
171 RTPRINT_DATA(FIOCTL, IOCTL_BT_EVENT_DETAIL, "To transfer Hex Data :\n",
174 BT_EventParse(padapter, pEvntData, dataLen);
176 printk(KERN_WARNING "%s: Linux has no way to report BT event!!\n", __func__);
178 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event end, %s\n",
179 (rt_status == RT_STATUS_SUCCESS) ? "SUCCESS" : "FAIL"));
184 /* ===== Below this line is sync from SD7 driver COMMOM/bt_hci.c ===== */
186 static u8 bthci_GetLocalChannel(struct rtw_adapter *padapter)
188 return padapter->mlmeextpriv.cur_channel;
191 static u8 bthci_GetCurrentEntryNum(struct rtw_adapter *padapter, u8 PhyHandle)
193 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
196 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
197 if ((pBTInfo->BtAsocEntry[i].bUsed) &&
198 (pBTInfo->BtAsocEntry[i].PhyLinkCmdData.BtPhyLinkhandle == PhyHandle))
205 static void bthci_DecideBTChannel(struct rtw_adapter *padapter, u8 EntryNum)
207 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
208 struct mlme_priv *pmlmepriv;
209 struct bt_30info *pBTInfo;
210 struct bt_mgnt *pBtMgnt;
211 struct bt_hci_info *pBtHciInfo;
212 struct chnl_txpower_triple *pTriple_subband = NULL;
213 struct common_triple *pTriple;
214 u8 i, j, localchnl, firstRemoteLegalChnlInTriplet = 0;
215 u8 regulatory_skipLen = 0;
216 u8 subbandTripletCnt = 0;
218 pmlmepriv = &padapter->mlmepriv;
219 pBTInfo = GET_BT_INFO(padapter);
220 pBtMgnt = &pBTInfo->BtMgnt;
221 pBtHciInfo = &pBTInfo->BtHciInfo;
223 pBtMgnt->CheckChnlIsSuit = true;
224 localchnl = bthci_GetLocalChannel(padapter);
226 pTriple = (struct common_triple *)
227 &pBtHciInfo->BTPreChnllist[COUNTRY_STR_LEN];
229 /* contains country string, len is 3 */
230 for (i = 0; i < (pBtHciInfo->BtPreChnlListLen-COUNTRY_STR_LEN); i += 3, pTriple++) {
232 /* check every triplet, an triplet may be */
233 /* regulatory extension identifier or sub-band triplet */
235 if (pTriple->byte_1st == 0xc9) {
236 /* Regulatory Extension Identifier, skip it */
237 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
238 ("Find Regulatory ID, regulatory class = %d\n", pTriple->byte_2nd));
239 regulatory_skipLen += 3;
240 pTriple_subband = NULL;
242 } else { /* Sub-band triplet */
243 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Find Sub-band triplet \n"));
245 pTriple_subband = (struct chnl_txpower_triple *)pTriple;
246 /* if remote first legal channel not found, then find first remote channel */
247 /* and it's legal for our channel plan. */
249 /* search the sub-band triplet and find if remote channel is legal to our channel plan. */
250 for (j = pTriple_subband->FirstChnl; j < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls); j++) {
251 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), (" Check if chnl(%d) is legal\n", j));
252 if (BT_IsLegalChannel(padapter, j)) {
253 /* remote channel is legal for our channel plan. */
254 firstRemoteLegalChnlInTriplet = j;
255 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
256 ("Find first remote legal channel : %d\n",
257 firstRemoteLegalChnlInTriplet));
259 /* If we find a remote legal channel in the sub-band triplet */
260 /* and only BT connection is established(local not connect to any AP or IBSS), */
261 /* then we just switch channel to remote channel. */
262 if (!(check_fwstate(pmlmepriv, WIFI_ASOC_STATE|WIFI_ADHOC_STATE|WIFI_AP_STATE) ||
263 BTHCI_HsConnectionEstablished(padapter))) {
264 pBtMgnt->BTChannel = firstRemoteLegalChnlInTriplet;
265 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Remote legal channel (%d) is selected, Local not connect to any!!\n", pBtMgnt->BTChannel));
268 if ((localchnl >= firstRemoteLegalChnlInTriplet) &&
269 (localchnl < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls))) {
270 pBtMgnt->BTChannel = localchnl;
271 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected, wifi or BT connection exists\n", pBtMgnt->BTChannel));
281 if (subbandTripletCnt) {
282 /* if any preferred channel triplet exists */
283 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("There are %d sub band triplet exists, ", subbandTripletCnt));
284 if (firstRemoteLegalChnlInTriplet == 0) {
285 /* no legal channel is found, reject the connection. */
286 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("no legal channel is found!!\n"));
288 /* Remote Legal channel is found but not match to local */
289 /* wifi connection exists), so reject the connection. */
290 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
291 ("Remote Legal channel is found but not match to local(wifi connection exists)!!\n"));
293 pBtMgnt->CheckChnlIsSuit = false;
295 /* There are not any preferred channel triplet exists */
296 /* Use current legal channel as the bt channel. */
297 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("No sub band triplet exists!!\n"));
299 pBtMgnt->BTChannel = localchnl;
300 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected!!\n", pBtMgnt->BTChannel));
303 /* Success:return true */
304 /* Fail:return false */
305 static u8 bthci_GetAssocInfo(struct rtw_adapter *padapter, u8 EntryNum)
307 struct bt_30info *pBTInfo;
308 struct bt_hci_info *pBtHciInfo;
311 u8 BaseMemoryShift = 0;
313 struct amp_assoc_structure *pAmpAsoc;
315 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo start\n"));
316 pBTInfo = GET_BT_INFO(padapter);
317 pBtHciInfo = &pBTInfo->BtHciInfo;
319 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar == 0) {
320 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen < (MAX_AMP_ASSOC_FRAG_LEN))
321 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen;
322 else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen == (MAX_AMP_ASSOC_FRAG_LEN))
323 TotalLen = MAX_AMP_ASSOC_FRAG_LEN;
324 } else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar > 0)
325 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar;
327 while ((pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar >= BaseMemoryShift) || TotalLen > BaseMemoryShift) {
328 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("GetAssocInfo, TotalLen =%d, BaseMemoryShift =%d\n", TotalLen, BaseMemoryShift));
330 (u8 *)pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment+BaseMemoryShift,
331 TotalLen-BaseMemoryShift);
332 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, "GetAssocInfo :\n",
333 tempBuf, TotalLen-BaseMemoryShift);
335 pAmpAsoc = (struct amp_assoc_structure *)tempBuf;
336 le16_to_cpus(&pAmpAsoc->Length);
337 BaseMemoryShift += 3 + pAmpAsoc->Length;
339 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TypeID = 0x%x, ", pAmpAsoc->TypeID));
340 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Hex Data: \n", pAmpAsoc->Data, pAmpAsoc->Length);
341 switch (pAmpAsoc->TypeID) {
343 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_MAC_ADDR\n"));
344 if (pAmpAsoc->Length > 6)
346 memcpy(pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, pAmpAsoc->Data, 6);
347 RTPRINT_ADDR(FIOCTL, IOCTL_BT_HCICMD, ("Remote Mac address \n"), pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr);
349 case AMP_PREFERRED_CHANNEL_LIST:
350 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_PREFERRED_CHANNEL_LIST\n"));
351 pBtHciInfo->BtPreChnlListLen = pAmpAsoc->Length;
352 memcpy(pBtHciInfo->BTPreChnllist,
354 pBtHciInfo->BtPreChnlListLen);
355 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Preferred channel list : \n", pBtHciInfo->BTPreChnllist, pBtHciInfo->BtPreChnlListLen);
356 bthci_DecideBTChannel(padapter, EntryNum);
358 case AMP_CONNECTED_CHANNEL:
359 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_CONNECTED_CHANNEL\n"));
360 pBtHciInfo->BTConnectChnlListLen = pAmpAsoc->Length;
361 memcpy(pBtHciInfo->BTConnectChnllist,
363 pBtHciInfo->BTConnectChnlListLen);
365 case AMP_80211_PAL_CAP_LIST:
366 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_80211_PAL_CAP_LIST\n"));
367 pBTInfo->BtAsocEntry[EntryNum].BTCapability = *(u32 *)(pAmpAsoc->Data);
368 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000001) {
371 /* Signifies PAL capable of utilizing received activity reports. */
373 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000002) {
375 /* Signifies PAL is capable of utilizing scheduling information received in an activity reports. */
378 case AMP_80211_PAL_VISION:
379 pBtHciInfo->BTPalVersion = *(u8 *)(pAmpAsoc->Data);
380 pBtHciInfo->BTPalCompanyID = *(u16 *)(((u8 *)(pAmpAsoc->Data))+1);
381 pBtHciInfo->BTPalsubversion = *(u16 *)(((u8 *)(pAmpAsoc->Data))+3);
382 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("==> AMP_80211_PAL_VISION PalVersion 0x%x, PalCompanyID 0x%x, Palsubversion 0x%x\n",
383 pBtHciInfo->BTPalVersion,
384 pBtHciInfo->BTPalCompanyID,
385 pBtHciInfo->BTPalsubversion));
388 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> Unsupport TypeID !!\n"));
393 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo end\n"));
398 static u8 bthci_AddEntry(struct rtw_adapter *padapter)
400 struct bt_30info *pBTInfo;
401 struct bt_mgnt *pBtMgnt;
404 pBTInfo = GET_BT_INFO(padapter);
405 pBtMgnt = &pBTInfo->BtMgnt;
407 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
408 if (pBTInfo->BtAsocEntry[i].bUsed == false) {
409 pBTInfo->BtAsocEntry[i].bUsed = true;
410 pBtMgnt->CurrentConnectEntryNum = i;
415 if (i == MAX_BT_ASOC_ENTRY_NUM) {
416 RTPRINT(FIOCTL, IOCTL_STATE, ("bthci_AddEntry(), Add entry fail!!\n"));
422 static u8 bthci_DiscardTxPackets(struct rtw_adapter *padapter, u16 LLH)
428 bthci_CheckLogLinkBehavior(
429 struct rtw_adapter *padapter,
430 struct hci_flow_spec TxFlowSpec
433 u8 ID = TxFlowSpec.Identifier;
434 u8 ServiceType = TxFlowSpec.ServiceType;
435 u16 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
436 u32 SDUInterArrivatime = TxFlowSpec.SDUInterArrivalTime;
441 if (ServiceType == BT_LL_BE) {
443 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX best effort flowspec\n"));
444 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 0xffff)) {
446 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed latency flowspec\n"));
447 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
448 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed Large latency flowspec\n"));
452 if (ServiceType == BT_LL_BE) {
454 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX best effort flowspec\n"));
459 if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 1492)) {
461 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed latency flowspec\n"));
462 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
463 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed Large latency flowspec\n"));
467 if (ServiceType == BT_LL_BE) {
468 if ((SDUInterArrivatime == 0xffffffff) && (ServiceType == BT_LL_BE) && (MaxSDUSize == 1492)) {
470 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX aggregated best effort flowspec\n"));
472 } else if (ServiceType == BT_LL_GU) {
473 if (SDUInterArrivatime == 100) {
475 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX guaranteed bandwidth flowspec\n"));
480 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = Unknow Type !!!!!!!!\n"));
484 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
485 ("ID = 0x%x, ServiceType = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, AccessLatency = 0x%x, FlushTimeout = 0x%x\n",
486 TxFlowSpec.Identifier, TxFlowSpec.ServiceType, MaxSDUSize,
487 SDUInterArrivatime, TxFlowSpec.AccessLatency, TxFlowSpec.FlushTimeout));
491 static u16 bthci_AssocMACAddr(struct rtw_adapter *padapter, void *pbuf)
493 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
494 pAssoStrc->TypeID = AMP_MAC_ADDR;
495 pAssoStrc->Length = 0x06;
496 memcpy(&pAssoStrc->Data[0], padapter->eeprompriv.mac_addr, 6);
497 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
498 ("AssocMACAddr : \n"), pAssoStrc, pAssoStrc->Length+3);
500 return pAssoStrc->Length + 3;
504 bthci_PALCapabilities(
505 struct rtw_adapter *padapter,
509 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
511 pAssoStrc->TypeID = AMP_80211_PAL_CAP_LIST;
512 pAssoStrc->Length = 0x04;
514 pAssoStrc->Data[0] = 0x00;
515 pAssoStrc->Data[1] = 0x00;
517 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("PALCapabilities:\n"), pAssoStrc, pAssoStrc->Length+3);
518 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("PALCapabilities \n"));
520 RTPRINT(FIOCTL, IOCTL_BT_LOGO, (" TypeID = 0x%x,\n Length = 0x%x,\n Content = 0x0000\n",
524 return pAssoStrc->Length + 3;
527 static u16 bthci_AssocPreferredChannelList(struct rtw_adapter *padapter,
528 void *pbuf, u8 EntryNum)
530 struct bt_30info *pBTInfo;
531 struct amp_assoc_structure *pAssoStrc;
532 struct amp_pref_chnl_regulatory *pReg;
533 struct chnl_txpower_triple *pTriple;
534 char ctrString[3] = {'X', 'X', 'X'};
538 pBTInfo = GET_BT_INFO(padapter);
539 pAssoStrc = (struct amp_assoc_structure *)pbuf;
540 pReg = (struct amp_pref_chnl_regulatory *)&pAssoStrc->Data[3];
542 preferredChnl = bthci_GetLocalChannel(padapter);
543 pAssoStrc->TypeID = AMP_PREFERRED_CHANNEL_LIST;
546 memcpy(&pAssoStrc->Data[0], &ctrString[0], 3);
548 pReg->regulatoryClass = 254;
549 pReg->coverageClass = 0;
551 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("PREFERRED_CHNL_LIST\n"));
552 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("XXX, 201, 254, 0\n"));
553 /* at the following, chnl 1~11 should be contained */
554 pTriple = (struct chnl_txpower_triple *)&pAssoStrc->Data[len];
556 /* (1) if any wifi or bt HS connection exists */
557 if ((pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR) ||
558 (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE |
559 WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE |
561 BTHCI_HsConnectionEstablished(padapter)) {
562 pTriple->FirstChnl = preferredChnl;
563 pTriple->NumChnls = 1;
564 pTriple->MaxTxPowerInDbm = 20;
566 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("First Channel = %d, Channel Num = %d, MaxDbm = %d\n",
569 pTriple->MaxTxPowerInDbm));
572 pAssoStrc->Length = (u16)len;
573 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, ("AssocPreferredChannelList : \n"), pAssoStrc, pAssoStrc->Length+3);
575 return pAssoStrc->Length + 3;
578 static u16 bthci_AssocPALVer(struct rtw_adapter *padapter, void *pbuf)
580 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
584 pAssoStrc->TypeID = AMP_80211_PAL_VISION;
585 pAssoStrc->Length = 0x5;
586 pu1Tmp = &pAssoStrc->Data[0];
587 *pu1Tmp = 0x1; /* PAL Version */
588 pu2Tmp = (u16 *)&pAssoStrc->Data[1];
589 *pu2Tmp = 0x5D; /* SIG Company identifier of 802.11 PAL vendor */
590 pu2Tmp = (u16 *)&pAssoStrc->Data[3];
591 *pu2Tmp = 0x1; /* PAL Sub-version specifier */
593 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("AssocPALVer : \n"), pAssoStrc, pAssoStrc->Length+3);
594 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("AssocPALVer \n"));
596 RTPRINT(FIOCTL, IOCTL_BT_LOGO, (" TypeID = 0x%x,\n Length = 0x%x,\n PAL Version = 0x01,\n PAL vendor = 0x01,\n PAL Sub-version specifier = 0x01\n",
599 return pAssoStrc->Length + 3;
602 static u8 bthci_CheckRfStateBeforeConnect(struct rtw_adapter *padapter)
604 struct bt_30info *pBTInfo;
605 enum rt_rf_power_state RfState;
607 pBTInfo = GET_BT_INFO(padapter);
609 RfState = padapter->pwrctrlpriv.rf_pwrstate;
611 if (RfState != rf_on) {
612 mod_timer(&pBTInfo->BTPsDisableTimer,
613 jiffies + msecs_to_jiffies(50));
619 static void bthci_ResponderStartToScan(struct rtw_adapter *padapter)
623 static u8 bthci_PhyLinkConnectionInProgress(struct rtw_adapter *padapter, u8 PhyLinkHandle)
625 struct bt_30info *pBTInfo;
626 struct bt_mgnt *pBtMgnt;
628 pBTInfo = GET_BT_INFO(padapter);
629 pBtMgnt = &pBTInfo->BtMgnt;
631 if (pBtMgnt->bPhyLinkInProgress &&
632 (pBtMgnt->BtCurrentPhyLinkhandle == PhyLinkHandle))
637 static void bthci_ResetFlowSpec(struct rtw_adapter *padapter, u8 EntryNum, u8 index)
639 struct bt_30info *pBTinfo;
641 pBTinfo = GET_BT_INFO(padapter);
643 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtLogLinkhandle = 0;
644 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtPhyLinkhandle = 0;
645 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCompleteEventIsSet = false;
646 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCancelCMDIsSetandComplete = false;
647 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtTxFlowSpecID = 0;
648 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].TxPacketCount = 0;
650 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.Identifier = 0x01;
651 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
652 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.MaximumSDUSize = 0xffff;
653 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
654 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.AccessLatency = 0xffffffff;
655 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.FlushTimeout = 0xffffffff;
657 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.Identifier = 0x01;
658 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
659 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.MaximumSDUSize = 0xffff;
660 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
661 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.AccessLatency = 0xffffffff;
662 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.FlushTimeout = 0xffffffff;
665 static void bthci_ResetEntry(struct rtw_adapter *padapter, u8 EntryNum)
667 struct bt_30info *pBTinfo;
668 struct bt_mgnt *pBtMgnt;
671 pBTinfo = GET_BT_INFO(padapter);
672 pBtMgnt = &pBTinfo->BtMgnt;
674 pBTinfo->BtAsocEntry[EntryNum].bUsed = false;
675 pBTinfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_DISCONNECTED;
676 pBTinfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED;
678 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen = 0;
679 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = 0;
680 if (pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment != NULL)
681 memset(pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment, 0, TOTAL_ALLOCIATE_ASSOC_LEN);
682 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = 0;
684 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = 0;
685 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = 0;
686 memset(pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, 0,
687 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
688 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = 0;
690 /* 0x640; 0.625ms*1600 = 1000ms, 0.625ms*16000 = 10000ms */
691 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = 0x3e80;
693 pBTinfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_NONE;
695 pBTinfo->BtAsocEntry[EntryNum].mAssoc = false;
696 pBTinfo->BtAsocEntry[EntryNum].b4waySuccess = false;
699 pBTinfo->BtAsocEntry[EntryNum].KeyReplayCounter = 0;
700 pBTinfo->BtAsocEntry[EntryNum].BTWPAAuthState = STATE_WPA_AUTH_UNINITIALIZED;
702 pBTinfo->BtAsocEntry[EntryNum].bSendSupervisionPacket = false;
703 pBTinfo->BtAsocEntry[EntryNum].NoRxPktCnt = 0;
704 pBTinfo->BtAsocEntry[EntryNum].ShortRangeMode = 0;
705 pBTinfo->BtAsocEntry[EntryNum].rxSuvpPktCnt = 0;
707 for (j = 0; j < MAX_LOGICAL_LINK_NUM; j++)
708 bthci_ResetFlowSpec(padapter, EntryNum, j);
710 pBtMgnt->BTAuthCount = 0;
711 pBtMgnt->BTAsocCount = 0;
712 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
713 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
715 HALBT_RemoveKey(padapter, EntryNum);
718 static void bthci_RemoveEntryByEntryNum(struct rtw_adapter *padapter, u8 EntryNum)
720 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
721 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
723 bthci_ResetEntry(padapter, EntryNum);
725 if (pBtMgnt->CurrentBTConnectionCnt > 0)
726 pBtMgnt->CurrentBTConnectionCnt--;
728 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d!!\n",
729 pBtMgnt->CurrentBTConnectionCnt));
731 if (pBtMgnt->CurrentBTConnectionCnt > 0) {
732 pBtMgnt->BtOperationOn = true;
734 pBtMgnt->BtOperationOn = false;
735 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation OFF!!\n"));
738 if (!pBtMgnt->BtOperationOn) {
739 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
740 del_timer_sync(&pBTInfo->BTBeaconTimer);
741 pBtMgnt->bStartSendSupervisionPkt = false;
746 bthci_CommandCompleteHeader(
750 enum hci_status status
753 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
754 u8 NumHCI_Comm = 0x1;
756 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
757 PPacketIrpEvent->Data[0] = NumHCI_Comm; /* packet # */
758 PPacketIrpEvent->Data[1] = HCIOPCODELOW(OCF, OGF);
759 PPacketIrpEvent->Data[2] = HCIOPCODEHIGHT(OCF, OGF);
761 if (OGF == OGF_EXTENSION) {
762 if (OCF == HCI_SET_RSSI_VALUE) {
763 RTPRINT(FIOCTL, (IOCTL_BT_EVENT_PERIODICAL),
764 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
765 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
767 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_EXT),
768 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
769 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
772 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
773 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
774 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
779 static u8 bthci_ExtensionEventHeaderRtk(u8 *pbuf, u8 extensionEvent)
781 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
782 PPacketIrpEvent->EventCode = HCI_EVENT_EXTENSION_RTK;
783 PPacketIrpEvent->Data[0] = extensionEvent; /* extension event code */
788 static enum rt_status
790 struct rtw_adapter *padapter,
795 return PlatformIndicateBTEvent(padapter, pEvntData, dataLen);
799 bthci_EventWriteRemoteAmpAssoc(
800 struct rtw_adapter *padapter,
801 enum hci_status status,
805 u8 localBuf[TmpLocalBufSize] = "";
808 struct packet_irp_hcievent_data *PPacketIrpEvent;
810 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
811 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
813 len += bthci_CommandCompleteHeader(&localBuf[0],
814 OGF_STATUS_PARAMETERS,
815 HCI_WRITE_REMOTE_AMP_ASSOC,
817 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("PhyLinkHandle = 0x%x, status = %d\n", PLHandle, status));
818 /* Return parameters starts from here */
819 pRetPar = &PPacketIrpEvent->Data[len];
820 pRetPar[0] = status; /* status */
821 pRetPar[1] = PLHandle;
823 PPacketIrpEvent->Length = len;
825 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
829 bthci_EventEnhancedFlushComplete(
830 struct rtw_adapter *padapter,
835 struct packet_irp_hcievent_data *PPacketIrpEvent;
837 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("EventEnhancedFlushComplete, LLH = 0x%x\n", LLH));
839 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
840 PPacketIrpEvent->EventCode = HCI_EVENT_ENHANCED_FLUSH_COMPLETE;
841 PPacketIrpEvent->Length = 2;
842 /* Logical link handle */
843 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LLH);
844 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LLH);
846 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
850 bthci_EventShortRangeModeChangeComplete(
851 struct rtw_adapter *padapter,
852 enum hci_status HciStatus,
857 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
858 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
860 struct packet_irp_hcievent_data *PPacketIrpEvent;
862 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE)) {
863 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
864 ("[BT event], Short Range Mode Change Complete, Ignore to send this event due to event mask page 2\n"));
867 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Short Range Mode Change Complete, Status = %d\n , PLH = 0x%x\n, Short_Range_Mode_State = 0x%x\n",
868 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, ShortRangeState));
870 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
871 PPacketIrpEvent->EventCode = HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE;
872 PPacketIrpEvent->Length = 3;
873 PPacketIrpEvent->Data[0] = HciStatus;
874 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
875 PPacketIrpEvent->Data[2] = ShortRangeState;
876 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
879 static void bthci_EventSendFlowSpecModifyComplete(struct rtw_adapter *padapter,
880 enum hci_status HciStatus,
884 struct packet_irp_hcievent_data *PPacketIrpEvent;
885 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
886 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
888 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE)) {
889 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
890 ("[BT event], Flow Spec Modify Complete, Ignore to send this event due to event mask page 2\n"));
893 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
894 ("[BT event], Flow Spec Modify Complete, status = 0x%x, LLH = 0x%x\n", HciStatus, logicHandle));
895 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
896 PPacketIrpEvent->EventCode = HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE;
897 PPacketIrpEvent->Length = 3;
899 PPacketIrpEvent->Data[0] = HciStatus;
900 /* Logical link handle */
901 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(logicHandle);
902 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(logicHandle);
904 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
908 bthci_EventExtWifiScanNotify(
909 struct rtw_adapter *padapter,
913 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
914 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
919 struct packet_irp_hcievent_data *PPacketIrpEvent;
921 if (!pBtMgnt->BtOperationOn)
924 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
926 len += bthci_ExtensionEventHeaderRtk(&localBuf[0], HCI_EVENT_EXT_WIFI_SCAN_NOTIFY);
928 /* Return parameters starts from here */
929 pRetPar = &PPacketIrpEvent->Data[len];
930 pu1Temp = (u8 *)&pRetPar[0];
934 PPacketIrpEvent->Length = len;
936 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS) {
937 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Wifi scan notify, scan type = %d\n",
943 bthci_EventAMPReceiverReport(
944 struct rtw_adapter *padapter,
948 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
949 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
951 if (pBtHciInfo->bTestNeedReport) {
952 u8 localBuf[20] = "";
955 struct packet_irp_hcievent_data *PPacketIrpEvent;
957 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_EVENT_AMP_RECEIVER_REPORT\n"));
958 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
959 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_RECEIVER_REPORT;
960 PPacketIrpEvent->Length = 2;
962 PPacketIrpEvent->Data[0] = pBtHciInfo->TestCtrType;
964 PPacketIrpEvent->Data[1] = Reason;
966 pu4Temp = (u32 *)&PPacketIrpEvent->Data[2];
967 *pu4Temp = pBtHciInfo->TestEventType;
969 pu2Temp = (u16 *)&PPacketIrpEvent->Data[6];
970 *pu2Temp = pBtHciInfo->TestNumOfFrame;
972 pu2Temp = (u16 *)&PPacketIrpEvent->Data[8];
973 *pu2Temp = pBtHciInfo->TestNumOfErrFrame;
975 pu4Temp = (u32 *)&PPacketIrpEvent->Data[10];
976 *pu4Temp = pBtHciInfo->TestNumOfBits;
978 pu4Temp = (u32 *)&PPacketIrpEvent->Data[14];
979 *pu4Temp = pBtHciInfo->TestNumOfErrBits;
981 bthci_IndicateEvent(padapter, PPacketIrpEvent, 20);
983 /* Return to Idel state with RX and TX off. */
987 pBtHciInfo->TestNumOfFrame = 0x00;
991 bthci_EventChannelSelected(
992 struct rtw_adapter *padapter,
996 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
997 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
999 struct packet_irp_hcievent_data *PPacketIrpEvent;
1001 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_CHANNEL_SELECT)) {
1002 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1003 ("[BT event], Channel Selected, Ignore to send this event due to event mask page 2\n"));
1007 RTPRINT(FIOCTL, IOCTL_BT_EVENT|IOCTL_STATE,
1008 ("[BT event], Channel Selected, PhyLinkHandle %d\n",
1009 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle));
1011 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1012 PPacketIrpEvent->EventCode = HCI_EVENT_CHANNEL_SELECT;
1013 PPacketIrpEvent->Length = 1;
1014 PPacketIrpEvent->Data[0] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1015 bthci_IndicateEvent(padapter, PPacketIrpEvent, 3);
1019 bthci_EventDisconnectPhyLinkComplete(
1020 struct rtw_adapter *padapter,
1021 enum hci_status HciStatus,
1022 enum hci_status Reason,
1026 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1027 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1028 u8 localBuf[5] = "";
1029 struct packet_irp_hcievent_data *PPacketIrpEvent;
1031 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE)) {
1032 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1033 ("[BT event], Disconnect Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1036 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1037 ("[BT event], Disconnect Physical Link Complete, Status = 0x%x, PLH = 0x%x Reason = 0x%x\n",
1038 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, Reason));
1039 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1040 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE;
1041 PPacketIrpEvent->Length = 3;
1042 PPacketIrpEvent->Data[0] = HciStatus;
1043 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1044 PPacketIrpEvent->Data[2] = Reason;
1045 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
1049 bthci_EventPhysicalLinkComplete(
1050 struct rtw_adapter *padapter,
1051 enum hci_status HciStatus,
1056 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1057 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1058 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1059 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1060 u8 localBuf[4] = "";
1061 struct packet_irp_hcievent_data *PPacketIrpEvent;
1064 pBtMgnt->bPhyLinkInProgress = false;
1065 pBtDbg->dbgHciInfo.hciCmdPhyLinkStatus = HciStatus;
1066 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_PHY_LINK_COMPLETE)) {
1067 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1068 ("[BT event], Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1072 if (EntryNum == 0xff) {
1073 /* connection not started yet, just use the input physical link handle to response. */
1074 PL_handle = PLHandle;
1076 /* connection is under progress, use the phy link handle we recorded. */
1077 PL_handle = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1078 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = false;
1081 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Physical Link Complete, Status = 0x%x PhyLinkHandle = 0x%x\n", HciStatus,
1084 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1085 PPacketIrpEvent->EventCode = HCI_EVENT_PHY_LINK_COMPLETE;
1086 PPacketIrpEvent->Length = 2;
1088 PPacketIrpEvent->Data[0] = HciStatus;
1089 PPacketIrpEvent->Data[1] = PL_handle;
1090 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1095 bthci_EventCommandStatus(
1096 struct rtw_adapter *padapter,
1099 enum hci_status HciStatus
1103 u8 localBuf[6] = "";
1104 struct packet_irp_hcievent_data *PPacketIrpEvent;
1105 u8 Num_Hci_Comm = 0x1;
1106 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1107 ("[BT event], CommandStatus, Opcode = 0x%02x%02x, OGF = 0x%x, OCF = 0x%x, Status = 0x%x, Num_HCI_COMM = 0x%x\n",
1108 (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), OGF, OCF, HciStatus, Num_Hci_Comm));
1110 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1111 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_STATUS;
1112 PPacketIrpEvent->Length = 4;
1113 PPacketIrpEvent->Data[0] = HciStatus; /* current pending */
1114 PPacketIrpEvent->Data[1] = Num_Hci_Comm; /* packet # */
1115 PPacketIrpEvent->Data[2] = HCIOPCODELOW(OCF, OGF);
1116 PPacketIrpEvent->Data[3] = HCIOPCODEHIGHT(OCF, OGF);
1118 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1123 bthci_EventLogicalLinkComplete(
1124 struct rtw_adapter *padapter,
1125 enum hci_status HciStatus,
1132 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1133 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1134 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1135 u8 localBuf[7] = "";
1136 struct packet_irp_hcievent_data *PPacketIrpEvent;
1138 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_LOGICAL_LINK_COMPLETE)) {
1139 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1140 ("[BT event], Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1143 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Logical Link Complete, PhyLinkHandle = 0x%x, LogLinkHandle = 0x%x, Status = 0x%x\n",
1144 PhyLinkHandle, LogLinkHandle, HciStatus));
1146 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1147 PPacketIrpEvent->EventCode = HCI_EVENT_LOGICAL_LINK_COMPLETE;
1148 PPacketIrpEvent->Length = 5;
1150 PPacketIrpEvent->Data[0] = HciStatus;/* status code */
1151 /* Logical link handle */
1152 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1153 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1154 /* Physical link handle */
1155 PPacketIrpEvent->Data[3] = TWOBYTE_LOWBYTE(PhyLinkHandle);
1156 /* corresponding Tx flow spec ID */
1157 if (HciStatus == HCI_STATUS_SUCCESS) {
1158 PPacketIrpEvent->Data[4] =
1159 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData[LogLinkIndex].Tx_Flow_Spec.Identifier;
1161 PPacketIrpEvent->Data[4] = 0x0;
1164 bthci_IndicateEvent(padapter, PPacketIrpEvent, 7);
1168 bthci_EventDisconnectLogicalLinkComplete(
1169 struct rtw_adapter *padapter,
1170 enum hci_status HciStatus,
1172 enum hci_status Reason
1175 u8 localBuf[6] = "";
1176 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1177 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1178 struct packet_irp_hcievent_data *PPacketIrpEvent;
1180 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE)) {
1181 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1184 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Status = 0x%x, LLH = 0x%x Reason = 0x%x\n", HciStatus, LogLinkHandle, Reason));
1186 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1187 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE;
1188 PPacketIrpEvent->Length = 4;
1190 PPacketIrpEvent->Data[0] = HciStatus;
1191 /* Logical link handle */
1192 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1193 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1194 /* Disconnect reason */
1195 PPacketIrpEvent->Data[3] = Reason;
1197 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1201 bthci_EventFlushOccurred(
1202 struct rtw_adapter *padapter,
1206 u8 localBuf[4] = "";
1207 struct packet_irp_hcievent_data *PPacketIrpEvent;
1208 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("bthci_EventFlushOccurred(), LLH = 0x%x\n", LogLinkHandle));
1210 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1211 PPacketIrpEvent->EventCode = HCI_EVENT_FLUSH_OCCRUED;
1212 PPacketIrpEvent->Length = 2;
1213 /* Logical link handle */
1214 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LogLinkHandle);
1215 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1217 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1220 static enum hci_status
1221 bthci_BuildPhysicalLink(
1222 struct rtw_adapter *padapter,
1223 struct packet_irp_hcicmd_data *pHciCmd,
1227 enum hci_status status = HCI_STATUS_SUCCESS;
1228 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1229 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1232 /* Send HCI Command status event to AMP. */
1233 bthci_EventCommandStatus(padapter,
1234 LINK_CONTROL_COMMANDS,
1236 HCI_STATUS_SUCCESS);
1238 PLH = *((u8 *)pHciCmd->Data);
1240 /* Check if resource or bt connection is under progress, if yes, reject the link creation. */
1241 if (!bthci_AddEntry(padapter)) {
1242 status = HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE;
1243 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1247 EntryNum = pBtMgnt->CurrentConnectEntryNum;
1248 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = PLH;
1249 pBtMgnt->BtCurrentPhyLinkhandle = PLH;
1251 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1252 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Create/Accept PhysicalLink, AMP controller is busy\n"));
1253 status = HCI_STATUS_CONTROLLER_BUSY;
1254 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1258 /* Record Key and the info */
1259 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = (*((u8 *)pHciCmd->Data+1));
1260 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = (*((u8 *)pHciCmd->Data+2));
1261 memcpy(pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1262 (((u8 *)pHciCmd->Data+3)), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1263 memcpy(pBTInfo->BtAsocEntry[EntryNum].PMK, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, PMK_LEN);
1264 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildPhysicalLink, EntryNum = %d, PLH = 0x%x KeyLen = 0x%x, KeyType = 0x%x\n",
1265 EntryNum, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1266 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen,
1267 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType));
1268 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("BtAMPKey\n"), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1269 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1270 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("PMK\n"), pBTInfo->BtAsocEntry[EntryNum].PMK,
1273 if (OCF == HCI_CREATE_PHYSICAL_LINK) {
1274 /* These macros require braces */
1275 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_CREATE_PHY_LINK, EntryNum);
1276 } else if (OCF == HCI_ACCEPT_PHYSICAL_LINK) {
1277 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ACCEPT_PHY_LINK, EntryNum);
1284 bthci_BuildLogicalLink(
1285 struct rtw_adapter *padapter,
1286 struct packet_irp_hcicmd_data *pHciCmd,
1290 enum hci_status status = HCI_STATUS_SUCCESS;
1291 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1292 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
1293 u8 PhyLinkHandle, EntryNum;
1294 static u16 AssignLogHandle = 1;
1296 struct hci_flow_spec TxFlowSpec;
1297 struct hci_flow_spec RxFlowSpec;
1298 u32 MaxSDUSize, ArriveTime, Bandwidth;
1300 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1302 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1305 &pHciCmd->Data[1], sizeof(struct hci_flow_spec));
1307 &pHciCmd->Data[17], sizeof(struct hci_flow_spec));
1309 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
1310 ArriveTime = TxFlowSpec.SDUInterArrivalTime;
1312 if (bthci_CheckLogLinkBehavior(padapter, TxFlowSpec) && bthci_CheckLogLinkBehavior(padapter, RxFlowSpec))
1313 Bandwidth = BTTOTALBANDWIDTH;
1314 else if (MaxSDUSize == 0xffff && ArriveTime == 0xffffffff)
1315 Bandwidth = BTTOTALBANDWIDTH;
1317 Bandwidth = MaxSDUSize*8*1000/(ArriveTime+244);
1319 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
1320 ("BuildLogicalLink, PhyLinkHandle = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, Bandwidth = 0x%x\n",
1321 PhyLinkHandle, MaxSDUSize, ArriveTime, Bandwidth));
1323 if (EntryNum == 0xff) {
1324 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Invalid Physical Link handle = 0x%x, status = HCI_STATUS_UNKNOW_CONNECT_ID, return\n", PhyLinkHandle));
1325 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1327 /* When we receive Create/Accept logical link command, we should send command status event first. */
1328 bthci_EventCommandStatus(padapter,
1329 LINK_CONTROL_COMMANDS,
1335 if (!pBtMgnt->bLogLinkInProgress) {
1336 if (bthci_PhyLinkConnectionInProgress(padapter, PhyLinkHandle)) {
1337 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Physical link connection in progress, status = HCI_STATUS_CMD_DISALLOW, return\n"));
1338 status = HCI_STATUS_CMD_DISALLOW;
1340 pBtMgnt->bPhyLinkInProgressStartLL = true;
1341 /* When we receive Create/Accept logical link command, we should send command status event first. */
1342 bthci_EventCommandStatus(padapter,
1343 LINK_CONTROL_COMMANDS,
1350 if (Bandwidth > BTTOTALBANDWIDTH) {
1351 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_QOS_REJECT, Bandwidth = 0x%x, return\n", Bandwidth));
1352 status = HCI_STATUS_QOS_REJECT;
1354 /* When we receive Create/Accept logical link command, we should send command status event first. */
1355 bthci_EventCommandStatus(padapter,
1356 LINK_CONTROL_COMMANDS,
1360 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_SUCCESS\n"));
1361 status = HCI_STATUS_SUCCESS;
1363 /* When we receive Create/Accept logical link command, we should send command status event first. */
1364 bthci_EventCommandStatus(padapter,
1365 LINK_CONTROL_COMMANDS,
1371 if (pBTinfo->BtAsocEntry[EntryNum].BtCurrentState != HCI_STATE_CONNECTED) {
1372 bthci_EventLogicalLinkComplete(padapter,
1373 HCI_STATUS_CMD_DISALLOW, 0, 0, 0, EntryNum);
1377 pBtMgnt->bLogLinkInProgress = true;
1379 /* find an unused logical link index and copy the data */
1380 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
1381 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle == 0) {
1382 enum hci_status LogCompEventstatus = HCI_STATUS_SUCCESS;
1384 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
1385 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle = AssignLogHandle;
1386 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildLogicalLink, EntryNum = %d, physical link handle = 0x%x, logical link handle = 0x%x\n",
1387 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1388 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle));
1389 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Tx_Flow_Spec,
1390 &TxFlowSpec, sizeof(struct hci_flow_spec));
1391 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Rx_Flow_Spec,
1392 &RxFlowSpec, sizeof(struct hci_flow_spec));
1394 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = false;
1396 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCancelCMDIsSetandComplete)
1397 LogCompEventstatus = HCI_STATUS_UNKNOW_CONNECT_ID;
1398 bthci_EventLogicalLinkComplete(padapter,
1400 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle,
1401 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle, i, EntryNum);
1403 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = true;
1406 pBtMgnt->BtCurrentLogLinkhandle = AssignLogHandle;
1413 bthci_EventLogicalLinkComplete(padapter,
1414 HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE, 0, 0, 0, EntryNum);
1416 pBtMgnt->bLogLinkInProgress = false;
1419 bthci_EventLogicalLinkComplete(padapter,
1420 HCI_STATUS_CONTROLLER_BUSY, 0, 0, 0, EntryNum);
1426 bthci_StartBeaconAndConnect(
1427 struct rtw_adapter *padapter,
1428 struct packet_irp_hcicmd_data *pHciCmd,
1432 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1433 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1434 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1436 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("StartBeaconAndConnect, CurrentAssocNum =%d, AMPRole =%d\n",
1438 pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole));
1440 if (!pBtMgnt->CheckChnlIsSuit) {
1441 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONNECT_REJ_NOT_SUIT_CHNL_FOUND, CurrentAssocNum, INVALID_PL_HANDLE);
1442 bthci_RemoveEntryByEntryNum(padapter, CurrentAssocNum);
1446 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1447 snprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32,
1448 "AMP-%pMF", padapter->eeprompriv.mac_addr);
1449 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1450 snprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32,
1451 "AMP-%pMF", pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr);
1454 FillOctetString(pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid, pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 21);
1455 pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid.Length = 21;
1457 /* To avoid set the start ap or connect twice, or the original connection will be disconnected. */
1458 if (!pBtMgnt->bBTConnectInProgress) {
1459 pBtMgnt->bBTConnectInProgress = true;
1460 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress ON!!\n"));
1461 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_STARTING, STATE_CMD_MAC_START_COMPLETE, CurrentAssocNum);
1463 /* 20100325 Joseph: Check RF ON/OFF. */
1464 /* If RF OFF, it reschedule connecting operation after 50ms. */
1465 if (!bthci_CheckRfStateBeforeConnect(padapter))
1468 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1469 /* These macros need braces */
1470 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_COMPLETE, CurrentAssocNum);
1471 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1472 bthci_ResponderStartToScan(padapter);
1475 RT_PRINT_STR(_module_rtl871x_mlme_c_, _drv_notice_,
1476 "StartBeaconAndConnect, SSID:\n",
1477 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Octet,
1478 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Length);
1481 static void bthci_ResetBtMgnt(struct bt_mgnt *pBtMgnt)
1483 pBtMgnt->BtOperationOn = false;
1484 pBtMgnt->bBTConnectInProgress = false;
1485 pBtMgnt->bLogLinkInProgress = false;
1486 pBtMgnt->bPhyLinkInProgress = false;
1487 pBtMgnt->bPhyLinkInProgressStartLL = false;
1488 pBtMgnt->DisconnectEntryNum = 0xff;
1489 pBtMgnt->bStartSendSupervisionPkt = false;
1490 pBtMgnt->JoinerNeedSendAuth = false;
1491 pBtMgnt->CurrentBTConnectionCnt = 0;
1492 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
1493 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
1494 pBtMgnt->BTAuthCount = 0;
1495 pBtMgnt->btLogoTest = 0;
1498 static void bthci_ResetBtHciInfo(struct bt_hci_info *pBtHciInfo)
1500 pBtHciInfo->BTEventMask = 0;
1501 pBtHciInfo->BTEventMaskPage2 = 0;
1502 pBtHciInfo->ConnAcceptTimeout = 10000;
1503 pBtHciInfo->PageTimeout = 0x30;
1504 pBtHciInfo->LocationDomainAware = 0x0;
1505 pBtHciInfo->LocationDomain = 0x5858;
1506 pBtHciInfo->LocationDomainOptions = 0x58;
1507 pBtHciInfo->LocationOptions = 0x0;
1508 pBtHciInfo->FlowControlMode = 0x1; /* 0:Packet based data flow control mode(BR/EDR), 1: Data block based data flow control mode(AMP). */
1510 pBtHciInfo->enFlush_LLH = 0;
1511 pBtHciInfo->FLTO_LLH = 0;
1513 /* Test command only */
1514 pBtHciInfo->bTestIsEnd = true;
1515 pBtHciInfo->bInTestMode = false;
1516 pBtHciInfo->bTestNeedReport = false;
1517 pBtHciInfo->TestScenario = 0xff;
1518 pBtHciInfo->TestReportInterval = 0x01;
1519 pBtHciInfo->TestCtrType = 0x5d;
1520 pBtHciInfo->TestEventType = 0x00;
1521 pBtHciInfo->TestNumOfFrame = 0;
1522 pBtHciInfo->TestNumOfErrFrame = 0;
1523 pBtHciInfo->TestNumOfBits = 0;
1524 pBtHciInfo->TestNumOfErrBits = 0;
1527 static void bthci_ResetBtSec(struct rtw_adapter *padapter, struct bt_security *pBtSec)
1529 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1531 /* Set BT used HW or SW encrypt !! */
1532 if (GET_HAL_DATA(padapter)->bBTMode)
1533 pBtSec->bUsedHwEncrypt = true;
1535 pBtSec->bUsedHwEncrypt = false;
1536 RT_TRACE(_module_rtl871x_security_c_, _drv_info_,
1537 "%s: bUsedHwEncrypt =%d\n", __func__, pBtSec->bUsedHwEncrypt);
1539 pBtSec->RSNIE.Octet = pBtSec->RSNIEBuf;
1542 static void bthci_ResetBtExtInfo(struct bt_mgnt *pBtMgnt)
1546 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
1547 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = 0;
1548 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = 0;
1549 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = 0;
1550 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = BT_PROFILE_NONE;
1551 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = BT_SPEC_2_1_EDR;
1552 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = 0;
1553 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
1554 pBtMgnt->ExtConfig.linkInfo[i].linkRole = BT_LINK_MASTER;
1557 pBtMgnt->ExtConfig.CurrentConnectHandle = 0;
1558 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = 0;
1559 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = 0;
1560 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
1561 pBtMgnt->ExtConfig.NumberOfHandle = 0;
1562 pBtMgnt->ExtConfig.NumberOfSCO = 0;
1563 pBtMgnt->ExtConfig.CurrentBTStatus = 0;
1564 pBtMgnt->ExtConfig.HCIExtensionVer = 0;
1566 pBtMgnt->ExtConfig.bManualControl = false;
1567 pBtMgnt->ExtConfig.bBTBusy = false;
1568 pBtMgnt->ExtConfig.bBTA2DPBusy = false;
1571 static enum hci_status bthci_CmdReset(struct rtw_adapter *_padapter, u8 bNeedSendEvent)
1573 enum hci_status status = HCI_STATUS_SUCCESS;
1574 struct rtw_adapter *padapter;
1575 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1576 struct bt_30info *pBTInfo;
1577 struct bt_mgnt *pBtMgnt;
1578 struct bt_hci_info *pBtHciInfo;
1579 struct bt_security *pBtSec;
1580 struct bt_dgb *pBtDbg;
1583 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_CmdReset()\n"));
1585 padapter = GetDefaultAdapter(_padapter);
1586 pBTInfo = GET_BT_INFO(padapter);
1587 pBtMgnt = &pBTInfo->BtMgnt;
1588 pBtHciInfo = &pBTInfo->BtHciInfo;
1589 pBtSec = &pBTInfo->BtSec;
1590 pBtDbg = &pBTInfo->BtDbg;
1592 pBTInfo->padapter = padapter;
1594 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++)
1595 bthci_ResetEntry(padapter, i);
1597 bthci_ResetBtMgnt(pBtMgnt);
1598 bthci_ResetBtHciInfo(pBtHciInfo);
1599 bthci_ResetBtSec(padapter, pBtSec);
1601 pBtMgnt->BTChannel = BT_Default_Chnl;
1602 pBtMgnt->CheckChnlIsSuit = true;
1604 pBTInfo->BTBeaconTmrOn = false;
1606 pBtMgnt->bCreateSpportQos = true;
1608 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
1609 del_timer_sync(&pBTInfo->BTBeaconTimer);
1611 HALBT_SetRtsCtsNoLenLimit(padapter);
1613 /* Maybe we need to take care Group != AES case !! */
1614 /* now we Pairwise and Group all used AES !! */
1616 bthci_ResetBtExtInfo(pBtMgnt);
1618 /* send command complete event here when all data are received. */
1619 if (bNeedSendEvent) {
1620 u8 localBuf[6] = "";
1623 struct packet_irp_hcievent_data *PPacketIrpEvent;
1625 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1627 len += bthci_CommandCompleteHeader(&localBuf[0],
1628 OGF_SET_EVENT_MASK_COMMAND,
1632 /* Return parameters starts from here */
1633 pRetPar = &PPacketIrpEvent->Data[len];
1634 pRetPar[0] = status; /* status */
1636 PPacketIrpEvent->Length = len;
1638 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1644 static enum hci_status
1645 bthci_CmdWriteRemoteAMPAssoc(
1646 struct rtw_adapter *padapter,
1647 struct packet_irp_hcicmd_data *pHciCmd
1650 enum hci_status status = HCI_STATUS_SUCCESS;
1651 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1652 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1656 pBtDbg->dbgHciInfo.hciCmdCntWriteRemoteAmpAssoc++;
1657 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1658 CurrentAssocNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1660 if (CurrentAssocNum == 0xff) {
1661 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, No such Handle in the Entry\n"));
1662 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1663 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1667 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1668 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, AMP controller is busy\n"));
1669 status = HCI_STATUS_CONTROLLER_BUSY;
1670 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1674 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.BtPhyLinkhandle = PhyLinkHandle;/* u8 *)pHciCmd->Data); */
1675 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
1676 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen = *((u16 *)((u8 *)pHciCmd->Data+3));
1678 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, LenSoFar = 0x%x, AssocRemLen = 0x%x\n",
1679 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar,
1680 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1682 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
1683 ("WriteRemoteAMPAssoc fragment \n"),
1685 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen+5);
1686 if ((pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen) > MAX_AMP_ASSOC_FRAG_LEN) {
1687 memcpy(((u8 *)pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8)))),
1688 (u8 *)pHciCmd->Data+5,
1689 MAX_AMP_ASSOC_FRAG_LEN);
1691 memcpy((u8 *)(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment)+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8))),
1692 ((u8 *)pHciCmd->Data+5),
1693 (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1695 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "WriteRemoteAMPAssoc :\n",
1696 pHciCmd->Data+5, pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen);
1698 if (!bthci_GetAssocInfo(padapter, CurrentAssocNum))
1699 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
1701 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1703 bthci_StartBeaconAndConnect(padapter, pHciCmd, CurrentAssocNum);
1710 static enum hci_status bthci_CmdReadConnectionAcceptTimeout(struct rtw_adapter *padapter)
1712 enum hci_status status = HCI_STATUS_SUCCESS;
1713 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1714 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1715 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1716 u8 localBuf[8] = "";
1719 struct packet_irp_hcievent_data *PPacketIrpEvent;
1722 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1724 len += bthci_CommandCompleteHeader(&localBuf[0],
1725 OGF_SET_EVENT_MASK_COMMAND,
1726 HCI_READ_CONNECTION_ACCEPT_TIMEOUT,
1729 /* Return parameters starts from here */
1730 pRetPar = &PPacketIrpEvent->Data[len];
1731 pRetPar[0] = status; /* status */
1732 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
1733 *pu2Temp = pBtHciInfo->ConnAcceptTimeout;
1735 PPacketIrpEvent->Length = len;
1737 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1743 static enum hci_status
1744 bthci_CmdWriteConnectionAcceptTimeout(
1745 struct rtw_adapter *padapter,
1746 struct packet_irp_hcicmd_data *pHciCmd
1749 enum hci_status status = HCI_STATUS_SUCCESS;
1750 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1751 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1753 u8 localBuf[6] = "";
1756 struct packet_irp_hcievent_data *PPacketIrpEvent;
1758 pu2Temp = (u16 *)&pHciCmd->Data[0];
1759 pBtHciInfo->ConnAcceptTimeout = *pu2Temp;
1760 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ConnAcceptTimeout = 0x%x",
1761 pBtHciInfo->ConnAcceptTimeout));
1763 /* send command complete event here when all data are received. */
1764 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1766 len += bthci_CommandCompleteHeader(&localBuf[0],
1767 OGF_SET_EVENT_MASK_COMMAND,
1768 HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT,
1771 /* Return parameters starts from here */
1772 pRetPar = &PPacketIrpEvent->Data[len];
1773 pRetPar[0] = status; /* status */
1775 PPacketIrpEvent->Length = len;
1777 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1782 static enum hci_status
1783 bthci_CmdReadPageTimeout(
1784 struct rtw_adapter *padapter,
1785 struct packet_irp_hcicmd_data *pHciCmd
1788 enum hci_status status = HCI_STATUS_SUCCESS;
1789 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1790 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1791 u8 localBuf[8] = "";
1794 struct packet_irp_hcievent_data *PPacketIrpEvent;
1797 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1799 len += bthci_CommandCompleteHeader(&localBuf[0],
1800 OGF_SET_EVENT_MASK_COMMAND,
1801 HCI_READ_PAGE_TIMEOUT,
1804 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Read PageTimeout = 0x%x\n", pBtHciInfo->PageTimeout));
1805 /* Return parameters starts from here */
1806 pRetPar = &PPacketIrpEvent->Data[len];
1807 pRetPar[0] = status; /* status */
1808 pu2Temp = (u16 *)&pRetPar[1]; /* Page_Timeout */
1809 *pu2Temp = pBtHciInfo->PageTimeout;
1811 PPacketIrpEvent->Length = len;
1813 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1818 static enum hci_status
1819 bthci_CmdWritePageTimeout(
1820 struct rtw_adapter *padapter,
1821 struct packet_irp_hcicmd_data *pHciCmd
1824 enum hci_status status = HCI_STATUS_SUCCESS;
1825 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1826 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1829 pu2Temp = (u16 *)&pHciCmd->Data[0];
1830 pBtHciInfo->PageTimeout = *pu2Temp;
1831 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Write PageTimeout = 0x%x\n",
1832 pBtHciInfo->PageTimeout));
1834 /* send command complete event here when all data are received. */
1836 u8 localBuf[6] = "";
1839 struct packet_irp_hcievent_data *PPacketIrpEvent;
1841 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1843 len += bthci_CommandCompleteHeader(&localBuf[0],
1844 OGF_SET_EVENT_MASK_COMMAND,
1845 HCI_WRITE_PAGE_TIMEOUT,
1848 /* Return parameters starts from here */
1849 pRetPar = &PPacketIrpEvent->Data[len];
1850 pRetPar[0] = status; /* status */
1852 PPacketIrpEvent->Length = len;
1854 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1860 static enum hci_status
1861 bthci_CmdReadLinkSupervisionTimeout(
1862 struct rtw_adapter *padapter,
1863 struct packet_irp_hcicmd_data *pHciCmd
1866 enum hci_status status = HCI_STATUS_SUCCESS;
1867 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1868 u8 physicalLinkHandle, EntryNum;
1870 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1872 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1874 if (EntryNum == 0xff) {
1875 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLinkSupervisionTimeout, No such Handle in the Entry\n"));
1876 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1880 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle)
1881 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1884 u8 localBuf[10] = "";
1887 struct packet_irp_hcievent_data *PPacketIrpEvent;
1890 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1892 len += bthci_CommandCompleteHeader(&localBuf[0],
1893 OGF_SET_EVENT_MASK_COMMAND,
1894 HCI_READ_LINK_SUPERVISION_TIMEOUT,
1897 /* Return parameters starts from here */
1898 pRetPar = &PPacketIrpEvent->Data[len];
1899 pRetPar[0] = status;
1900 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1902 pu2Temp = (u16 *)&pRetPar[3]; /* Conn_Accept_Timeout */
1903 *pu2Temp = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout;
1905 PPacketIrpEvent->Length = len;
1907 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1913 static enum hci_status
1914 bthci_CmdWriteLinkSupervisionTimeout(
1915 struct rtw_adapter *padapter,
1916 struct packet_irp_hcicmd_data *pHciCmd
1919 enum hci_status status = HCI_STATUS_SUCCESS;
1920 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1921 u8 physicalLinkHandle, EntryNum;
1923 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1925 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1927 if (EntryNum == 0xff) {
1928 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("WriteLinkSupervisionTimeout, No such Handle in the Entry\n"));
1929 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1931 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle) {
1932 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1934 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = *((u16 *)(((u8 *)pHciCmd->Data)+2));
1935 RTPRINT(FIOCTL, IOCTL_STATE, ("BT Write LinkSuperversionTimeout[%d] = 0x%x\n",
1936 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout));
1941 u8 localBuf[8] = "";
1944 struct packet_irp_hcievent_data *PPacketIrpEvent;
1946 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1948 len += bthci_CommandCompleteHeader(&localBuf[0],
1949 OGF_SET_EVENT_MASK_COMMAND,
1950 HCI_WRITE_LINK_SUPERVISION_TIMEOUT,
1953 /* Return parameters starts from here */
1954 pRetPar = &PPacketIrpEvent->Data[len];
1955 pRetPar[0] = status;
1956 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1959 PPacketIrpEvent->Length = len;
1961 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1967 static enum hci_status
1968 bthci_CmdEnhancedFlush(
1969 struct rtw_adapter *padapter,
1970 struct packet_irp_hcicmd_data *pHciCmd
1973 enum hci_status status = HCI_STATUS_SUCCESS;
1974 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1975 struct bt_hci_info *pBtHciInfo = &pBTinfo->BtHciInfo;
1979 logicHandle = *((u16 *)&pHciCmd->Data[0]);
1980 Packet_Type = pHciCmd->Data[2];
1982 if (Packet_Type != 0)
1983 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
1985 pBtHciInfo->enFlush_LLH = logicHandle;
1987 if (bthci_DiscardTxPackets(padapter, pBtHciInfo->enFlush_LLH))
1988 bthci_EventFlushOccurred(padapter, pBtHciInfo->enFlush_LLH);
1990 /* should send command status event */
1991 bthci_EventCommandStatus(padapter,
1992 OGF_SET_EVENT_MASK_COMMAND,
1996 if (pBtHciInfo->enFlush_LLH) {
1997 bthci_EventEnhancedFlushComplete(padapter, pBtHciInfo->enFlush_LLH);
1998 pBtHciInfo->enFlush_LLH = 0;
2004 static enum hci_status
2005 bthci_CmdReadLogicalLinkAcceptTimeout(
2006 struct rtw_adapter *padapter,
2007 struct packet_irp_hcicmd_data *pHciCmd
2010 enum hci_status status = HCI_STATUS_SUCCESS;
2011 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2012 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2013 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2014 u8 localBuf[8] = "";
2017 struct packet_irp_hcievent_data *PPacketIrpEvent;
2020 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2022 len += bthci_CommandCompleteHeader(&localBuf[0],
2023 OGF_SET_EVENT_MASK_COMMAND,
2024 HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT,
2027 /* Return parameters starts from here */
2028 pRetPar = &PPacketIrpEvent->Data[len];
2029 pRetPar[0] = status;
2031 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
2032 *pu2Temp = pBtHciInfo->LogicalAcceptTimeout;
2034 PPacketIrpEvent->Length = len;
2036 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2041 static enum hci_status
2042 bthci_CmdWriteLogicalLinkAcceptTimeout(
2043 struct rtw_adapter *padapter,
2044 struct packet_irp_hcicmd_data *pHciCmd
2047 enum hci_status status = HCI_STATUS_SUCCESS;
2048 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2049 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2050 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2051 u8 localBuf[6] = "";
2054 struct packet_irp_hcievent_data *PPacketIrpEvent;
2056 pBtHciInfo->LogicalAcceptTimeout = *((u16 *)pHciCmd->Data);
2058 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2060 len += bthci_CommandCompleteHeader(&localBuf[0],
2061 OGF_SET_EVENT_MASK_COMMAND,
2062 HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT,
2065 /* Return parameters starts from here */
2066 pRetPar = &PPacketIrpEvent->Data[len];
2067 pRetPar[0] = status;
2070 PPacketIrpEvent->Length = len;
2072 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2076 static enum hci_status
2077 bthci_CmdSetEventMask(
2078 struct rtw_adapter *padapter,
2079 struct packet_irp_hcicmd_data *pHciCmd
2082 enum hci_status status = HCI_STATUS_SUCCESS;
2083 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2084 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2085 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2087 u8 localBuf[6] = "";
2090 struct packet_irp_hcievent_data *PPacketIrpEvent;
2092 pu8Temp = (u8 *)&pHciCmd->Data[0];
2093 pBtHciInfo->BTEventMask = *pu8Temp;
2094 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("BTEventMask = 0x%"i64fmt"x\n",
2095 pBtHciInfo->BTEventMask));
2097 /* send command complete event here when all data are received. */
2098 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2100 len += bthci_CommandCompleteHeader(&localBuf[0],
2101 OGF_SET_EVENT_MASK_COMMAND,
2105 /* Return parameters starts from here */
2106 pRetPar = &PPacketIrpEvent->Data[len];
2107 pRetPar[0] = status; /* status */
2109 PPacketIrpEvent->Length = len;
2111 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2117 static enum hci_status
2118 bthci_CmdSetEventMaskPage2(
2119 struct rtw_adapter *padapter,
2120 struct packet_irp_hcicmd_data *pHciCmd
2123 enum hci_status status = HCI_STATUS_SUCCESS;
2124 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2125 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2127 u8 localBuf[6] = "";
2130 struct packet_irp_hcievent_data *PPacketIrpEvent;
2132 pu8Temp = (u8 *)&pHciCmd->Data[0];
2133 pBtHciInfo->BTEventMaskPage2 = *pu8Temp;
2134 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("BTEventMaskPage2 = 0x%"i64fmt"x\n",
2135 pBtHciInfo->BTEventMaskPage2));
2137 /* send command complete event here when all data are received. */
2138 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2140 len += bthci_CommandCompleteHeader(&localBuf[0],
2141 OGF_SET_EVENT_MASK_COMMAND,
2142 HCI_SET_EVENT_MASK_PAGE_2,
2145 /* Return parameters starts from here */
2146 pRetPar = &PPacketIrpEvent->Data[len];
2147 pRetPar[0] = status; /* status */
2149 PPacketIrpEvent->Length = len;
2151 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2156 static enum hci_status
2157 bthci_CmdReadLocationData(
2158 struct rtw_adapter *padapter,
2159 struct packet_irp_hcicmd_data *pHciCmd
2162 enum hci_status status = HCI_STATUS_SUCCESS;
2163 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2164 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2165 u8 localBuf[12] = "";
2168 struct packet_irp_hcievent_data *PPacketIrpEvent;
2171 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2173 len += bthci_CommandCompleteHeader(&localBuf[0],
2174 OGF_SET_EVENT_MASK_COMMAND,
2175 HCI_READ_LOCATION_DATA,
2177 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2178 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2179 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2180 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2182 /* Return parameters starts from here */
2183 pRetPar = &PPacketIrpEvent->Data[len];
2184 pRetPar[0] = status;
2186 pRetPar[1] = pBtHciInfo->LocationDomainAware; /* 0x0; Location_Domain_Aware */
2187 pu2Temp = (u16 *)&pRetPar[2]; /* Location_Domain */
2188 *pu2Temp = pBtHciInfo->LocationDomain; /* 0x5858; */
2189 pRetPar[4] = pBtHciInfo->LocationDomainOptions; /* 0x58; Location_Domain_Options */
2190 pRetPar[5] = pBtHciInfo->LocationOptions; /* 0x0; Location_Options */
2192 PPacketIrpEvent->Length = len;
2194 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2198 static enum hci_status
2199 bthci_CmdWriteLocationData(
2200 struct rtw_adapter *padapter,
2201 struct packet_irp_hcicmd_data *pHciCmd
2204 enum hci_status status = HCI_STATUS_SUCCESS;
2205 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2206 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2208 u8 localBuf[6] = "";
2211 struct packet_irp_hcievent_data *PPacketIrpEvent;
2213 pBtHciInfo->LocationDomainAware = pHciCmd->Data[0];
2214 pu2Temp = (u16 *)&pHciCmd->Data[1];
2215 pBtHciInfo->LocationDomain = *pu2Temp;
2216 pBtHciInfo->LocationDomainOptions = pHciCmd->Data[3];
2217 pBtHciInfo->LocationOptions = pHciCmd->Data[4];
2218 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2219 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2220 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2221 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2223 /* send command complete event here when all data are received. */
2224 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2226 len += bthci_CommandCompleteHeader(&localBuf[0],
2227 OGF_SET_EVENT_MASK_COMMAND,
2228 HCI_WRITE_LOCATION_DATA,
2231 /* Return parameters starts from here */
2232 pRetPar = &PPacketIrpEvent->Data[len];
2233 pRetPar[0] = status; /* status */
2235 PPacketIrpEvent->Length = len;
2237 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2242 static enum hci_status
2243 bthci_CmdReadFlowControlMode(
2244 struct rtw_adapter *padapter,
2245 struct packet_irp_hcicmd_data *pHciCmd
2248 enum hci_status status = HCI_STATUS_SUCCESS;
2249 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2250 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2251 u8 localBuf[7] = "";
2254 struct packet_irp_hcievent_data *PPacketIrpEvent;
2256 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2258 len += bthci_CommandCompleteHeader(&localBuf[0],
2259 OGF_SET_EVENT_MASK_COMMAND,
2260 HCI_READ_FLOW_CONTROL_MODE,
2263 /* Return parameters starts from here */
2264 pRetPar = &PPacketIrpEvent->Data[len];
2265 pRetPar[0] = status;
2266 pRetPar[1] = pBtHciInfo->FlowControlMode; /* Flow Control Mode */
2268 PPacketIrpEvent->Length = len;
2270 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2274 static enum hci_status
2275 bthci_CmdWriteFlowControlMode(
2276 struct rtw_adapter *padapter,
2277 struct packet_irp_hcicmd_data *pHciCmd
2280 enum hci_status status = HCI_STATUS_SUCCESS;
2281 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2282 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2283 u8 localBuf[6] = "";
2286 struct packet_irp_hcievent_data *PPacketIrpEvent;
2288 pBtHciInfo->FlowControlMode = pHciCmd->Data[0];
2290 /* send command complete event here when all data are received. */
2291 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2293 len += bthci_CommandCompleteHeader(&localBuf[0],
2294 OGF_SET_EVENT_MASK_COMMAND,
2295 HCI_WRITE_FLOW_CONTROL_MODE,
2298 /* Return parameters starts from here */
2299 pRetPar = &PPacketIrpEvent->Data[len];
2300 pRetPar[0] = status; /* status */
2302 PPacketIrpEvent->Length = len;
2304 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2309 static enum hci_status
2310 bthci_CmdReadBestEffortFlushTimeout(
2311 struct rtw_adapter *padapter,
2312 struct packet_irp_hcicmd_data *pHciCmd
2315 enum hci_status status = HCI_STATUS_SUCCESS;
2316 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2317 u16 i, j, logicHandle;
2318 u32 BestEffortFlushTimeout = 0xffffffff;
2321 logicHandle = *((u16 *)pHciCmd->Data);
2322 /* find an matched logical link index and copy the data */
2323 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2324 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2325 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2326 BestEffortFlushTimeout = pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout;
2334 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2337 u8 localBuf[10] = "";
2340 struct packet_irp_hcievent_data *PPacketIrpEvent;
2343 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2345 len += bthci_CommandCompleteHeader(&localBuf[0],
2346 OGF_SET_EVENT_MASK_COMMAND,
2347 HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT,
2350 /* Return parameters starts from here */
2351 pRetPar = &PPacketIrpEvent->Data[len];
2352 pRetPar[0] = status;
2353 pu4Temp = (u32 *)&pRetPar[1]; /* Best_Effort_Flush_Timeout */
2354 *pu4Temp = BestEffortFlushTimeout;
2356 PPacketIrpEvent->Length = len;
2358 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2363 static enum hci_status
2364 bthci_CmdWriteBestEffortFlushTimeout(
2365 struct rtw_adapter *padapter,
2366 struct packet_irp_hcicmd_data *pHciCmd
2369 enum hci_status status = HCI_STATUS_SUCCESS;
2370 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2371 u16 i, j, logicHandle;
2372 u32 BestEffortFlushTimeout = 0xffffffff;
2375 logicHandle = *((u16 *)pHciCmd->Data);
2376 BestEffortFlushTimeout = *((u32 *)(pHciCmd->Data+1));
2378 /* find an matched logical link index and copy the data */
2379 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2380 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2381 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2382 pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout = BestEffortFlushTimeout;
2390 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2393 u8 localBuf[6] = "";
2396 struct packet_irp_hcievent_data *PPacketIrpEvent;
2398 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2400 len += bthci_CommandCompleteHeader(&localBuf[0],
2401 OGF_SET_EVENT_MASK_COMMAND,
2402 HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT,
2405 /* Return parameters starts from here */
2406 pRetPar = &PPacketIrpEvent->Data[len];
2407 pRetPar[0] = status;
2409 PPacketIrpEvent->Length = len;
2411 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2416 static enum hci_status
2417 bthci_CmdShortRangeMode(
2418 struct rtw_adapter *padapter,
2419 struct packet_irp_hcicmd_data *pHciCmd
2422 enum hci_status status = HCI_STATUS_SUCCESS;
2423 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2424 u8 PhyLinkHandle, EntryNum, ShortRangeMode;
2426 PhyLinkHandle = pHciCmd->Data[0];
2427 ShortRangeMode = pHciCmd->Data[1];
2428 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x, Short_Range_Mode = 0x%x\n", PhyLinkHandle, ShortRangeMode));
2430 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2431 if (EntryNum != 0xff) {
2432 pBTInfo->BtAsocEntry[EntryNum].ShortRangeMode = ShortRangeMode;
2434 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PhyLinkHandle));
2435 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2438 bthci_EventCommandStatus(padapter,
2439 OGF_SET_EVENT_MASK_COMMAND,
2440 HCI_SHORT_RANGE_MODE,
2443 bthci_EventShortRangeModeChangeComplete(padapter, status, ShortRangeMode, EntryNum);
2448 static enum hci_status bthci_CmdReadLocalSupportedCommands(struct rtw_adapter *padapter)
2450 enum hci_status status = HCI_STATUS_SUCCESS;
2451 u8 localBuf[TmpLocalBufSize] = "";
2452 u8 *pRetPar, *pSupportedCmds;
2454 struct packet_irp_hcievent_data *PPacketIrpEvent;
2456 /* send command complete event here when all data are received. */
2457 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2458 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2460 len += bthci_CommandCompleteHeader(&localBuf[0],
2461 OGF_INFORMATIONAL_PARAMETERS,
2462 HCI_READ_LOCAL_SUPPORTED_COMMANDS,
2465 /* Return parameters starts from here */
2466 pRetPar = &PPacketIrpEvent->Data[len];
2467 pRetPar[0] = status; /* status */
2469 pSupportedCmds = &pRetPar[1];
2470 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[5]= 0xc0\nBit [6]= Set Event Mask, [7]= Reset\n"));
2471 pSupportedCmds[5] = 0xc0;
2472 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[6]= 0x01\nBit [0]= Set Event Filter\n"));
2473 pSupportedCmds[6] = 0x01;
2474 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[7]= 0x0c\nBit [2]= Read Connection Accept Timeout, [3]= Write Connection Accept Timeout\n"));
2475 pSupportedCmds[7] = 0x0c;
2476 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[10]= 0x80\nBit [7]= Host Number Of Completed Packets\n"));
2477 pSupportedCmds[10] = 0x80;
2478 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[11]= 0x03\nBit [0]= Read Link Supervision Timeout, [1]= Write Link Supervision Timeout\n"));
2479 pSupportedCmds[11] = 0x03;
2480 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[14]= 0xa8\nBit [3]= Read Local Version Information, [5]= Read Local Supported Features, [7]= Read Buffer Size\n"));
2481 pSupportedCmds[14] = 0xa8;
2482 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[15]= 0x1c\nBit [2]= Read Failed Contact Count, [3]= Reset Failed Contact Count, [4]= Get Link Quality\n"));
2483 pSupportedCmds[15] = 0x1c;
2484 /* pSupportedCmds[16] = 0x04; */
2485 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[19]= 0x40\nBit [6]= Enhanced Flush\n"));
2486 pSupportedCmds[19] = 0x40;
2487 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[21]= 0xff\nBit [0]= Create Physical Link, [1]= Accept Physical Link, [2]= Disconnect Physical Link, [3]= Create Logical Link\n"));
2488 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), (" [4]= Accept Logical Link, [5]= Disconnect Logical Link, [6]= Logical Link Cancel, [7]= Flow Spec Modify\n"));
2489 pSupportedCmds[21] = 0xff;
2490 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[22]= 0xff\nBit [0]= Read Logical Link Accept Timeout, [1]= Write Logical Link Accept Timeout, [2]= Set Event Mask Page 2, [3]= Read Location Data\n"));
2491 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), (" [4]= Write Location Data, [5]= Read Local AMP Info, [6]= Read Local AMP_ASSOC, [7]= Write Remote AMP_ASSOC\n"));
2492 pSupportedCmds[22] = 0xff;
2493 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[23]= 0x07\nBit [0]= Read Flow Control Mode, [1]= Write Flow Control Mode, [2]= Read Data Block Size\n"));
2494 pSupportedCmds[23] = 0x07;
2495 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[24]= 0x1c\nBit [2]= Read Best Effort Flush Timeout, [3]= Write Best Effort Flush Timeout, [4]= Short Range Mode\n"));
2496 pSupportedCmds[24] = 0x1c;
2498 PPacketIrpEvent->Length = len;
2500 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2505 static enum hci_status bthci_CmdReadLocalSupportedFeatures(struct rtw_adapter *padapter)
2507 enum hci_status status = HCI_STATUS_SUCCESS;
2508 u8 localBuf[TmpLocalBufSize] = "";
2511 struct packet_irp_hcievent_data *PPacketIrpEvent;
2513 /* send command complete event here when all data are received. */
2514 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2515 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2517 len += bthci_CommandCompleteHeader(&localBuf[0],
2518 OGF_INFORMATIONAL_PARAMETERS,
2519 HCI_READ_LOCAL_SUPPORTED_FEATURES,
2522 /* Return parameters starts from here */
2523 pRetPar = &PPacketIrpEvent->Data[len];
2524 pRetPar[0] = status; /* status */
2526 PPacketIrpEvent->Length = len;
2528 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2532 static enum hci_status bthci_CmdReadLocalAMPAssoc(struct rtw_adapter *padapter,
2533 struct packet_irp_hcicmd_data *pHciCmd)
2535 enum hci_status status = HCI_STATUS_SUCCESS;
2536 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2537 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
2538 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2539 u8 PhyLinkHandle, EntryNum;
2541 pBtDbg->dbgHciInfo.hciCmdCntReadLocalAmpAssoc++;
2542 PhyLinkHandle = *((u8 *)pHciCmd->Data);
2543 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2545 if ((EntryNum == 0xff) && PhyLinkHandle != 0) {
2546 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x\n",
2547 EntryNum, PhyLinkHandle));
2548 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2549 } else if (pBtMgnt->bPhyLinkInProgressStartLL) {
2550 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2551 pBtMgnt->bPhyLinkInProgressStartLL = false;
2553 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
2554 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
2555 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen = *((u16 *)((u8 *)pHciCmd->Data+3));
2556 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ReadLocalAMPAssoc, LenSoFar =%d, MaxRemoteASSOCLen =%d\n",
2557 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar,
2558 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen));
2561 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x, LengthSoFar = %x \n",
2562 EntryNum, PhyLinkHandle, pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar));
2564 /* send command complete event here when all data are received. */
2566 struct packet_irp_hcievent_data *PPacketIrpEvent;
2568 /* PVOID buffer = padapter->IrpHCILocalbuf.Ptr; */
2569 u8 localBuf[TmpLocalBufSize] = "";
2572 u16 typeLen = 0, remainLen = 0, ret_index = 0;
2575 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2576 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2577 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2579 totalLen += bthci_CommandCompleteHeader(&localBuf[0],
2580 OGF_STATUS_PARAMETERS,
2581 HCI_READ_LOCAL_AMP_ASSOC,
2583 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2584 /* Return parameters starts from here */
2585 pRetPar = &PPacketIrpEvent->Data[totalLen];
2586 pRetPar[0] = status; /* status */
2587 pRetPar[1] = *((u8 *)pHciCmd->Data);
2588 pRemainLen = (u16 *)&pRetPar[2]; /* AMP_ASSOC_Remaining_Length */
2589 totalLen += 4; /* 0]~[3] */
2592 typeLen = bthci_AssocMACAddr(padapter, &pRetPar[ret_index]);
2593 totalLen += typeLen;
2594 remainLen += typeLen;
2595 ret_index += typeLen;
2596 typeLen = bthci_AssocPreferredChannelList(padapter, &pRetPar[ret_index], EntryNum);
2597 totalLen += typeLen;
2598 remainLen += typeLen;
2599 ret_index += typeLen;
2600 typeLen = bthci_PALCapabilities(padapter, &pRetPar[ret_index]);
2601 totalLen += typeLen;
2602 remainLen += typeLen;
2603 ret_index += typeLen;
2604 typeLen = bthci_AssocPALVer(padapter, &pRetPar[ret_index]);
2605 totalLen += typeLen;
2606 remainLen += typeLen;
2607 PPacketIrpEvent->Length = (u8)totalLen;
2608 *pRemainLen = remainLen; /* AMP_ASSOC_Remaining_Length */
2609 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2610 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("AMP_ASSOC_fragment : \n"), PPacketIrpEvent->Data, totalLen);
2612 bthci_IndicateEvent(padapter, PPacketIrpEvent, totalLen+2);
2618 static enum hci_status bthci_CmdReadFailedContactCounter(struct rtw_adapter *padapter,
2619 struct packet_irp_hcicmd_data *pHciCmd)
2622 enum hci_status status = HCI_STATUS_SUCCESS;
2623 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2624 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2625 u8 localBuf[TmpLocalBufSize] = "";
2628 struct packet_irp_hcievent_data *PPacketIrpEvent;
2631 handle = *((u16 *)pHciCmd->Data);
2632 /* send command complete event here when all data are received. */
2633 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2634 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2636 len += bthci_CommandCompleteHeader(&localBuf[0],
2637 OGF_STATUS_PARAMETERS,
2638 HCI_READ_FAILED_CONTACT_COUNTER,
2641 /* Return parameters starts from here */
2642 pRetPar = &PPacketIrpEvent->Data[len];
2643 pRetPar[0] = status; /* status */
2644 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2645 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2646 pRetPar[3] = TWOBYTE_LOWBYTE(pBtHciInfo->FailContactCount);
2647 pRetPar[4] = TWOBYTE_HIGHTBYTE(pBtHciInfo->FailContactCount);
2649 PPacketIrpEvent->Length = len;
2651 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2656 static enum hci_status
2657 bthci_CmdResetFailedContactCounter(
2658 struct rtw_adapter *padapter,
2659 struct packet_irp_hcicmd_data *pHciCmd
2662 enum hci_status status = HCI_STATUS_SUCCESS;
2663 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2664 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2665 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2667 u8 localBuf[TmpLocalBufSize] = "";
2670 struct packet_irp_hcievent_data *PPacketIrpEvent;
2672 handle = *((u16 *)pHciCmd->Data);
2673 pBtHciInfo->FailContactCount = 0;
2675 /* send command complete event here when all data are received. */
2676 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2677 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2678 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2680 len += bthci_CommandCompleteHeader(&localBuf[0],
2681 OGF_STATUS_PARAMETERS,
2682 HCI_RESET_FAILED_CONTACT_COUNTER,
2685 /* Return parameters starts from here */
2686 pRetPar = &PPacketIrpEvent->Data[len];
2687 pRetPar[0] = status; /* status */
2688 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2689 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2691 PPacketIrpEvent->Length = len;
2693 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2698 /* BT 3.0+HS [Vol 2] 7.4.1 */
2700 static enum hci_status
2701 bthci_CmdReadLocalVersionInformation(
2702 struct rtw_adapter *padapter
2705 enum hci_status status = HCI_STATUS_SUCCESS;
2706 /* send command complete event here when all data are received. */
2707 u8 localBuf[TmpLocalBufSize] = "";
2710 struct packet_irp_hcievent_data *PPacketIrpEvent;
2713 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2714 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2716 len += bthci_CommandCompleteHeader(&localBuf[0],
2717 OGF_INFORMATIONAL_PARAMETERS,
2718 HCI_READ_LOCAL_VERSION_INFORMATION,
2721 /* Return parameters starts from here */
2722 pRetPar = &PPacketIrpEvent->Data[len];
2723 pRetPar[0] = status; /* status */
2724 pRetPar[1] = 0x05; /* HCI_Version */
2725 pu2Temp = (u16 *)&pRetPar[2]; /* HCI_Revision */
2727 pRetPar[4] = 0x05; /* LMP/PAL_Version */
2728 pu2Temp = (u16 *)&pRetPar[5]; /* Manufacturer_Name */
2730 pu2Temp = (u16 *)&pRetPar[7]; /* LMP/PAL_Subversion */
2733 PPacketIrpEvent->Length = len;
2735 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LOCAL_VERSION_INFORMATION\n"));
2736 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Status %x\n", status));
2737 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Version = 0x05\n"));
2738 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Revision = 0x0001\n"));
2739 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Version = 0x05\n"));
2740 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Manufacturer_Name = 0x0001\n"));
2741 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Subversion = 0x0001\n"));
2743 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2749 static enum hci_status bthci_CmdReadDataBlockSize(struct rtw_adapter *padapter)
2751 enum hci_status status = HCI_STATUS_SUCCESS;
2752 u8 localBuf[TmpLocalBufSize] = "";
2755 struct packet_irp_hcievent_data *PPacketIrpEvent;
2758 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2759 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2761 len += bthci_CommandCompleteHeader(&localBuf[0],
2762 OGF_INFORMATIONAL_PARAMETERS,
2763 HCI_READ_DATA_BLOCK_SIZE,
2766 /* Return parameters starts from here */
2767 pRetPar = &PPacketIrpEvent->Data[len];
2768 pRetPar[0] = HCI_STATUS_SUCCESS; /* status */
2769 pu2Temp = (u16 *)&pRetPar[1]; /* Max_ACL_Data_Packet_Length */
2770 *pu2Temp = Max80211PALPDUSize;
2772 pu2Temp = (u16 *)&pRetPar[3]; /* Data_Block_Length */
2773 *pu2Temp = Max80211PALPDUSize;
2774 pu2Temp = (u16 *)&pRetPar[5]; /* Total_Num_Data_Blocks */
2775 *pu2Temp = BTTotalDataBlockNum;
2777 PPacketIrpEvent->Length = len;
2779 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2785 static enum hci_status bthci_CmdReadBufferSize(struct rtw_adapter *padapter)
2787 enum hci_status status = HCI_STATUS_SUCCESS;
2788 u8 localBuf[TmpLocalBufSize] = "";
2791 struct packet_irp_hcievent_data *PPacketIrpEvent;
2794 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2795 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2796 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2798 len += bthci_CommandCompleteHeader(&localBuf[0],
2799 OGF_INFORMATIONAL_PARAMETERS,
2800 HCI_READ_BUFFER_SIZE,
2802 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Synchronous_Data_Packet_Length = 0x%x\n", BTSynDataPacketLength));
2803 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_ACL_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2804 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_Synchronous_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2805 /* Return parameters starts from here */
2806 pRetPar = &PPacketIrpEvent->Data[len];
2807 pRetPar[0] = status; /* status */
2808 pu2Temp = (u16 *)&pRetPar[1]; /* HC_ACL_Data_Packet_Length */
2809 *pu2Temp = Max80211PALPDUSize;
2811 pRetPar[3] = BTSynDataPacketLength; /* HC_Synchronous_Data_Packet_Length */
2812 pu2Temp = (u16 *)&pRetPar[4]; /* HC_Total_Num_ACL_Data_Packets */
2813 *pu2Temp = BTTotalDataBlockNum;
2814 pu2Temp = (u16 *)&pRetPar[6]; /* HC_Total_Num_Synchronous_Data_Packets */
2815 *pu2Temp = BTTotalDataBlockNum;
2817 PPacketIrpEvent->Length = len;
2819 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2824 static enum hci_status bthci_CmdReadLocalAMPInfo(struct rtw_adapter *padapter)
2826 enum hci_status status = HCI_STATUS_SUCCESS;
2827 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
2828 u8 localBuf[TmpLocalBufSize] = "";
2831 struct packet_irp_hcievent_data *PPacketIrpEvent;
2834 u32 TotalBandwidth = BTTOTALBANDWIDTH, MaxBandGUBandwidth = BTMAXBANDGUBANDWIDTH;
2835 u8 ControlType = 0x01, AmpStatus = 0x01;
2836 u32 MaxFlushTimeout = 10000, BestEffortFlushTimeout = 5000;
2837 u16 MaxPDUSize = Max80211PALPDUSize, PalCap = 0x1, AmpAssocLen = Max80211AMPASSOCLen, MinLatency = 20;
2839 if ((ppwrctrl->rfoff_reason & RF_CHANGE_BY_HW) ||
2840 (ppwrctrl->rfoff_reason & RF_CHANGE_BY_SW)) {
2841 AmpStatus = AMP_STATUS_NO_CAPACITY_FOR_BT;
2844 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2845 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2846 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2848 len += bthci_CommandCompleteHeader(&localBuf[0],
2849 OGF_STATUS_PARAMETERS,
2850 HCI_READ_LOCAL_AMP_INFO,
2853 /* Return parameters starts from here */
2854 pRetPar = &PPacketIrpEvent->Data[len];
2855 pRetPar[0] = status; /* status */
2856 pRetPar[1] = AmpStatus; /* AMP_Status */
2857 pu4Temp = (u32 *)&pRetPar[2]; /* Total_Bandwidth */
2858 *pu4Temp = TotalBandwidth; /* 0x19bfcc00;0x7530; */
2859 pu4Temp = (u32 *)&pRetPar[6]; /* Max_Guaranteed_Bandwidth */
2860 *pu4Temp = MaxBandGUBandwidth; /* 0x19bfcc00;0x4e20; */
2861 pu4Temp = (u32 *)&pRetPar[10]; /* Min_Latency */
2862 *pu4Temp = MinLatency; /* 150; */
2863 pu4Temp = (u32 *)&pRetPar[14]; /* Max_PDU_Size */
2864 *pu4Temp = MaxPDUSize;
2865 pRetPar[18] = ControlType; /* Controller_Type */
2866 pu2Temp = (u16 *)&pRetPar[19]; /* PAL_Capabilities */
2868 pu2Temp = (u16 *)&pRetPar[21]; /* AMP_ASSOC_Length */
2869 *pu2Temp = AmpAssocLen;
2870 pu4Temp = (u32 *)&pRetPar[23]; /* Max_Flush_Timeout */
2871 *pu4Temp = MaxFlushTimeout;
2872 pu4Temp = (u32 *)&pRetPar[27]; /* Best_Effort_Flush_Timeout */
2873 *pu4Temp = BestEffortFlushTimeout;
2875 PPacketIrpEvent->Length = len;
2876 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("AmpStatus = 0x%x\n",
2878 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TotalBandwidth = 0x%x, MaxBandGUBandwidth = 0x%x, MinLatency = 0x%x, \n MaxPDUSize = 0x%x, ControlType = 0x%x\n",
2879 TotalBandwidth, MaxBandGUBandwidth, MinLatency, MaxPDUSize, ControlType));
2880 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PalCap = 0x%x, AmpAssocLen = 0x%x, MaxFlushTimeout = 0x%x, BestEffortFlushTimeout = 0x%x\n",
2881 PalCap, AmpAssocLen, MaxFlushTimeout, BestEffortFlushTimeout));
2882 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2886 static enum hci_status
2887 bthci_CmdCreatePhysicalLink(
2888 struct rtw_adapter *padapter,
2889 struct packet_irp_hcicmd_data *pHciCmd
2892 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2893 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2895 pBtDbg->dbgHciInfo.hciCmdCntCreatePhyLink++;
2897 return bthci_BuildPhysicalLink(padapter,
2898 pHciCmd, HCI_CREATE_PHYSICAL_LINK);
2901 static enum hci_status
2902 bthci_CmdReadLinkQuality(
2903 struct rtw_adapter *padapter,
2904 struct packet_irp_hcicmd_data *pHciCmd
2907 enum hci_status status = HCI_STATUS_SUCCESS;
2908 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2910 u8 EntryNum, LinkQuality = 0x55;
2912 PLH = *((u16 *)&pHciCmd->Data[0]);
2913 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x\n", PLH));
2915 EntryNum = bthci_GetCurrentEntryNum(padapter, (u8)PLH);
2916 if (EntryNum == 0xff) {
2917 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PLH));
2918 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2922 u8 localBuf[11] = "";
2925 struct packet_irp_hcievent_data *PPacketIrpEvent;
2927 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2929 len += bthci_CommandCompleteHeader(&localBuf[0],
2930 OGF_STATUS_PARAMETERS,
2931 HCI_READ_LINK_QUALITY,
2934 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" PLH = 0x%x\n Link Quality = 0x%x\n", PLH, LinkQuality));
2936 /* Return parameters starts from here */
2937 pRetPar = &PPacketIrpEvent->Data[len];
2938 pRetPar[0] = status; /* status */
2939 *((u16 *)&pRetPar[1]) = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle; /* Handle */
2940 pRetPar[3] = 0x55; /* Link Quailty */
2942 PPacketIrpEvent->Length = len;
2944 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2950 static enum hci_status
2951 bthci_CmdCreateLogicalLink(
2952 struct rtw_adapter *padapter,
2953 struct packet_irp_hcicmd_data *pHciCmd
2956 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2957 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2959 pBtDbg->dbgHciInfo.hciCmdCntCreateLogLink++;
2961 bthci_BuildLogicalLink(padapter, pHciCmd,
2962 HCI_CREATE_LOGICAL_LINK);
2964 return HCI_STATUS_SUCCESS;
2967 static enum hci_status
2968 bthci_CmdAcceptLogicalLink(
2969 struct rtw_adapter *padapter,
2970 struct packet_irp_hcicmd_data *pHciCmd
2973 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2974 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2976 pBtDbg->dbgHciInfo.hciCmdCntAcceptLogLink++;
2978 bthci_BuildLogicalLink(padapter, pHciCmd,
2979 HCI_ACCEPT_LOGICAL_LINK);
2981 return HCI_STATUS_SUCCESS;
2984 static enum hci_status
2985 bthci_CmdDisconnectLogicalLink(
2986 struct rtw_adapter *padapter,
2987 struct packet_irp_hcicmd_data *pHciCmd
2990 enum hci_status status = HCI_STATUS_SUCCESS;
2991 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2992 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2993 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
2994 struct bt_dgb *pBtDbg = &pBTinfo->BtDbg;
2996 u8 i, j, find = 0, LogLinkCount = 0;
2998 pBtDbg->dbgHciInfo.hciCmdCntDisconnectLogLink++;
3000 logicHandle = *((u16 *)pHciCmd->Data);
3001 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle = 0x%x\n", logicHandle));
3003 /* find an created logical link index and clear the data */
3004 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3005 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3006 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3007 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle is matched 0x%x\n", logicHandle));
3008 bthci_ResetFlowSpec(padapter, j, i);
3010 pBtMgnt->DisconnectEntryNum = j;
3017 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3020 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3021 if (pBTinfo->BtAsocEntry[pBtMgnt->DisconnectEntryNum].LogLinkCmdData[i].BtLogLinkhandle != 0)
3025 /* When we receive Create logical link command, we should send command status event first. */
3026 bthci_EventCommandStatus(padapter,
3027 LINK_CONTROL_COMMANDS,
3028 HCI_DISCONNECT_LOGICAL_LINK,
3031 /* When we determines the logical link is established, we should send command complete event. */
3033 if (status == HCI_STATUS_SUCCESS) {
3034 bthci_EventDisconnectLogicalLinkComplete(padapter, status,
3035 logicHandle, HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST);
3038 if (LogLinkCount == 0)
3039 mod_timer(&pBTinfo->BTDisconnectPhyLinkTimer,
3040 jiffies + msecs_to_jiffies(100));
3045 static enum hci_status
3046 bthci_CmdLogicalLinkCancel(struct rtw_adapter *padapter,
3047 struct packet_irp_hcicmd_data *pHciCmd)
3049 enum hci_status status = HCI_STATUS_SUCCESS;
3050 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3051 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3052 u8 CurrentEntryNum, CurrentLogEntryNum;
3054 u8 physicalLinkHandle, TxFlowSpecID, i;
3055 u16 CurrentLogicalHandle;
3057 physicalLinkHandle = *((u8 *)pHciCmd->Data);
3058 TxFlowSpecID = *(((u8 *)pHciCmd->Data)+1);
3060 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, physicalLinkHandle = 0x%x, TxFlowSpecID = 0x%x\n",
3061 physicalLinkHandle, TxFlowSpecID));
3063 CurrentEntryNum = pBtMgnt->CurrentConnectEntryNum;
3064 CurrentLogicalHandle = pBtMgnt->BtCurrentLogLinkhandle;
3066 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("CurrentEntryNum = 0x%x, CurrentLogicalHandle = 0x%x\n",
3067 CurrentEntryNum, CurrentLogicalHandle));
3069 CurrentLogEntryNum = 0xff;
3070 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3071 if ((CurrentLogicalHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtLogLinkhandle) &&
3072 (physicalLinkHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtPhyLinkhandle)) {
3073 CurrentLogEntryNum = i;
3078 if (CurrentLogEntryNum == 0xff) {
3079 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, CurrentLogEntryNum == 0xff !!!!\n"));
3080 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3083 if (pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCompleteEventIsSet) {
3084 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, LLCompleteEventIsSet!!!!\n"));
3085 status = HCI_STATUS_ACL_CONNECT_EXISTS;
3090 u8 localBuf[8] = "";
3093 struct packet_irp_hcievent_data *PPacketIrpEvent;
3095 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3097 len += bthci_CommandCompleteHeader(&localBuf[0],
3098 LINK_CONTROL_COMMANDS,
3099 HCI_LOGICAL_LINK_CANCEL,
3102 /* Return parameters starts from here */
3103 pRetPar = &PPacketIrpEvent->Data[len];
3104 pRetPar[0] = status; /* status */
3105 pRetPar[1] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtPhyLinkhandle;
3106 pRetPar[2] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtTxFlowSpecID;
3108 PPacketIrpEvent->Length = len;
3110 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3113 pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCancelCMDIsSetandComplete = true;
3118 static enum hci_status
3119 bthci_CmdFlowSpecModify(struct rtw_adapter *padapter,
3120 struct packet_irp_hcicmd_data *pHciCmd)
3122 enum hci_status status = HCI_STATUS_SUCCESS;
3123 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3124 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3128 logicHandle = *((u16 *)pHciCmd->Data);
3129 /* find an matched logical link index and copy the data */
3130 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3131 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3132 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3133 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec,
3134 &pHciCmd->Data[2], sizeof(struct hci_flow_spec));
3135 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Rx_Flow_Spec,
3136 &pHciCmd->Data[18], sizeof(struct hci_flow_spec));
3138 bthci_CheckLogLinkBehavior(padapter, pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec);
3144 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("FlowSpecModify, LLH = 0x%x, \n", logicHandle));
3146 /* When we receive Flow Spec Modify command, we should send command status event first. */
3147 bthci_EventCommandStatus(padapter,
3148 LINK_CONTROL_COMMANDS,
3149 HCI_FLOW_SPEC_MODIFY,
3150 HCI_STATUS_SUCCESS);
3153 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3155 bthci_EventSendFlowSpecModifyComplete(padapter, status, logicHandle);
3160 static enum hci_status
3161 bthci_CmdAcceptPhysicalLink(struct rtw_adapter *padapter,
3162 struct packet_irp_hcicmd_data *pHciCmd)
3164 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3165 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3167 pBtDbg->dbgHciInfo.hciCmdCntAcceptPhyLink++;
3169 return bthci_BuildPhysicalLink(padapter,
3170 pHciCmd, HCI_ACCEPT_PHYSICAL_LINK);
3173 static enum hci_status
3174 bthci_CmdDisconnectPhysicalLink(struct rtw_adapter *padapter,
3175 struct packet_irp_hcicmd_data *pHciCmd)
3177 enum hci_status status = HCI_STATUS_SUCCESS;
3178 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3179 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3180 u8 PLH, CurrentEntryNum, PhysLinkDisconnectReason;
3182 pBtDbg->dbgHciInfo.hciCmdCntDisconnectPhyLink++;
3184 PLH = *((u8 *)pHciCmd->Data);
3185 PhysLinkDisconnectReason = *((u8 *)pHciCmd->Data+1);
3186 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK PhyHandle = 0x%x, Reason = 0x%x\n",
3187 PLH, PhysLinkDisconnectReason));
3189 CurrentEntryNum = bthci_GetCurrentEntryNum(padapter, PLH);
3191 if (CurrentEntryNum == 0xff) {
3192 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
3193 ("DisconnectPhysicalLink, No such Handle in the Entry\n"));
3194 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3196 pBTInfo->BtAsocEntry[CurrentEntryNum].PhyLinkDisconnectReason =
3197 (enum hci_status)PhysLinkDisconnectReason;
3199 /* Send HCI Command status event to AMP. */
3200 bthci_EventCommandStatus(padapter, LINK_CONTROL_COMMANDS,
3201 HCI_DISCONNECT_PHYSICAL_LINK, status);
3203 if (status != HCI_STATUS_SUCCESS)
3206 /* The macros below require { and } in the if statement */
3207 if (pBTInfo->BtAsocEntry[CurrentEntryNum].BtCurrentState == HCI_STATE_DISCONNECTED) {
3208 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3210 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3215 static enum hci_status
3216 bthci_CmdSetACLLinkDataFlowMode(struct rtw_adapter *padapter,
3217 struct packet_irp_hcicmd_data *pHciCmd)
3219 enum hci_status status = HCI_STATUS_SUCCESS;
3220 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3221 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3222 u8 localBuf[8] = "";
3225 struct packet_irp_hcievent_data *PPacketIrpEvent;
3228 pBtMgnt->ExtConfig.CurrentConnectHandle = *((u16 *)pHciCmd->Data);
3229 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = *((u8 *)pHciCmd->Data)+2;
3230 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = *((u8 *)pHciCmd->Data)+3;
3231 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Connection Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic mode = 0x%x",
3232 pBtMgnt->ExtConfig.CurrentConnectHandle,
3233 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode,
3234 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode));
3237 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3239 len += bthci_CommandCompleteHeader(&localBuf[0],
3241 HCI_SET_ACL_LINK_DATA_FLOW_MODE,
3244 /* Return parameters starts from here */
3245 pRetPar = &PPacketIrpEvent->Data[len];
3246 pRetPar[0] = status; /* status */
3248 pu2Temp = (u16 *)&pRetPar[1];
3249 *pu2Temp = pBtMgnt->ExtConfig.CurrentConnectHandle;
3251 PPacketIrpEvent->Length = len;
3253 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3257 static enum hci_status
3258 bthci_CmdSetACLLinkStatus(struct rtw_adapter *padapter,
3259 struct packet_irp_hcicmd_data *pHciCmd)
3261 enum hci_status status = HCI_STATUS_SUCCESS;
3262 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3263 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3264 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3268 pBtDbg->dbgHciInfo.hciCmdCntSetAclLinkStatus++;
3269 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "SetACLLinkStatus, Hex Data :\n",
3270 &pHciCmd->Data[0], pHciCmd->Length);
3272 /* Only Core Stack v251 and later version support this command. */
3273 pBtMgnt->bSupportProfile = true;
3275 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3276 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3278 pTriple = &pHciCmd->Data[1];
3279 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3280 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3281 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = pTriple[2];
3282 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = pTriple[3];
3283 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3284 ("Connection_Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic Mode = 0x%x\n",
3285 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3286 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode,
3287 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode));
3292 u8 localBuf[6] = "";
3295 struct packet_irp_hcievent_data *PPacketIrpEvent;
3297 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3299 len += bthci_CommandCompleteHeader(&localBuf[0],
3301 HCI_SET_ACL_LINK_STATUS,
3304 /* Return parameters starts from here */
3305 pRetPar = &PPacketIrpEvent->Data[len];
3306 pRetPar[0] = status; /* status */
3309 PPacketIrpEvent->Length = len;
3311 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3317 static enum hci_status
3318 bthci_CmdSetSCOLinkStatus(
3319 struct rtw_adapter *padapter,
3320 struct packet_irp_hcicmd_data *pHciCmd
3323 enum hci_status status = HCI_STATUS_SUCCESS;
3324 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3325 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3326 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3328 pBtDbg->dbgHciInfo.hciCmdCntSetScoLinkStatus++;
3329 pBtMgnt->ExtConfig.NumberOfSCO = *((u8 *)pHciCmd->Data);
3330 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfSCO = 0x%x\n",
3331 pBtMgnt->ExtConfig.NumberOfSCO));
3334 u8 localBuf[6] = "";
3337 struct packet_irp_hcievent_data *PPacketIrpEvent;
3339 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3341 len += bthci_CommandCompleteHeader(&localBuf[0],
3343 HCI_SET_SCO_LINK_STATUS,
3346 /* Return parameters starts from here */
3347 pRetPar = &PPacketIrpEvent->Data[len];
3348 pRetPar[0] = status; /* status */
3351 PPacketIrpEvent->Length = len;
3353 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3359 static enum hci_status
3360 bthci_CmdSetRSSIValue(
3361 struct rtw_adapter *padapter,
3362 struct packet_irp_hcicmd_data *pHciCmd
3365 enum hci_status status = HCI_STATUS_SUCCESS;
3366 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3367 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3370 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3371 if (pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle == *((u16 *)&pHciCmd->Data[0])) {
3372 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = (s8)(pHciCmd->Data[2]);
3373 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL,
3374 ("Connection_Handle = 0x%x, RSSI = %d \n",
3375 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3376 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI));
3378 /* get the minimum bt rssi value */
3379 if (pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI <= min_bt_rssi)
3380 min_bt_rssi = pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI;
3383 pBtMgnt->ExtConfig.MIN_BT_RSSI = min_bt_rssi;
3384 RTPRINT(FBT, BT_TRACE, ("[bt rssi], the min rssi is %d\n", min_bt_rssi));
3387 u8 localBuf[6] = "";
3390 struct packet_irp_hcievent_data *PPacketIrpEvent;
3392 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3394 len += bthci_CommandCompleteHeader(&localBuf[0],
3399 /* Return parameters starts from here */
3400 pRetPar = &PPacketIrpEvent->Data[len];
3401 pRetPar[0] = status; /* status */
3404 PPacketIrpEvent->Length = len;
3406 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3412 static enum hci_status
3413 bthci_CmdSetCurrentBluetoothStatus(
3414 struct rtw_adapter *padapter,
3415 struct packet_irp_hcicmd_data *pHciCmd
3418 enum hci_status status = HCI_STATUS_SUCCESS;
3419 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3420 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3421 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3423 pBtMgnt->ExtConfig.CurrentBTStatus = *((u8 *)&pHciCmd->Data[0]);
3424 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("SetCurrentBluetoothStatus, CurrentBTStatus = 0x%x\n",
3425 pBtMgnt->ExtConfig.CurrentBTStatus));
3428 u8 localBuf[6] = "";
3431 struct packet_irp_hcievent_data *PPacketIrpEvent;
3433 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3435 len += bthci_CommandCompleteHeader(&localBuf[0],
3437 HCI_SET_CURRENT_BLUETOOTH_STATUS,
3440 /* Return parameters starts from here */
3441 pRetPar = &PPacketIrpEvent->Data[len];
3442 pRetPar[0] = status; /* status */
3445 PPacketIrpEvent->Length = len;
3447 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3453 static enum hci_status
3454 bthci_CmdExtensionVersionNotify(
3455 struct rtw_adapter *padapter,
3456 struct packet_irp_hcicmd_data *pHciCmd
3459 enum hci_status status = HCI_STATUS_SUCCESS;
3460 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3461 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3462 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3464 pBtDbg->dbgHciInfo.hciCmdCntExtensionVersionNotify++;
3465 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "ExtensionVersionNotify, Hex Data :\n",
3466 &pHciCmd->Data[0], pHciCmd->Length);
3468 pBtMgnt->ExtConfig.HCIExtensionVer = *((u16 *)&pHciCmd->Data[0]);
3469 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = 0x%x\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3472 u8 localBuf[6] = "";
3475 struct packet_irp_hcievent_data *PPacketIrpEvent;
3477 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3479 len += bthci_CommandCompleteHeader(&localBuf[0],
3481 HCI_EXTENSION_VERSION_NOTIFY,
3484 /* Return parameters starts from here */
3485 pRetPar = &PPacketIrpEvent->Data[len];
3486 pRetPar[0] = status; /* status */
3489 PPacketIrpEvent->Length = len;
3491 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3497 static enum hci_status
3498 bthci_CmdLinkStatusNotify(
3499 struct rtw_adapter *padapter,
3500 struct packet_irp_hcicmd_data *pHciCmd
3503 enum hci_status status = HCI_STATUS_SUCCESS;
3504 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3505 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3506 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3510 pBtDbg->dbgHciInfo.hciCmdCntLinkStatusNotify++;
3511 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "LinkStatusNotify, Hex Data :\n",
3512 &pHciCmd->Data[0], pHciCmd->Length);
3514 /* Current only RTL8723 support this command. */
3515 pBtMgnt->bSupportProfile = true;
3517 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3518 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3519 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = %d\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3521 pTriple = &pHciCmd->Data[1];
3522 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3523 if (pBtMgnt->ExtConfig.HCIExtensionVer < 1) {
3524 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3525 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3526 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3527 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3528 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d\n",
3529 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3530 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3531 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec));
3533 } else if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
3534 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3535 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3536 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3537 pBtMgnt->ExtConfig.linkInfo[i].linkRole = pTriple[4];
3538 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3539 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d, LinkRole =%d\n",
3540 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3541 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3542 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec,
3543 pBtMgnt->ExtConfig.linkInfo[i].linkRole));
3548 BTHCI_UpdateBTProfileRTKToMoto(padapter);
3550 u8 localBuf[6] = "";
3553 struct packet_irp_hcievent_data *PPacketIrpEvent;
3555 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3557 len += bthci_CommandCompleteHeader(&localBuf[0],
3559 HCI_LINK_STATUS_NOTIFY,
3562 /* Return parameters starts from here */
3563 pRetPar = &PPacketIrpEvent->Data[len];
3564 pRetPar[0] = status; /* status */
3567 PPacketIrpEvent->Length = len;
3569 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3575 static enum hci_status
3576 bthci_CmdBtOperationNotify(
3577 struct rtw_adapter *padapter,
3578 struct packet_irp_hcicmd_data *pHciCmd
3581 enum hci_status status = HCI_STATUS_SUCCESS;
3582 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3583 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3585 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Bt Operation notify, Hex Data :\n",
3586 &pHciCmd->Data[0], pHciCmd->Length);
3588 pBtMgnt->ExtConfig.btOperationCode = *((u8 *)pHciCmd->Data);
3589 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("btOperationCode = 0x%x\n", pBtMgnt->ExtConfig.btOperationCode));
3590 switch (pBtMgnt->ExtConfig.btOperationCode) {
3591 case HCI_BT_OP_NONE:
3592 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Operation None!!\n"));
3594 case HCI_BT_OP_INQUIRY_START:
3595 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire start!!\n"));
3597 case HCI_BT_OP_INQUIRY_FINISH:
3598 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire finished!!\n"));
3600 case HCI_BT_OP_PAGING_START:
3601 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging is started!!\n"));
3603 case HCI_BT_OP_PAGING_SUCCESS:
3604 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete successfully!!\n"));
3606 case HCI_BT_OP_PAGING_UNSUCCESS:
3607 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete unsuccessfully!!\n"));
3609 case HCI_BT_OP_PAIRING_START:
3610 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing start!!\n"));
3612 case HCI_BT_OP_PAIRING_FINISH:
3613 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing finished!!\n"));
3615 case HCI_BT_OP_BT_DEV_ENABLE:
3616 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is enabled!!\n"));
3618 case HCI_BT_OP_BT_DEV_DISABLE:
3619 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is disabled!!\n"));
3622 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Unknown, error!!\n"));
3625 BTDM_AdjustForBtOperation(padapter);
3627 u8 localBuf[6] = "";
3630 struct packet_irp_hcievent_data *PPacketIrpEvent;
3632 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3634 len += bthci_CommandCompleteHeader(&localBuf[0],
3636 HCI_BT_OPERATION_NOTIFY,
3639 /* Return parameters starts from here */
3640 pRetPar = &PPacketIrpEvent->Data[len];
3641 pRetPar[0] = status; /* status */
3644 PPacketIrpEvent->Length = len;
3646 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3652 static enum hci_status
3653 bthci_CmdEnableWifiScanNotify(struct rtw_adapter *padapter,
3654 struct packet_irp_hcicmd_data *pHciCmd)
3656 enum hci_status status = HCI_STATUS_SUCCESS;
3657 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3658 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3660 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Enable Wifi scan notify, Hex Data :\n",
3661 &pHciCmd->Data[0], pHciCmd->Length);
3663 pBtMgnt->ExtConfig.bEnableWifiScanNotify = *((u8 *)pHciCmd->Data);
3664 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("bEnableWifiScanNotify = %d\n", pBtMgnt->ExtConfig.bEnableWifiScanNotify));
3667 u8 localBuf[6] = "";
3670 struct packet_irp_hcievent_data *PPacketIrpEvent;
3672 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3674 len += bthci_CommandCompleteHeader(&localBuf[0],
3676 HCI_ENABLE_WIFI_SCAN_NOTIFY,
3679 /* Return parameters starts from here */
3680 pRetPar = &PPacketIrpEvent->Data[len];
3681 pRetPar[0] = status; /* status */
3684 PPacketIrpEvent->Length = len;
3686 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3692 static enum hci_status
3693 bthci_CmdWIFICurrentChannel(struct rtw_adapter *padapter,
3694 struct packet_irp_hcicmd_data *pHciCmd)
3696 enum hci_status status = HCI_STATUS_SUCCESS;
3697 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3698 u8 chnl = pmlmeext->cur_channel;
3700 if (pmlmeext->cur_bwmode == HT_CHANNEL_WIDTH_40) {
3701 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
3703 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
3707 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current Channel = 0x%x\n", chnl));
3710 u8 localBuf[8] = "";
3713 struct packet_irp_hcievent_data *PPacketIrpEvent;
3715 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3717 len += bthci_CommandCompleteHeader(&localBuf[0],
3719 HCI_WIFI_CURRENT_CHANNEL,
3722 /* Return parameters starts from here */
3723 pRetPar = &PPacketIrpEvent->Data[len];
3724 pRetPar[0] = status; /* status */
3725 pRetPar[1] = chnl; /* current channel */
3727 PPacketIrpEvent->Length = len;
3729 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3735 static enum hci_status
3736 bthci_CmdWIFICurrentBandwidth(struct rtw_adapter *padapter,
3737 struct packet_irp_hcicmd_data *pHciCmd)
3739 enum hci_status status = HCI_STATUS_SUCCESS;
3740 enum ht_channel_width bw;
3743 bw = padapter->mlmeextpriv.cur_bwmode;
3745 if (bw == HT_CHANNEL_WIDTH_20)
3747 else if (bw == HT_CHANNEL_WIDTH_40)
3750 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current BW = 0x%x\n",
3754 u8 localBuf[8] = "";
3757 struct packet_irp_hcievent_data *PPacketIrpEvent;
3759 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3761 len += bthci_CommandCompleteHeader(&localBuf[0],
3763 HCI_WIFI_CURRENT_BANDWIDTH,
3766 /* Return parameters starts from here */
3767 pRetPar = &PPacketIrpEvent->Data[len];
3768 pRetPar[0] = status; /* status */
3769 pRetPar[1] = CurrentBW; /* current BW */
3771 PPacketIrpEvent->Length = len;
3773 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3779 static enum hci_status
3780 bthci_CmdWIFIConnectionStatus(
3781 struct rtw_adapter *padapter,
3782 struct packet_irp_hcicmd_data *pHciCmd
3785 enum hci_status status = HCI_STATUS_SUCCESS;
3786 u8 connectStatus = HCI_WIFI_NOT_CONNECTED;
3788 if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) {
3789 if (padapter->stapriv.asoc_sta_count >= 3)
3790 connectStatus = HCI_WIFI_CONNECTED;
3792 connectStatus = HCI_WIFI_NOT_CONNECTED;
3793 } else if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE|WIFI_ASOC_STATE)) {
3794 connectStatus = HCI_WIFI_CONNECTED;
3795 } else if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING)) {
3796 connectStatus = HCI_WIFI_CONNECT_IN_PROGRESS;
3798 connectStatus = HCI_WIFI_NOT_CONNECTED;
3802 u8 localBuf[8] = "";
3805 struct packet_irp_hcievent_data *PPacketIrpEvent;
3807 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3809 len += bthci_CommandCompleteHeader(&localBuf[0],
3811 HCI_WIFI_CONNECTION_STATUS,
3814 /* Return parameters starts from here */
3815 pRetPar = &PPacketIrpEvent->Data[len];
3816 pRetPar[0] = status; /* status */
3817 pRetPar[1] = connectStatus; /* connect status */
3819 PPacketIrpEvent->Length = len;
3821 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3827 static enum hci_status
3828 bthci_CmdEnableDeviceUnderTestMode(
3829 struct rtw_adapter *padapter,
3830 struct packet_irp_hcicmd_data *pHciCmd
3833 enum hci_status status = HCI_STATUS_SUCCESS;
3834 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3835 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3837 pBtHciInfo->bInTestMode = true;
3838 pBtHciInfo->bTestIsEnd = false;
3840 /* send command complete event here when all data are received. */
3842 u8 localBuf[6] = "";
3845 struct packet_irp_hcievent_data *PPacketIrpEvent;
3847 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3849 len += bthci_CommandCompleteHeader(&localBuf[0],
3850 OGF_TESTING_COMMANDS,
3851 HCI_ENABLE_DEVICE_UNDER_TEST_MODE,
3854 /* Return parameters starts from here */
3855 pRetPar = &PPacketIrpEvent->Data[len];
3856 pRetPar[0] = status; /* status */
3858 PPacketIrpEvent->Length = len;
3860 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3866 static enum hci_status
3867 bthci_CmdAMPTestEnd(struct rtw_adapter *padapter,
3868 struct packet_irp_hcicmd_data *pHciCmd)
3870 enum hci_status status = HCI_STATUS_SUCCESS;
3871 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3872 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3874 if (!pBtHciInfo->bInTestMode) {
3875 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3876 status = HCI_STATUS_CMD_DISALLOW;
3880 pBtHciInfo->bTestIsEnd = true;
3882 del_timer_sync(&pBTInfo->BTTestSendPacketTimer);
3884 rtl8723a_check_bssid(padapter, true);
3886 /* send command complete event here when all data are received. */
3888 u8 localBuf[4] = "";
3889 struct packet_irp_hcievent_data *PPacketIrpEvent;
3891 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3892 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3893 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3894 PPacketIrpEvent->Length = 2;
3896 PPacketIrpEvent->Data[0] = status;
3897 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario;
3899 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3902 bthci_EventAMPReceiverReport(padapter, 0x01);
3907 static enum hci_status
3908 bthci_CmdAMPTestCommand(struct rtw_adapter *padapter,
3909 struct packet_irp_hcicmd_data *pHciCmd)
3911 enum hci_status status = HCI_STATUS_SUCCESS;
3912 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3913 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3915 if (!pBtHciInfo->bInTestMode) {
3916 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3917 status = HCI_STATUS_CMD_DISALLOW;
3921 pBtHciInfo->TestScenario = *((u8 *)pHciCmd->Data);
3923 if (pBtHciInfo->TestScenario == 0x01)
3924 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
3925 else if (pBtHciInfo->TestScenario == 0x02)
3926 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
3928 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("No Such Test !!!!!!!!!!!!!!!!!! \n"));
3930 if (pBtHciInfo->bTestIsEnd) {
3931 u8 localBuf[5] = "";
3932 struct packet_irp_hcievent_data *PPacketIrpEvent;
3934 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3935 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3936 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3937 PPacketIrpEvent->Length = 2;
3939 PPacketIrpEvent->Data[0] = status;
3940 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
3942 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3944 /* Return to Idel state with RX and TX off. */
3949 /* should send command status event */
3950 bthci_EventCommandStatus(padapter,
3951 OGF_TESTING_COMMANDS,
3952 HCI_AMP_TEST_COMMAND,
3955 /* The HCI_AMP_Start Test Event shall be generated when the */
3956 /* HCI_AMP_Test_Command has completed and the first data is ready to be sent */
3960 u8 localBuf[5] = "";
3961 struct packet_irp_hcievent_data *PPacketIrpEvent;
3963 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_AMP_Start Test Event \n"));
3964 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3965 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_START_TEST;
3966 PPacketIrpEvent->Length = 2;
3968 PPacketIrpEvent->Data[0] = status;
3969 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
3971 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3973 /* Return to Idel state with RX and TX off. */
3976 if (pBtHciInfo->TestScenario == 0x01) {
3978 When in a transmitter test scenario and the frames/bursts count have been
3979 transmitted the HCI_AMP_Test_End event shall be sent.
3981 mod_timer(&pBTInfo->BTTestSendPacketTimer,
3982 jiffies + msecs_to_jiffies(50));
3983 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
3984 } else if (pBtHciInfo->TestScenario == 0x02) {
3985 rtl8723a_check_bssid(padapter, false);
3986 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
3992 static enum hci_status
3993 bthci_CmdEnableAMPReceiverReports(struct rtw_adapter *padapter,
3994 struct packet_irp_hcicmd_data *pHciCmd)
3996 enum hci_status status = HCI_STATUS_SUCCESS;
3997 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3998 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4000 if (!pBtHciInfo->bInTestMode) {
4001 status = HCI_STATUS_CMD_DISALLOW;
4002 /* send command complete event here when all data are received. */
4004 u8 localBuf[6] = "";
4007 struct packet_irp_hcievent_data *PPacketIrpEvent;
4009 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4011 len += bthci_CommandCompleteHeader(&localBuf[0],
4012 OGF_TESTING_COMMANDS,
4013 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4016 /* Return parameters starts from here */
4017 pRetPar = &PPacketIrpEvent->Data[len];
4018 pRetPar[0] = status; /* status */
4020 PPacketIrpEvent->Length = len;
4022 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4027 pBtHciInfo->bTestNeedReport = *((u8 *)pHciCmd->Data);
4028 pBtHciInfo->TestReportInterval = (*((u8 *)pHciCmd->Data+2));
4030 bthci_EventAMPReceiverReport(padapter, 0x00);
4032 /* send command complete event here when all data are received. */
4034 u8 localBuf[6] = "";
4037 struct packet_irp_hcievent_data *PPacketIrpEvent;
4039 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4041 len += bthci_CommandCompleteHeader(&localBuf[0],
4042 OGF_TESTING_COMMANDS,
4043 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4046 /* Return parameters starts from here */
4047 pRetPar = &PPacketIrpEvent->Data[len];
4048 pRetPar[0] = status; /* status */
4050 PPacketIrpEvent->Length = len;
4052 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4058 static enum hci_status
4059 bthci_CmdHostBufferSize(struct rtw_adapter *padapter,
4060 struct packet_irp_hcicmd_data *pHciCmd)
4062 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4063 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4064 struct packet_irp_hcievent_data *PPacketIrpEvent;
4065 enum hci_status status = HCI_STATUS_SUCCESS;
4066 u8 localBuf[6] = "";
4070 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].ACLPacketsData.ACLDataPacketLen = *((u16 *)pHciCmd->Data);
4071 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].SyncDataPacketLen = *((u8 *)(pHciCmd->Data+2));
4072 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalNumACLDataPackets = *((u16 *)(pHciCmd->Data+3));
4073 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalSyncNumDataPackets = *((u16 *)(pHciCmd->Data+5));
4075 /* send command complete event here when all data are received. */
4076 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4078 len += bthci_CommandCompleteHeader(&localBuf[0],
4079 OGF_SET_EVENT_MASK_COMMAND,
4080 HCI_HOST_BUFFER_SIZE,
4083 /* Return parameters starts from here */
4084 pRetPar = &PPacketIrpEvent->Data[len];
4085 pRetPar[0] = status; /* status */
4087 PPacketIrpEvent->Length = len;
4089 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4094 static enum hci_status
4095 bthci_UnknownCMD(struct rtw_adapter *padapter, struct packet_irp_hcicmd_data *pHciCmd)
4097 enum hci_status status = HCI_STATUS_UNKNOW_HCI_CMD;
4098 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4099 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
4101 pBtDbg->dbgHciInfo.hciCmdCntUnknown++;
4102 bthci_EventCommandStatus(padapter,
4110 static enum hci_status
4111 bthci_HandleOGFInformationalParameters(struct rtw_adapter *padapter,
4112 struct packet_irp_hcicmd_data *pHciCmd)
4114 enum hci_status status = HCI_STATUS_SUCCESS;
4116 switch (pHciCmd->OCF) {
4117 case HCI_READ_LOCAL_VERSION_INFORMATION:
4118 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_VERSION_INFORMATION\n"));
4119 status = bthci_CmdReadLocalVersionInformation(padapter);
4121 case HCI_READ_LOCAL_SUPPORTED_COMMANDS:
4122 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_COMMANDS\n"));
4123 status = bthci_CmdReadLocalSupportedCommands(padapter);
4125 case HCI_READ_LOCAL_SUPPORTED_FEATURES:
4126 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_FEATURES\n"));
4127 status = bthci_CmdReadLocalSupportedFeatures(padapter);
4129 case HCI_READ_BUFFER_SIZE:
4130 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BUFFER_SIZE\n"));
4131 status = bthci_CmdReadBufferSize(padapter);
4133 case HCI_READ_DATA_BLOCK_SIZE:
4134 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_DATA_BLOCK_SIZE\n"));
4135 status = bthci_CmdReadDataBlockSize(padapter);
4138 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFInformationalParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4139 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4140 status = bthci_UnknownCMD(padapter, pHciCmd);
4146 static enum hci_status
4147 bthci_HandleOGFSetEventMaskCMD(struct rtw_adapter *padapter,
4148 struct packet_irp_hcicmd_data *pHciCmd)
4150 enum hci_status status = HCI_STATUS_SUCCESS;
4152 switch (pHciCmd->OCF) {
4153 case HCI_SET_EVENT_MASK:
4154 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK\n"));
4155 status = bthci_CmdSetEventMask(padapter, pHciCmd);
4158 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET\n"));
4159 status = bthci_CmdReset(padapter, true);
4161 case HCI_READ_CONNECTION_ACCEPT_TIMEOUT:
4162 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_CONNECTION_ACCEPT_TIMEOUT\n"));
4163 status = bthci_CmdReadConnectionAcceptTimeout(padapter);
4165 case HCI_SET_EVENT_FILTER:
4166 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_FILTER\n"));
4168 case HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT:
4169 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT\n"));
4170 status = bthci_CmdWriteConnectionAcceptTimeout(padapter, pHciCmd);
4172 case HCI_READ_PAGE_TIMEOUT:
4173 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_PAGE_TIMEOUT\n"));
4174 status = bthci_CmdReadPageTimeout(padapter, pHciCmd);
4176 case HCI_WRITE_PAGE_TIMEOUT:
4177 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_PAGE_TIMEOUT\n"));
4178 status = bthci_CmdWritePageTimeout(padapter, pHciCmd);
4180 case HCI_HOST_NUMBER_OF_COMPLETED_PACKETS:
4181 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_NUMBER_OF_COMPLETED_PACKETS\n"));
4183 case HCI_READ_LINK_SUPERVISION_TIMEOUT:
4184 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_SUPERVISION_TIMEOUT\n"));
4185 status = bthci_CmdReadLinkSupervisionTimeout(padapter, pHciCmd);
4187 case HCI_WRITE_LINK_SUPERVISION_TIMEOUT:
4188 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LINK_SUPERVISION_TIMEOUT\n"));
4189 status = bthci_CmdWriteLinkSupervisionTimeout(padapter, pHciCmd);
4191 case HCI_ENHANCED_FLUSH:
4192 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENHANCED_FLUSH\n"));
4193 status = bthci_CmdEnhancedFlush(padapter, pHciCmd);
4195 case HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT:
4196 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4197 status = bthci_CmdReadLogicalLinkAcceptTimeout(padapter, pHciCmd);
4199 case HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT:
4200 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4201 status = bthci_CmdWriteLogicalLinkAcceptTimeout(padapter, pHciCmd);
4203 case HCI_SET_EVENT_MASK_PAGE_2:
4204 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK_PAGE_2\n"));
4205 status = bthci_CmdSetEventMaskPage2(padapter, pHciCmd);
4207 case HCI_READ_LOCATION_DATA:
4208 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCATION_DATA\n"));
4209 status = bthci_CmdReadLocationData(padapter, pHciCmd);
4211 case HCI_WRITE_LOCATION_DATA:
4212 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOCATION_DATA\n"));
4213 status = bthci_CmdWriteLocationData(padapter, pHciCmd);
4215 case HCI_READ_FLOW_CONTROL_MODE:
4216 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FLOW_CONTROL_MODE\n"));
4217 status = bthci_CmdReadFlowControlMode(padapter, pHciCmd);
4219 case HCI_WRITE_FLOW_CONTROL_MODE:
4220 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_FLOW_CONTROL_MODE\n"));
4221 status = bthci_CmdWriteFlowControlMode(padapter, pHciCmd);
4223 case HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT:
4224 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4225 status = bthci_CmdReadBestEffortFlushTimeout(padapter, pHciCmd);
4227 case HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT:
4228 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4229 status = bthci_CmdWriteBestEffortFlushTimeout(padapter, pHciCmd);
4231 case HCI_SHORT_RANGE_MODE:
4232 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SHORT_RANGE_MODE\n"));
4233 status = bthci_CmdShortRangeMode(padapter, pHciCmd);
4235 case HCI_HOST_BUFFER_SIZE:
4236 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_BUFFER_SIZE\n"));
4237 status = bthci_CmdHostBufferSize(padapter, pHciCmd);
4240 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFSetEventMaskCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4241 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4242 status = bthci_UnknownCMD(padapter, pHciCmd);
4248 static enum hci_status
4249 bthci_HandleOGFStatusParameters(struct rtw_adapter *padapter,
4250 struct packet_irp_hcicmd_data *pHciCmd)
4252 enum hci_status status = HCI_STATUS_SUCCESS;
4254 switch (pHciCmd->OCF) {
4255 case HCI_READ_FAILED_CONTACT_COUNTER:
4256 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FAILED_CONTACT_COUNTER\n"));
4257 status = bthci_CmdReadFailedContactCounter(padapter, pHciCmd);
4259 case HCI_RESET_FAILED_CONTACT_COUNTER:
4260 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET_FAILED_CONTACT_COUNTER\n"));
4261 status = bthci_CmdResetFailedContactCounter(padapter, pHciCmd);
4263 case HCI_READ_LINK_QUALITY:
4264 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_QUALITY\n"));
4265 status = bthci_CmdReadLinkQuality(padapter, pHciCmd);
4268 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_RSSI\n"));
4270 case HCI_READ_LOCAL_AMP_INFO:
4271 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_INFO\n"));
4272 status = bthci_CmdReadLocalAMPInfo(padapter);
4274 case HCI_READ_LOCAL_AMP_ASSOC:
4275 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_ASSOC\n"));
4276 status = bthci_CmdReadLocalAMPAssoc(padapter, pHciCmd);
4278 case HCI_WRITE_REMOTE_AMP_ASSOC:
4279 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_REMOTE_AMP_ASSOC\n"));
4280 status = bthci_CmdWriteRemoteAMPAssoc(padapter, pHciCmd);
4283 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFStatusParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4284 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4285 status = bthci_UnknownCMD(padapter, pHciCmd);
4291 static enum hci_status
4292 bthci_HandleOGFLinkControlCMD(struct rtw_adapter *padapter,
4293 struct packet_irp_hcicmd_data *pHciCmd)
4295 enum hci_status status = HCI_STATUS_SUCCESS;
4297 switch (pHciCmd->OCF) {
4298 case HCI_CREATE_PHYSICAL_LINK:
4299 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_PHYSICAL_LINK\n"));
4300 status = bthci_CmdCreatePhysicalLink(padapter, pHciCmd);
4302 case HCI_ACCEPT_PHYSICAL_LINK:
4303 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_PHYSICAL_LINK\n"));
4304 status = bthci_CmdAcceptPhysicalLink(padapter, pHciCmd);
4306 case HCI_DISCONNECT_PHYSICAL_LINK:
4307 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK\n"));
4308 status = bthci_CmdDisconnectPhysicalLink(padapter, pHciCmd);
4310 case HCI_CREATE_LOGICAL_LINK:
4311 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_LOGICAL_LINK\n"));
4312 status = bthci_CmdCreateLogicalLink(padapter, pHciCmd);
4314 case HCI_ACCEPT_LOGICAL_LINK:
4315 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_LOGICAL_LINK\n"));
4316 status = bthci_CmdAcceptLogicalLink(padapter, pHciCmd);
4318 case HCI_DISCONNECT_LOGICAL_LINK:
4319 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_LOGICAL_LINK\n"));
4320 status = bthci_CmdDisconnectLogicalLink(padapter, pHciCmd);
4322 case HCI_LOGICAL_LINK_CANCEL:
4323 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_LOGICAL_LINK_CANCEL\n"));
4324 status = bthci_CmdLogicalLinkCancel(padapter, pHciCmd);
4326 case HCI_FLOW_SPEC_MODIFY:
4327 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_FLOW_SPEC_MODIFY\n"));
4328 status = bthci_CmdFlowSpecModify(padapter, pHciCmd);
4331 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFLinkControlCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4332 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4333 status = bthci_UnknownCMD(padapter, pHciCmd);
4339 static enum hci_status
4340 bthci_HandleOGFTestingCMD(struct rtw_adapter *padapter,
4341 struct packet_irp_hcicmd_data *pHciCmd)
4343 enum hci_status status = HCI_STATUS_SUCCESS;
4344 switch (pHciCmd->OCF) {
4345 case HCI_ENABLE_DEVICE_UNDER_TEST_MODE:
4346 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_DEVICE_UNDER_TEST_MODE\n"));
4347 bthci_CmdEnableDeviceUnderTestMode(padapter, pHciCmd);
4349 case HCI_AMP_TEST_END:
4350 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_END\n"));
4351 bthci_CmdAMPTestEnd(padapter, pHciCmd);
4353 case HCI_AMP_TEST_COMMAND:
4354 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_COMMAND\n"));
4355 bthci_CmdAMPTestCommand(padapter, pHciCmd);
4357 case HCI_ENABLE_AMP_RECEIVER_REPORTS:
4358 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_AMP_RECEIVER_REPORTS\n"));
4359 bthci_CmdEnableAMPReceiverReports(padapter, pHciCmd);
4362 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4363 status = bthci_UnknownCMD(padapter, pHciCmd);
4369 static enum hci_status
4370 bthci_HandleOGFExtension(struct rtw_adapter *padapter,
4371 struct packet_irp_hcicmd_data *pHciCmd)
4373 enum hci_status status = HCI_STATUS_SUCCESS;
4374 switch (pHciCmd->OCF) {
4375 case HCI_SET_ACL_LINK_DATA_FLOW_MODE:
4376 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_DATA_FLOW_MODE\n"));
4377 status = bthci_CmdSetACLLinkDataFlowMode(padapter, pHciCmd);
4379 case HCI_SET_ACL_LINK_STATUS:
4380 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_STATUS\n"));
4381 status = bthci_CmdSetACLLinkStatus(padapter, pHciCmd);
4383 case HCI_SET_SCO_LINK_STATUS:
4384 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_SCO_LINK_STATUS\n"));
4385 status = bthci_CmdSetSCOLinkStatus(padapter, pHciCmd);
4387 case HCI_SET_RSSI_VALUE:
4388 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("HCI_SET_RSSI_VALUE\n"));
4389 status = bthci_CmdSetRSSIValue(padapter, pHciCmd);
4391 case HCI_SET_CURRENT_BLUETOOTH_STATUS:
4392 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_CURRENT_BLUETOOTH_STATUS\n"));
4393 status = bthci_CmdSetCurrentBluetoothStatus(padapter, pHciCmd);
4395 /* The following is for RTK8723 */
4397 case HCI_EXTENSION_VERSION_NOTIFY:
4398 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_EXTENSION_VERSION_NOTIFY\n"));
4399 status = bthci_CmdExtensionVersionNotify(padapter, pHciCmd);
4401 case HCI_LINK_STATUS_NOTIFY:
4402 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_LINK_STATUS_NOTIFY\n"));
4403 status = bthci_CmdLinkStatusNotify(padapter, pHciCmd);
4405 case HCI_BT_OPERATION_NOTIFY:
4406 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_BT_OPERATION_NOTIFY\n"));
4407 status = bthci_CmdBtOperationNotify(padapter, pHciCmd);
4409 case HCI_ENABLE_WIFI_SCAN_NOTIFY:
4410 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_ENABLE_WIFI_SCAN_NOTIFY\n"));
4411 status = bthci_CmdEnableWifiScanNotify(padapter, pHciCmd);
4414 /* The following is for IVT */
4415 case HCI_WIFI_CURRENT_CHANNEL:
4416 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_CHANNEL\n"));
4417 status = bthci_CmdWIFICurrentChannel(padapter, pHciCmd);
4419 case HCI_WIFI_CURRENT_BANDWIDTH:
4420 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_BANDWIDTH\n"));
4421 status = bthci_CmdWIFICurrentBandwidth(padapter, pHciCmd);
4423 case HCI_WIFI_CONNECTION_STATUS:
4424 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CONNECTION_STATUS\n"));
4425 status = bthci_CmdWIFIConnectionStatus(padapter, pHciCmd);
4429 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_UNKNOWN_COMMAND\n"));
4430 status = bthci_UnknownCMD(padapter, pHciCmd);
4437 bthci_StateStarting(struct rtw_adapter *padapter,
4438 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4440 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4441 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4443 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Starting], "));
4445 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4446 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4447 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4448 pBtMgnt->bNeedNotifyAMPNoCap = true;
4449 BTHCI_DisconnectPeer(padapter, EntryNum);
4451 case STATE_CMD_DISCONNECT_PHY_LINK:
4452 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4454 bthci_EventDisconnectPhyLinkComplete(padapter,
4456 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4459 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4461 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4463 BTHCI_DisconnectPeer(padapter, EntryNum);
4465 case STATE_CMD_MAC_START_COMPLETE:
4466 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_START_COMPLETE\n"));
4467 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR)
4468 bthci_EventChannelSelected(padapter, EntryNum);
4471 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4477 bthci_StateConnecting(struct rtw_adapter *padapter,
4478 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4480 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4481 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4483 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connecting], "));
4485 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4486 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4487 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4488 pBtMgnt->bNeedNotifyAMPNoCap = true;
4489 BTHCI_DisconnectPeer(padapter, EntryNum);
4491 case STATE_CMD_MAC_CONNECT_COMPLETE:
4492 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_COMPLETE\n"));
4494 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_JOINER) {
4495 RT_TRACE(_module_rtl871x_security_c_, _drv_info_,
4496 "StateConnecting\n");
4499 case STATE_CMD_DISCONNECT_PHY_LINK:
4500 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4502 bthci_EventDisconnectPhyLinkComplete(padapter,
4504 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4507 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4509 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4511 BTHCI_DisconnectPeer(padapter, EntryNum);
4514 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4515 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4516 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONTROLLER_BUSY;
4517 /* Because this state cmd is caused by the BTHCI_EventAMPStatusChange(), */
4518 /* we don't need to send event in the following BTHCI_DisconnectPeer() again. */
4519 pBtMgnt->bNeedNotifyAMPNoCap = false;
4520 BTHCI_DisconnectPeer(padapter, EntryNum);
4523 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4529 bthci_StateConnected(struct rtw_adapter *padapter,
4530 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4532 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4533 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4534 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4536 u16 logicHandle = 0;
4538 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connected], "));
4540 case STATE_CMD_DISCONNECT_PHY_LINK:
4541 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4543 /* When we are trying to disconnect the phy link, we should disconnect log link first, */
4544 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
4545 if (pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle != 0) {
4546 logicHandle = pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle;
4548 bthci_EventDisconnectLogicalLinkComplete(padapter, HCI_STATUS_SUCCESS,
4549 logicHandle, pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason);
4551 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle = 0;
4555 bthci_EventDisconnectPhyLinkComplete(padapter,
4557 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4560 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4562 BTHCI_DisconnectPeer(padapter, EntryNum);
4565 case STATE_CMD_MAC_DISCONNECT_INDICATE:
4566 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_DISCONNECT_INDICATE\n"));
4568 bthci_EventDisconnectPhyLinkComplete(padapter,
4570 /* TODO: Remote Host not local host */
4571 HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST,
4573 BTHCI_DisconnectPeer(padapter, EntryNum);
4576 case STATE_CMD_ENTER_STATE:
4577 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4579 if (pBtMgnt->bBTConnectInProgress) {
4580 pBtMgnt->bBTConnectInProgress = false;
4581 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4583 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_CONNECTED;
4584 pBTInfo->BtAsocEntry[EntryNum].b4waySuccess = true;
4585 pBtMgnt->bStartSendSupervisionPkt = true;
4587 /* for rate adaptive */
4589 rtl8723a_update_ramask(padapter,
4590 MAX_FW_SUPPORT_MACID_NUM-1-EntryNum, 0);
4592 HalSetBrateCfg23a(padapter, padapter->mlmepriv.cur_network.network.SupportedRates);
4593 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
4596 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4602 bthci_StateAuth(struct rtw_adapter *padapter, enum hci_state_with_cmd StateCmd,
4605 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4606 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4608 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Authenticating], "));
4610 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4611 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4612 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4613 pBtMgnt->bNeedNotifyAMPNoCap = true;
4614 BTHCI_DisconnectPeer(padapter, EntryNum);
4616 case STATE_CMD_DISCONNECT_PHY_LINK:
4617 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4618 bthci_EventDisconnectPhyLinkComplete(padapter,
4620 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4623 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4625 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4627 BTHCI_DisconnectPeer(padapter, EntryNum);
4629 case STATE_CMD_4WAY_FAILED:
4630 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_FAILED\n"));
4632 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_AUTH_FAIL;
4633 pBtMgnt->bNeedNotifyAMPNoCap = true;
4635 BTHCI_DisconnectPeer(padapter, EntryNum);
4637 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4639 case STATE_CMD_4WAY_SUCCESSED:
4640 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_SUCCESSED\n"));
4642 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_SUCCESS, EntryNum, INVALID_PL_HANDLE);
4644 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4646 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4649 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4655 bthci_StateDisconnecting(struct rtw_adapter *padapter,
4656 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4658 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4659 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4661 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnecting], "));
4663 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4664 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4665 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4666 bthci_EventPhysicalLinkComplete(padapter,
4667 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus,
4668 EntryNum, INVALID_PL_HANDLE);
4671 if (pBtMgnt->bBTConnectInProgress) {
4672 pBtMgnt->bBTConnectInProgress = false;
4673 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4676 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4678 case STATE_CMD_DISCONNECT_PHY_LINK:
4679 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4681 bthci_EventDisconnectPhyLinkComplete(padapter,
4683 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4686 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4688 BTHCI_DisconnectPeer(padapter, EntryNum);
4691 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4697 bthci_StateDisconnected(struct rtw_adapter *padapter,
4698 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4700 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4701 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4702 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4703 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4705 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnected], "));
4707 case STATE_CMD_CREATE_PHY_LINK:
4708 case STATE_CMD_ACCEPT_PHY_LINK:
4709 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4710 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CREATE_PHY_LINK\n"));
4712 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ACCEPT_PHY_LINK\n"));
4714 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], Disable IPS and LPS\n"));
4715 ips_leave23a(padapter);
4716 LPS_Leave23a(padapter);
4718 pBtMgnt->bPhyLinkInProgress = true;
4719 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
4720 pBtMgnt->CurrentBTConnectionCnt++;
4721 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d\n",
4722 pBtMgnt->CurrentBTConnectionCnt));
4723 pBtMgnt->BtOperationOn = true;
4724 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation ON!! CurrentConnectEntryNum = %d\n",
4725 pBtMgnt->CurrentConnectEntryNum));
4727 if (pBtMgnt->bBTConnectInProgress) {
4728 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONTROLLER_BUSY, INVALID_ENTRY_NUM, pBtMgnt->BtCurrentPhyLinkhandle);
4729 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4733 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4734 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_CREATOR;
4736 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_JOINER;
4738 /* 1. MAC not yet in selected channel */
4739 while (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)) {
4740 RTPRINT(FIOCTL, IOCTL_STATE, ("Scan/Roaming/Wifi Link is in Progress, wait 200 ms\n"));
4743 /* 2. MAC already in selected channel */
4744 RTPRINT(FIOCTL, IOCTL_STATE, ("Channel is Ready\n"));
4745 mod_timer(&pBTInfo->BTHCIJoinTimeoutTimer,
4746 jiffies + msecs_to_jiffies(pBtHciInfo->ConnAcceptTimeout));
4748 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = true;
4750 case STATE_CMD_DISCONNECT_PHY_LINK:
4751 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4753 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4755 bthci_EventDisconnectPhyLinkComplete(padapter,
4757 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4760 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4761 bthci_EventPhysicalLinkComplete(padapter,
4762 HCI_STATUS_UNKNOW_CONNECT_ID,
4763 EntryNum, INVALID_PL_HANDLE);
4766 if (pBtMgnt->bBTConnectInProgress) {
4767 pBtMgnt->bBTConnectInProgress = false;
4768 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4770 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4771 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4773 case STATE_CMD_ENTER_STATE:
4774 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4777 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4782 void BTHCI_EventParse(struct rtw_adapter *padapter, void *pEvntData, u32 dataLen)
4786 u8 BTHCI_HsConnectionEstablished(struct rtw_adapter *padapter)
4788 u8 bBtConnectionExist = false;
4789 struct bt_30info *pBtinfo = GET_BT_INFO(padapter);
4792 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
4793 if (pBtinfo->BtAsocEntry[i].b4waySuccess) {
4794 bBtConnectionExist = true;
4799 /*RTPRINT(FIOCTL, IOCTL_STATE, (" BTHCI_HsConnectionEstablished(), connection exist = %d\n", bBtConnectionExist)); */
4801 return bBtConnectionExist;
4805 BTHCI_CheckProfileExist(struct rtw_adapter *padapter,
4806 enum bt_traffic_mode_profile Profile)
4808 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4809 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4810 u8 IsPRofile = false;
4813 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4814 if (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile == Profile) {
4823 void BTHCI_UpdateBTProfileRTKToMoto(struct rtw_adapter *padapter)
4825 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4826 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4829 pBtMgnt->ExtConfig.NumberOfSCO = 0;
4831 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4832 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
4834 if (pBtMgnt->ExtConfig.linkInfo[i].BTProfile == BT_PROFILE_SCO)
4835 pBtMgnt->ExtConfig.NumberOfSCO++;
4837 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = pBtMgnt->ExtConfig.linkInfo[i].BTProfile;
4838 switch (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile) {
4839 case BT_PROFILE_SCO:
4841 case BT_PROFILE_PAN:
4842 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_BE;
4843 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4845 case BT_PROFILE_A2DP:
4846 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GULB;
4847 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_GULB;
4849 case BT_PROFILE_HID:
4850 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GUL;
4851 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4858 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RTK, NumberOfHandle = %d, NumberOfSCO = %d\n",
4859 pBtMgnt->ExtConfig.NumberOfHandle, pBtMgnt->ExtConfig.NumberOfSCO));
4862 void BTHCI_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
4864 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4865 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4867 if (pBtMgnt->ExtConfig.bEnableWifiScanNotify)
4868 bthci_EventExtWifiScanNotify(padapter, scanType);
4873 struct rtw_adapter *padapter,
4875 enum hci_state_with_cmd StateCmd,
4879 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4880 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4882 if (EntryNum == 0xff) {
4883 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, error EntryNum = 0x%x \n", EntryNum));
4886 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, EntryNum = 0x%x, CurrentState = 0x%x, BtNextState = 0x%x, StateCmd = 0x%x , StateToEnter = 0x%x\n",
4887 EntryNum, pBTInfo->BtAsocEntry[EntryNum].BtCurrentState, pBTInfo->BtAsocEntry[EntryNum].BtNextState, StateCmd, StateToEnter));
4889 if (pBTInfo->BtAsocEntry[EntryNum].BtNextState & StateToEnter) {
4890 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = StateToEnter;
4892 switch (StateToEnter) {
4893 case HCI_STATE_STARTING:
4894 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTING;
4895 bthci_StateStarting(padapter, StateCmd, EntryNum);
4897 case HCI_STATE_CONNECTING:
4898 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTING | HCI_STATE_DISCONNECTING | HCI_STATE_AUTHENTICATING;
4899 bthci_StateConnecting(padapter, StateCmd, EntryNum);
4901 case HCI_STATE_AUTHENTICATING:
4902 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTED;
4903 bthci_StateAuth(padapter, StateCmd, EntryNum);
4905 case HCI_STATE_CONNECTED:
4906 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTED | HCI_STATE_DISCONNECTING;
4907 bthci_StateConnected(padapter, StateCmd, EntryNum);
4909 case HCI_STATE_DISCONNECTING:
4910 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_DISCONNECTING;
4911 bthci_StateDisconnecting(padapter, StateCmd, EntryNum);
4913 case HCI_STATE_DISCONNECTED:
4914 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_STARTING | HCI_STATE_CONNECTING;
4915 bthci_StateDisconnected(padapter, StateCmd, EntryNum);
4918 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Unknown state to enter!!!\n"));
4922 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Wrong state to enter\n"));
4925 /* 20100325 Joseph: Disable/Enable IPS/LPS according to BT status. */
4926 if (!pBtMgnt->bBTConnectInProgress && !pBtMgnt->BtOperationOn) {
4927 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], ips_enter23a()\n"));
4928 ips_enter23a(padapter);
4932 void BTHCI_DisconnectPeer(struct rtw_adapter *padapter, u8 EntryNum)
4934 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4935 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4937 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" BTHCI_DisconnectPeer()\n"));
4939 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, EntryNum);
4941 if (pBTInfo->BtAsocEntry[EntryNum].bUsed) {
4942 /*BTPKT_SendDeauthentication(padapter, pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, unspec_reason); not porting yet */
4945 if (pBtMgnt->bBTConnectInProgress) {
4946 pBtMgnt->bBTConnectInProgress = false;
4947 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4950 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4952 if (pBtMgnt->bNeedNotifyAMPNoCap) {
4953 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT AMPStatus], set to invalid in BTHCI_DisconnectPeer()\n"));
4954 BTHCI_EventAMPStatusChange(padapter, AMP_STATUS_NO_CAPACITY_FOR_BT);
4958 void BTHCI_EventNumOfCompletedDataBlocks(struct rtw_adapter *padapter)
4960 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4961 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4962 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4963 u8 localBuf[TmpLocalBufSize] = "";
4964 u8 *pRetPar, *pTriple;
4965 u8 len = 0, i, j, handleNum = 0;
4966 struct packet_irp_hcievent_data *PPacketIrpEvent;
4967 u16 *pu2Temp, *pPackets, *pHandle, *pDblocks;
4970 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4972 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS)) {
4973 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Num Of Completed DataBlocks, Ignore to send NumOfCompletedDataBlocksEvent due to event mask page 2\n"));
4977 /* Return parameters starts from here */
4978 pRetPar = &PPacketIrpEvent->Data[0];
4979 pTriple = &pRetPar[3];
4980 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
4982 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
4983 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle) {
4985 pHandle = (u16 *)&pTriple[0]; /* Handle[i] */
4986 pPackets = (u16 *)&pTriple[2]; /* Num_Of_Completed_Packets[i] */
4987 pDblocks = (u16 *)&pTriple[4]; /* Num_Of_Completed_Blocks[i] */
4988 *pHandle = pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle;
4989 *pPackets = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
4990 *pDblocks = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
4991 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount) {
4993 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL,
4994 ("[BT event], Num Of Completed DataBlocks, Handle = 0x%x, Num_Of_Completed_Packets = 0x%x, Num_Of_Completed_Blocks = 0x%x\n",
4995 *pHandle, *pPackets, *pDblocks));
4997 pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount = 0;
5004 pRetPar[2] = handleNum; /* Number_of_Handles */
5006 pu2Temp = (u16 *)&pRetPar[0];
5007 *pu2Temp = BTTotalDataBlockNum;
5010 PPacketIrpEvent->EventCode = HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS;
5011 PPacketIrpEvent->Length = len;
5012 if (handleNum && sent)
5013 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
5016 void BTHCI_EventAMPStatusChange(struct rtw_adapter *padapter, u8 AMP_Status)
5018 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5019 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
5020 struct packet_irp_hcievent_data *PPacketIrpEvent;
5022 u8 localBuf[7] = "";
5025 if (AMP_Status == AMP_STATUS_NO_CAPACITY_FOR_BT) {
5026 pBtMgnt->BTNeedAMPStatusChg = true;
5027 pBtMgnt->bNeedNotifyAMPNoCap = false;
5029 BTHCI_DisconnectAll(padapter);
5030 } else if (AMP_Status == AMP_STATUS_FULL_CAPACITY_FOR_BT) {
5031 pBtMgnt->BTNeedAMPStatusChg = false;
5034 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5035 /* Return parameters starts from here */
5036 pRetPar = &PPacketIrpEvent->Data[0];
5038 pRetPar[0] = 0; /* Status */
5040 pRetPar[1] = AMP_Status; /* AMP_Status */
5043 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_STATUS_CHANGE;
5044 PPacketIrpEvent->Length = len;
5045 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS)
5046 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_STATE), ("[BT event], AMP Status Change, AMP_Status = %d\n", AMP_Status));
5049 void BTHCI_DisconnectAll(struct rtw_adapter *padapter)
5051 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5054 RTPRINT(FIOCTL, IOCTL_STATE, (" DisconnectALL()\n"));
5056 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
5057 if (pBTInfo->BtAsocEntry[i].b4waySuccess) {
5058 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, i);
5059 } else if (pBTInfo->BtAsocEntry[i].bUsed) {
5060 if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_CONNECTING) {
5061 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5062 } else if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_DISCONNECTING) {
5063 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5071 struct rtw_adapter *padapter,
5072 struct packet_irp_hcicmd_data *pHciCmd
5075 enum hci_status status = HCI_STATUS_SUCCESS;
5076 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5077 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
5079 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("\n"));
5080 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI Command start, OGF = 0x%x, OCF = 0x%x, Length = 0x%x\n",
5081 pHciCmd->OGF, pHciCmd->OCF, pHciCmd->Length));
5082 if (pHciCmd->Length) {
5083 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "HCI Command, Hex Data :\n",
5084 &pHciCmd->Data[0], pHciCmd->Length);
5086 if (pHciCmd->OGF == OGF_EXTENSION) {
5087 if (pHciCmd->OCF == HCI_SET_RSSI_VALUE)
5088 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("[BT cmd], "));
5090 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[BT cmd], "));
5092 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("[BT cmd], "));
5095 pBtDbg->dbgHciInfo.hciCmdCnt++;
5097 switch (pHciCmd->OGF) {
5098 case LINK_CONTROL_COMMANDS:
5099 status = bthci_HandleOGFLinkControlCMD(padapter, pHciCmd);
5101 case HOLD_MODE_COMMAND:
5103 case OGF_SET_EVENT_MASK_COMMAND:
5104 status = bthci_HandleOGFSetEventMaskCMD(padapter, pHciCmd);
5106 case OGF_INFORMATIONAL_PARAMETERS:
5107 status = bthci_HandleOGFInformationalParameters(padapter, pHciCmd);
5109 case OGF_STATUS_PARAMETERS:
5110 status = bthci_HandleOGFStatusParameters(padapter, pHciCmd);
5112 case OGF_TESTING_COMMANDS:
5113 status = bthci_HandleOGFTestingCMD(padapter, pHciCmd);
5116 status = bthci_HandleOGFExtension(padapter, pHciCmd);
5119 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI Command(), Unknown OGF = 0x%x\n", pHciCmd->OGF));
5120 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
5121 status = bthci_UnknownCMD(padapter, pHciCmd);
5124 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("HCI Command execution end!!\n"));
5129 /* ===== End of sync from SD7 driver COMMOM/bt_hci.c ===== */
5131 static const char *const BtStateString[] = {
5139 "BT_ACL_INQ_OR_PAG",
5140 "BT_STATE_NOT_DEFINED"
5143 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
5145 static void btdm_SetFwIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
5147 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5148 u8 H2C_Parameter[1] = {0};
5151 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Ignore Wlan_Act !!\n"));
5152 H2C_Parameter[0] |= BIT(0); /* function enable */
5153 pHalData->bt_coexist.bFWCoexistAllOff = false;
5155 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT don't ignore Wlan_Act !!\n"));
5158 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, write 0x25 = 0x%02x\n",
5161 FillH2CCmd(padapter, BT_IGNORE_WLAN_ACT_EID, 1, H2C_Parameter);
5164 static void btdm_NotifyFwScan(struct rtw_adapter *padapter, u8 scanType)
5166 u8 H2C_Parameter[1] = {0};
5168 if (scanType == true)
5169 H2C_Parameter[0] = 0x1;
5171 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Notify FW for wifi scan, write 0x3b = 0x%02x\n",
5174 FillH2CCmd(padapter, 0x3b, 1, H2C_Parameter);
5177 static void btdm_1AntSetPSMode(struct rtw_adapter *padapter,
5178 u8 enable, u8 smartps, u8 mode)
5180 struct pwrctrl_priv *pwrctrl;
5182 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current LPS(%s, %d), smartps =%d\n", enable == true?"ON":"OFF", mode, smartps));
5184 pwrctrl = &padapter->pwrctrlpriv;
5186 if (enable == true) {
5187 rtw_set_ps_mode23a(padapter, PS_MODE_MIN, smartps, mode);
5189 rtw_set_ps_mode23a(padapter, PS_MODE_ACTIVE, 0, 0);
5190 LPS_RF_ON_check23a(padapter, 100);
5194 static void btdm_1AntTSFSwitch(struct rtw_adapter *padapter, u8 enable)
5198 oldVal = rtl8723au_read8(padapter, 0x550);
5201 newVal = oldVal | EN_BCN_FUNCTION;
5203 newVal = oldVal & ~EN_BCN_FUNCTION;
5205 if (oldVal != newVal)
5206 rtl8723au_write8(padapter, 0x550, newVal);
5209 static u8 btdm_Is1AntPsTdmaStateChange(struct rtw_adapter *padapter)
5211 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5212 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5214 if ((pBtdm8723->bPrePsTdmaOn != pBtdm8723->bCurPsTdmaOn) ||
5215 (pBtdm8723->prePsTdma != pBtdm8723->curPsTdma))
5221 /* Before enter TDMA, make sure Power Saving is enable! */
5224 struct rtw_adapter *padapter,
5229 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5230 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5232 pBtdm8723->bCurPsTdmaOn = bTurnOn;
5233 pBtdm8723->curPsTdma = type;
5236 case 1: /* A2DP Level-1 or FTP/OPP */
5238 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5239 /* wide duration for WiFi */
5240 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x0, 0x58);
5243 case 2: /* A2DP Level-2 */
5244 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5245 /* normal duration for WiFi */
5246 BTDM_SetFw3a(padapter, 0xd3, 0x12, 0x12, 0x0, 0x58);
5249 case 3: /* BT FTP/OPP */
5250 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5251 /* normal duration for WiFi */
5252 BTDM_SetFw3a(padapter, 0xd3, 0x30, 0x03, 0x10, 0x58);
5256 case 4: /* for wifi scan & BT is connected */
5257 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5258 /* protect 3 beacons in 3-beacon period & no Tx pause at BT slot */
5259 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x0);
5262 case 5: /* for WiFi connected-busy & BT is Non-Connected-Idle */
5263 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5264 /* SCO mode, Ant fixed at WiFi, WLAN_Act toggle */
5265 BTDM_SetFw3a(padapter, 0x61, 0x15, 0x03, 0x31, 0x00);
5268 case 9: /* ACL high-retry type - 2 */
5269 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5270 /* narrow duration for WiFi */
5271 BTDM_SetFw3a(padapter, 0xd3, 0xa, 0xa, 0x0, 0x58); /* narrow duration for WiFi */
5274 case 10: /* for WiFi connect idle & BT ACL busy or WiFi Connected-Busy & BT is Inquiry */
5275 if (btdm_Is1AntPsTdmaStateChange(padapter))
5276 BTDM_SetFw3a(padapter, 0x13, 0xa, 0xa, 0x0, 0x40);
5278 case 11: /* ACL high-retry type - 3 */
5279 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5280 /* narrow duration for WiFi */
5281 BTDM_SetFw3a(padapter, 0xd3, 0x05, 0x05, 0x00, 0x58);
5284 case 12: /* for WiFi Connected-Busy & BT is Connected-Idle */
5285 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5286 /* Allow High-Pri BT */
5287 BTDM_SetFw3a(padapter, 0xeb, 0x0a, 0x03, 0x31, 0x18);
5290 case 20: /* WiFi only busy , TDMA mode for power saving */
5291 if (btdm_Is1AntPsTdmaStateChange(padapter))
5292 BTDM_SetFw3a(padapter, 0x13, 0x25, 0x25, 0x00, 0x00);
5294 case 27: /* WiFi DHCP/Site Survey & BT SCO busy */
5295 if (btdm_Is1AntPsTdmaStateChange(padapter))
5296 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x31, 0x98);
5298 case 28: /* WiFi DHCP/Site Survey & BT idle */
5299 if (btdm_Is1AntPsTdmaStateChange(padapter))
5300 BTDM_SetFw3a(padapter, 0x69, 0x25, 0x03, 0x31, 0x00);
5302 case 29: /* WiFi DHCP/Site Survey & BT ACL busy */
5303 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5304 BTDM_SetFw3a(padapter, 0xeb, 0x1a, 0x1a, 0x01, 0x18);
5305 rtl8723au_write32(padapter, 0x6c0, 0x5afa5afa);
5306 rtl8723au_write32(padapter, 0x6c4, 0x5afa5afa);
5309 case 30: /* WiFi idle & BT Inquiry */
5310 if (btdm_Is1AntPsTdmaStateChange(padapter))
5311 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x00);
5313 case 31: /* BT HID */
5314 if (btdm_Is1AntPsTdmaStateChange(padapter))
5315 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x58);
5317 case 32: /* BT SCO & Inquiry */
5318 if (btdm_Is1AntPsTdmaStateChange(padapter))
5319 BTDM_SetFw3a(padapter, 0xab, 0x0a, 0x03, 0x11, 0x98);
5321 case 33: /* BT SCO & WiFi site survey */
5322 if (btdm_Is1AntPsTdmaStateChange(padapter))
5323 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x30, 0x98);
5325 case 34: /* BT HID & WiFi site survey */
5326 if (btdm_Is1AntPsTdmaStateChange(padapter))
5327 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x18);
5329 case 35: /* BT HID & WiFi Connecting */
5330 if (btdm_Is1AntPsTdmaStateChange(padapter))
5331 BTDM_SetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x00, 0x18);
5335 /* disable PS-TDMA */
5338 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5339 /* Antenna control by PTA, 0x870 = 0x310 */
5340 BTDM_SetFw3a(padapter, 0x8, 0x0, 0x0, 0x0, 0x0);
5345 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5346 /* Antenna control by PTA, 0x870 = 0x310 */
5347 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5349 /* Switch Antenna to BT */
5350 rtl8723au_write16(padapter, 0x860, 0x210);
5351 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x210, Switch Antenna to BT\n"));
5354 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5355 /* Antenna control by PTA, 0x870 = 0x310 */
5356 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5358 /* Switch Antenna to WiFi */
5359 rtl8723au_write16(padapter, 0x860, 0x110);
5360 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x110, Switch Antenna to WiFi\n"));
5365 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current TDMA(%s, %d)\n",
5366 pBtdm8723->bCurPsTdmaOn?"ON":"OFF", pBtdm8723->curPsTdma));
5368 /* update pre state */
5369 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
5370 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
5374 _btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn, u8 smartps,
5375 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5377 struct pwrctrl_priv *pwrctrl;
5378 struct hal_data_8723a *pHalData;
5379 struct btdm_8723a_1ant *pBtdm8723;
5383 if (!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) &&
5384 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
5385 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5388 psOption &= ~BIT(0);
5390 RTPRINT(FBT, BT_TRACE,
5391 ("[BTCoex], Set LPS(%s, %d) TDMA(%s, %d)\n",
5392 bPSEn == true?"ON":"OFF", psOption,
5393 bTDMAOn == true?"ON":"OFF", tdmaType));
5395 pwrctrl = &padapter->pwrctrlpriv;
5396 pHalData = GET_HAL_DATA(padapter);
5397 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5400 if (pBtdm8723->bWiFiHalt) {
5401 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Halt!!\n"));
5405 if (pwrctrl->bInSuspend) {
5406 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Suspend!!\n"));
5410 if (padapter->bDriverStopped) {
5411 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi driver stopped!!\n"));
5415 if (padapter->bSurpriseRemoved) {
5416 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi Surprise Removed!!\n"));
5420 psMode = PS_MODE_MIN;
5422 psMode = PS_MODE_ACTIVE;
5426 if (psMode != pwrctrl->pwr_mode) {
5428 } else if (psMode != PS_MODE_ACTIVE) {
5429 if (psOption != pwrctrl->bcn_ant_mode)
5431 else if (smartps != pwrctrl->smart_ps)
5441 if (pBtdm8723->bCurPsTdmaOn) {
5443 btdm_1AntPsTdma(padapter, false, tdmaType);
5445 if (!rtl8723a_BT_enabled(padapter) ||
5446 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_NO_CONNECTION) ||
5447 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_CONNECT_IDLE) ||
5449 btdm_1AntPsTdma(padapter, false, 9);
5451 btdm_1AntPsTdma(padapter, false, 0);
5455 /* change Power Save State */
5456 btdm_1AntSetPSMode(padapter, bPSEn, smartps, psOption);
5459 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5463 btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn,
5464 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5466 _btdm_1AntSetPSTDMA(padapter, bPSEn, 0, psOption, bTDMAOn, tdmaType);
5469 static void btdm_1AntWifiParaAdjust(struct rtw_adapter *padapter, u8 bEnable)
5471 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5472 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5475 pBtdm8723->curWifiPara = 1;
5476 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5477 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_LOW_PENALTY);
5479 pBtdm8723->curWifiPara = 2;
5480 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5481 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_NORMAL);
5486 static void btdm_1AntPtaParaReload(struct rtw_adapter *padapter)
5489 rtl8723au_write8(padapter, 0x6cc, 0x0); /* 1-Ant coex */
5490 rtl8723au_write32(padapter, 0x6c8, 0xffff); /* wifi break table */
5491 rtl8723au_write32(padapter, 0x6c4, 0x55555555); /* coex table */
5493 /* Antenna switch control parameter */
5494 rtl8723au_write32(padapter, 0x858, 0xaaaaaaaa);
5495 if (IS_8723A_A_CUT(GET_HAL_DATA(padapter)->VersionID)) {
5496 /* SPDT(connected with TRSW) control by hardware PTA */
5497 rtl8723au_write32(padapter, 0x870, 0x0);
5498 rtl8723au_write8(padapter, 0x40, 0x24);
5500 rtl8723au_write8(padapter, 0x40, 0x20);
5501 /* set antenna at bt side if ANTSW is software control */
5502 rtl8723au_write16(padapter, 0x860, 0x210);
5503 /* SPDT(connected with TRSW) control by hardware PTA */
5504 rtl8723au_write32(padapter, 0x870, 0x300);
5505 /* ANTSW keep by GNT_BT */
5506 rtl8723au_write32(padapter, 0x874, 0x22804000);
5509 /* coexistence parameters */
5510 rtl8723au_write8(padapter, 0x778, 0x1); /* enable RTK mode PTA */
5512 /* BT don't ignore WLAN_Act */
5513 btdm_SetFwIgnoreWlanAct(padapter, false);
5518 *1: upgrade (add WiFi duration time)
5520 *-1: downgrade (add BT duration time)
5522 static s8 btdm_1AntTdmaJudgement(struct rtw_adapter *padapter, u8 retry)
5524 struct hal_data_8723a *pHalData;
5525 struct btdm_8723a_1ant *pBtdm8723;
5526 static s8 up, dn, m = 1, WaitCount;
5529 pHalData = GET_HAL_DATA(padapter);
5530 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5533 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5543 /* no retry in the last 2-second duration */
5549 /* retry = 0 in consecutive 3m*(2s), add WiFi duration */
5555 } else if (retry <= 3) {
5556 /* retry<= 3 in the last 2-second duration */
5563 /* retry<= 3 in consecutive 2*(2s), minus WiFi duration (add BT duration) */
5566 /* record how many time downgrad WiFi duration */
5571 /* the max number of m is 20 */
5572 /* the longest time of upgrade WiFi duration is 20*3*2s = 120s */
5580 /* retry count > 3 */
5581 /* retry>3, minus WiFi duration (add BT duration) */
5584 /* record how many time downgrad WiFi duration */
5599 static void btdm_1AntTdmaDurationAdjustForACL(struct rtw_adapter *padapter)
5601 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5602 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5604 if (pBtdm8723->psTdmaGlobalCnt != pBtdm8723->psTdmaMonitorCnt) {
5605 pBtdm8723->psTdmaMonitorCnt = 0;
5606 pBtdm8723->psTdmaGlobalCnt = 0;
5608 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5609 btdm_1AntSetPSTDMA(padapter, true, 0, true, 2);
5610 pBtdm8723->psTdmaDuAdjType = 2;
5612 /* Now we only have 4 level Ps Tdma, */
5613 /* if that's not the following 4 level(will changed by wifi scan, dhcp...), */
5614 /* then we have to adjust it back to the previous record one. */
5615 if ((pBtdm8723->curPsTdma != 1) &&
5616 (pBtdm8723->curPsTdma != 2) &&
5617 (pBtdm8723->curPsTdma != 9) &&
5618 (pBtdm8723->curPsTdma != 11)) {
5619 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5623 judge = btdm_1AntTdmaJudgement(padapter, pHalData->bt_coexist.halCoex8723.btRetryCnt);
5625 if (pBtdm8723->curPsTdma == 1) {
5626 /* Decrease WiFi duration for high BT retry */
5627 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5628 pBtdm8723->psTdmaDuAdjType = 9;
5630 pBtdm8723->psTdmaDuAdjType = 2;
5631 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5632 } else if (pBtdm8723->curPsTdma == 2) {
5633 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5634 pBtdm8723->psTdmaDuAdjType = 9;
5635 } else if (pBtdm8723->curPsTdma == 9) {
5636 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5637 pBtdm8723->psTdmaDuAdjType = 11;
5639 } else if (judge == 1) {
5640 if (pBtdm8723->curPsTdma == 11) {
5641 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5642 pBtdm8723->psTdmaDuAdjType = 9;
5643 } else if (pBtdm8723->curPsTdma == 9) {
5644 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5645 pBtdm8723->psTdmaDuAdjType = 9;
5647 pBtdm8723->psTdmaDuAdjType = 2;
5648 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5649 } else if (pBtdm8723->curPsTdma == 2) {
5650 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5651 pBtdm8723->psTdmaDuAdjType = 9;
5653 pBtdm8723->psTdmaDuAdjType = 1;
5654 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5658 RTPRINT(FBT, BT_TRACE,
5659 ("[BTCoex], ACL current TDMA(%s, %d)\n",
5660 (pBtdm8723->bCurPsTdmaOn ? "ON" : "OFF"), pBtdm8723->curPsTdma));
5662 pBtdm8723->psTdmaMonitorCnt++;
5665 static void btdm_1AntCoexProcessForWifiConnect(struct rtw_adapter *padapter)
5667 struct mlme_priv *pmlmepriv;
5668 struct hal_data_8723a *pHalData;
5669 struct bt_coexist_8723a *pBtCoex;
5670 struct btdm_8723a_1ant *pBtdm8723;
5673 pmlmepriv = &padapter->mlmepriv;
5674 pHalData = GET_HAL_DATA(padapter);
5675 pBtCoex = &pHalData->bt_coexist.halCoex8723;
5676 pBtdm8723 = &pBtCoex->btdm1Ant;
5677 BtState = pBtCoex->c2hBtInfo;
5679 RTPRINT(FBT, BT_TRACE, ("[BTCoex], WiFi is %s\n",
5680 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
5681 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is %s\n",
5682 BtStateString[BtState]));
5684 padapter->pwrctrlpriv.btcoex_rfon = false;
5686 if (!BTDM_IsWifiBusy(padapter) &&
5687 !check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) &&
5688 (BtState == BT_INFO_STATE_NO_CONNECTION ||
5689 BtState == BT_INFO_STATE_CONNECT_IDLE)) {
5691 case BT_INFO_STATE_NO_CONNECTION:
5692 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 9);
5694 case BT_INFO_STATE_CONNECT_IDLE:
5695 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 0);
5700 case BT_INFO_STATE_NO_CONNECTION:
5701 case BT_INFO_STATE_CONNECT_IDLE:
5703 btdm_1AntSetPSTDMA(padapter, false, 0, true, 5);
5704 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5705 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5707 case BT_INFO_STATE_ACL_INQ_OR_PAG:
5708 RTPRINT(FBT, BT_TRACE,
5709 ("[BTCoex], BT PROFILE is "
5710 "BT_INFO_STATE_ACL_INQ_OR_PAG\n"));
5711 case BT_INFO_STATE_INQ_OR_PAG:
5712 padapter->pwrctrlpriv.btcoex_rfon = true;
5713 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
5715 case BT_INFO_STATE_SCO_ONLY_BUSY:
5716 case BT_INFO_STATE_ACL_SCO_BUSY:
5717 if (true == pBtCoex->bC2hBtInquiryPage)
5718 btdm_1AntSetPSTDMA(padapter, false, 0,
5721 #ifdef BTCOEX_CMCC_TEST
5722 btdm_1AntSetPSTDMA(padapter, false, 0,
5724 #else /* !BTCOEX_CMCC_TEST */
5725 btdm_1AntSetPSTDMA(padapter, false, 0,
5727 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5728 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5729 #endif /* !BTCOEX_CMCC_TEST */
5732 case BT_INFO_STATE_ACL_ONLY_BUSY:
5733 padapter->pwrctrlpriv.btcoex_rfon = true;
5734 if (pBtCoex->c2hBtProfile == BT_INFO_HID) {
5735 RTPRINT(FBT, BT_TRACE,
5736 ("[BTCoex], BT PROFILE is HID\n"));
5737 btdm_1AntSetPSTDMA(padapter, true, 0, true, 31);
5738 } else if (pBtCoex->c2hBtProfile == BT_INFO_FTP) {
5739 RTPRINT(FBT, BT_TRACE,
5740 ("[BTCoex], BT PROFILE is FTP/OPP\n"));
5741 btdm_1AntSetPSTDMA(padapter, true, 0, true, 3);
5742 } else if (pBtCoex->c2hBtProfile == (BT_INFO_A2DP|BT_INFO_FTP)) {
5743 RTPRINT(FBT, BT_TRACE,
5744 ("[BTCoex], BT PROFILE is A2DP_FTP\n"));
5745 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5747 if (pBtCoex->c2hBtProfile == BT_INFO_A2DP)
5748 RTPRINT(FBT, BT_TRACE,
5749 ("[BTCoex], BT PROFILE is "
5752 RTPRINT(FBT, BT_TRACE,
5753 ("[BTCoex], BT PROFILE is "
5754 "UNKNOWN(0x%02X)! Use A2DP "
5756 pBtCoex->c2hBtProfile));
5757 btdm_1AntTdmaDurationAdjustForACL(padapter);
5763 pBtdm8723->psTdmaGlobalCnt++;
5767 btdm_1AntUpdateHalRAMask(struct rtw_adapter *padapter, u32 mac_id, u32 filter)
5772 u8 shortGIrate = false;
5773 int supportRateNum = 0;
5774 struct sta_info *psta;
5775 struct hal_data_8723a *pHalData;
5776 struct dm_priv *pdmpriv;
5777 struct mlme_ext_priv *pmlmeext;
5778 struct mlme_ext_info *pmlmeinfo;
5779 struct wlan_bssid_ex *cur_network;
5781 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d, filter = 0x%08x!!\n",
5782 __func__, mac_id, filter));
5784 pHalData = GET_HAL_DATA(padapter);
5785 pdmpriv = &pHalData->dmpriv;
5786 pmlmeext = &padapter->mlmeextpriv;
5787 pmlmeinfo = &pmlmeext->mlmext_info;
5788 cur_network = &pmlmeinfo->network;
5790 if (mac_id >= NUM_STA) { /* CAM_SIZE */
5791 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d illegal!!\n",
5796 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
5798 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, Can't find station!!\n",
5806 case 0:/* for infra mode */
5808 rtw_get_rateset_len23a(cur_network->SupportedRates);
5809 mask = update_supported_rate23a(cur_network->SupportedRates,
5811 mask |= (pmlmeinfo->HT_enable) ?
5812 update_MSC_rate23a(&pmlmeinfo->ht_cap):0;
5813 if (support_short_GI23a(padapter, &pmlmeinfo->ht_cap))
5816 case 1:/* for broadcast/multicast */
5817 supportRateNum = rtw_get_rateset_len23a(
5818 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5819 mask = update_basic_rate23a(cur_network->SupportedRates,
5822 default: /* for each sta in IBSS */
5823 supportRateNum = rtw_get_rateset_len23a(
5824 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5825 mask = update_supported_rate23a(cur_network->SupportedRates,
5829 mask |= ((raid<<28)&0xf0000000);
5832 init_rate = get_highest_rate_idx23a(mask)&0x3f;
5834 arg = mac_id&0x1f;/* MACID */
5836 if (true == shortGIrate)
5839 RTPRINT(FBT, BT_TRACE,
5840 ("[BTCoex], Update FW RAID entry, MASK = 0x%08x, "
5841 "arg = 0x%02x\n", mask, arg));
5843 rtl8723a_set_raid_cmd(padapter, mask, arg);
5845 psta->init_rate = init_rate;
5846 pdmpriv->INIDATA_RATE[mac_id] = init_rate;
5850 btdm_1AntUpdateHalRAMaskForSCO(struct rtw_adapter *padapter, u8 forceUpdate)
5852 struct btdm_8723a_1ant *pBtdm8723;
5853 struct sta_priv *pstapriv;
5854 struct wlan_bssid_ex *cur_network;
5855 struct sta_info *psta;
5859 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5861 if (pBtdm8723->bRAChanged == true && forceUpdate == false)
5864 pstapriv = &padapter->stapriv;
5865 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5866 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5867 macid = psta->mac_id;
5869 filter |= BIT(_1M_RATE_);
5870 filter |= BIT(_2M_RATE_);
5871 filter |= BIT(_5M_RATE_);
5872 filter |= BIT(_11M_RATE_);
5873 filter |= BIT(_6M_RATE_);
5874 filter |= BIT(_9M_RATE_);
5876 btdm_1AntUpdateHalRAMask(padapter, macid, filter);
5878 pBtdm8723->bRAChanged = true;
5881 static void btdm_1AntRecoverHalRAMask(struct rtw_adapter *padapter)
5883 struct btdm_8723a_1ant *pBtdm8723;
5884 struct sta_priv *pstapriv;
5885 struct wlan_bssid_ex *cur_network;
5886 struct sta_info *psta;
5888 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5890 if (pBtdm8723->bRAChanged == false)
5893 pstapriv = &padapter->stapriv;
5894 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5895 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5897 Update_RA_Entry23a(padapter, psta);
5899 pBtdm8723->bRAChanged = false;
5903 btdm_1AntBTStateChangeHandler(struct rtw_adapter *padapter,
5904 enum bt_state_1ant oldState,
5905 enum bt_state_1ant newState)
5907 struct hal_data_8723a *phaldata;
5908 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT state change, %s => %s\n",
5909 BtStateString[oldState],
5910 BtStateString[newState]));
5912 /* BT default ignore wlan active, */
5913 /* WiFi MUST disable this when BT is enable */
5914 if (newState > BT_INFO_STATE_DISABLED)
5915 btdm_SetFwIgnoreWlanAct(padapter, false);
5917 if ((check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
5918 (BTDM_IsWifiConnectionExist(padapter))) {
5919 if ((newState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
5920 (newState == BT_INFO_STATE_ACL_SCO_BUSY)) {
5921 btdm_1AntUpdateHalRAMaskForSCO(padapter, false);
5923 /* Recover original RA setting */
5924 btdm_1AntRecoverHalRAMask(padapter);
5927 phaldata = GET_HAL_DATA(padapter);
5928 phaldata->bt_coexist.halCoex8723.btdm1Ant.bRAChanged = false;
5931 if (oldState == newState)
5934 if (oldState == BT_INFO_STATE_ACL_ONLY_BUSY) {
5935 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
5936 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCnt = 0;
5937 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
5940 if ((oldState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
5941 (oldState == BT_INFO_STATE_ACL_SCO_BUSY)) {
5942 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
5943 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
5946 /* Active 2Ant mechanism when BT Connected */
5947 if ((oldState == BT_INFO_STATE_DISABLED) ||
5948 (oldState == BT_INFO_STATE_NO_CONNECTION)) {
5949 if ((newState != BT_INFO_STATE_DISABLED) &&
5950 (newState != BT_INFO_STATE_NO_CONNECTION)) {
5951 BTDM_SetSwRfRxLpfCorner(padapter,
5952 BT_RF_RX_LPF_CORNER_SHRINK);
5953 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
5954 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
5957 if ((newState == BT_INFO_STATE_DISABLED) ||
5958 (newState == BT_INFO_STATE_NO_CONNECTION)) {
5959 BTDM_SetSwRfRxLpfCorner(padapter,
5960 BT_RF_RX_LPF_CORNER_RESUME);
5961 BTDM_AGCTable(padapter, BT_AGCTABLE_OFF);
5962 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_OFF);
5967 static void btdm_1AntBtCoexistHandler(struct rtw_adapter *padapter)
5969 struct hal_data_8723a *pHalData;
5970 struct bt_coexist_8723a *pBtCoex8723;
5971 struct btdm_8723a_1ant *pBtdm8723;
5973 pHalData = GET_HAL_DATA(padapter);
5974 pBtCoex8723 = &pHalData->bt_coexist.halCoex8723;
5975 pBtdm8723 = &pBtCoex8723->btdm1Ant;
5976 padapter->pwrctrlpriv.btcoex_rfon = false;
5977 if (!rtl8723a_BT_enabled(padapter)) {
5978 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is disabled\n"));
5980 if (BTDM_IsWifiConnectionExist(padapter)) {
5981 RTPRINT(FBT, BT_TRACE,
5982 ("[BTCoex], wifi is connected\n"));
5984 if (BTDM_IsWifiBusy(padapter)) {
5985 RTPRINT(FBT, BT_TRACE,
5986 ("[BTCoex], Wifi is busy\n"));
5987 btdm_1AntSetPSTDMA(padapter, false, 0,
5990 RTPRINT(FBT, BT_TRACE,
5991 ("[BTCoex], Wifi is idle\n"));
5992 _btdm_1AntSetPSTDMA(padapter, true, 2, 1,
5996 RTPRINT(FBT, BT_TRACE,
5997 ("[BTCoex], wifi is disconnected\n"));
5999 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6002 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is enabled\n"));
6004 if (BTDM_IsWifiConnectionExist(padapter)) {
6005 RTPRINT(FBT, BT_TRACE,
6006 ("[BTCoex], wifi is connected\n"));
6008 btdm_1AntWifiParaAdjust(padapter, true);
6009 btdm_1AntCoexProcessForWifiConnect(padapter);
6011 RTPRINT(FBT, BT_TRACE,
6012 ("[BTCoex], wifi is disconnected\n"));
6014 /* Antenna switch at BT side(0x870 = 0x300,
6015 0x860 = 0x210) after PSTDMA off */
6016 btdm_1AntWifiParaAdjust(padapter, false);
6017 btdm_1AntSetPSTDMA(padapter, false, 0, false, 0);
6021 btdm_1AntBTStateChangeHandler(padapter, pBtCoex8723->prec2hBtInfo,
6022 pBtCoex8723->c2hBtInfo);
6023 pBtCoex8723->prec2hBtInfo = pBtCoex8723->c2hBtInfo;
6026 void BTDM_1AntSignalCompensation(struct rtw_adapter *padapter,
6027 u8 *rssi_wifi, u8 *rssi_bt)
6029 struct hal_data_8723a *pHalData;
6030 struct btdm_8723a_1ant *pBtdm8723;
6031 u8 RSSI_WiFi_Cmpnstn, RSSI_BT_Cmpnstn;
6033 pHalData = GET_HAL_DATA(padapter);
6034 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
6035 RSSI_WiFi_Cmpnstn = 0;
6036 RSSI_BT_Cmpnstn = 0;
6038 switch (pBtdm8723->curPsTdma) {
6039 case 1: /* WiFi 52ms */
6040 RSSI_WiFi_Cmpnstn = 11; /* 22*0.48 */
6042 case 2: /* WiFi 36ms */
6043 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6045 case 9: /* WiFi 20ms */
6046 RSSI_WiFi_Cmpnstn = 18; /* 22*0.80 */
6048 case 11: /* WiFi 10ms */
6049 RSSI_WiFi_Cmpnstn = 20; /* 22*0.90 */
6051 case 4: /* WiFi 21ms */
6052 RSSI_WiFi_Cmpnstn = 17; /* 22*0.79 */
6054 case 16: /* WiFi 24ms */
6055 RSSI_WiFi_Cmpnstn = 18; /* 22*0.76 */
6057 case 18: /* WiFi 37ms */
6058 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6060 case 23: /* Level-1, Antenna switch to BT at all time */
6061 case 24: /* Level-2, Antenna switch to BT at all time */
6062 case 25: /* Level-3a, Antenna switch to BT at all time */
6063 case 26: /* Level-3b, Antenna switch to BT at all time */
6064 case 27: /* Level-3b, Antenna switch to BT at all time */
6065 case 33: /* BT SCO & WiFi site survey */
6066 RSSI_WiFi_Cmpnstn = 22;
6072 if (rssi_wifi && RSSI_WiFi_Cmpnstn) {
6073 RTPRINT(FBT, BT_TRACE,
6074 ("[BTCoex], 1AntSgnlCmpnstn, case %d, WiFiCmpnstn "
6075 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6076 RSSI_WiFi_Cmpnstn, *rssi_wifi,
6077 *rssi_wifi+RSSI_WiFi_Cmpnstn));
6078 *rssi_wifi += RSSI_WiFi_Cmpnstn;
6081 if (rssi_bt && RSSI_BT_Cmpnstn) {
6082 RTPRINT(FBT, BT_TRACE,
6083 ("[BTCoex], 1AntSgnlCmpnstn, case %d, BTCmpnstn "
6084 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6085 RSSI_BT_Cmpnstn, *rssi_bt, *rssi_bt+RSSI_BT_Cmpnstn));
6086 *rssi_bt += RSSI_BT_Cmpnstn;
6090 static void BTDM_1AntParaInit(struct rtw_adapter *padapter)
6092 struct hal_data_8723a *pHalData;
6093 struct bt_coexist_8723a *pBtCoex;
6094 struct btdm_8723a_1ant *pBtdm8723;
6096 pHalData = GET_HAL_DATA(padapter);
6097 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6098 pBtdm8723 = &pBtCoex->btdm1Ant;
6100 /* Enable counter statistics */
6101 rtl8723au_write8(padapter, 0x76e, 0x4);
6102 btdm_1AntPtaParaReload(padapter);
6104 pBtdm8723->wifiRssiThresh = 48;
6106 pBtdm8723->bWiFiHalt = false;
6107 pBtdm8723->bRAChanged = false;
6109 if ((pBtCoex->c2hBtInfo != BT_INFO_STATE_DISABLED) &&
6110 (pBtCoex->c2hBtInfo != BT_INFO_STATE_NO_CONNECTION)) {
6111 BTDM_SetSwRfRxLpfCorner(padapter, BT_RF_RX_LPF_CORNER_SHRINK);
6112 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6113 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6117 static void BTDM_1AntForHalt(struct rtw_adapter *padapter)
6119 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for halt\n"));
6121 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6124 btdm_1AntWifiParaAdjust(padapter, false);
6126 /* don't use btdm_1AntSetPSTDMA() here */
6127 /* it will call rtw_set_ps_mode23a() and request pwrpriv->lock. */
6128 /* This will lead to deadlock, if this function is called in IPS */
6129 /* Lucas@20130205 */
6130 btdm_1AntPsTdma(padapter, false, 0);
6132 btdm_SetFwIgnoreWlanAct(padapter, true);
6135 static void BTDM_1AntLpsLeave(struct rtw_adapter *padapter)
6137 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for LPS Leave\n"));
6139 /* Prevent from entering LPS again */
6140 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6143 btdm_1AntSetPSTDMA(padapter, false, 0, false, 8);
6144 /*btdm_1AntPsTdma(padapter, false, 8); */
6147 static void BTDM_1AntWifiAssociateNotify(struct rtw_adapter *padapter, u8 type)
6149 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6151 RTPRINT(FBT, BT_TRACE,
6152 ("\n[BTCoex], 1Ant for associate, type =%d\n", type));
6155 rtl8723a_CheckAntenna_Selection(padapter);
6156 if (!rtl8723a_BT_enabled(padapter))
6157 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6159 struct bt_coexist_8723a *pBtCoex;
6162 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6163 BtState = pBtCoex->c2hBtInfo;
6165 btdm_1AntTSFSwitch(padapter, true);
6167 if (BtState == BT_INFO_STATE_NO_CONNECTION ||
6168 BtState == BT_INFO_STATE_CONNECT_IDLE) {
6169 btdm_1AntSetPSTDMA(padapter, false, 0,
6171 } else if (BtState == BT_INFO_STATE_SCO_ONLY_BUSY ||
6172 BtState == BT_INFO_STATE_ACL_SCO_BUSY) {
6173 btdm_1AntSetPSTDMA(padapter, false, 0,
6175 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
6176 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
6177 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY ||
6178 BtState == BT_INFO_STATE_ACL_INQ_OR_PAG) {
6179 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6180 btdm_1AntSetPSTDMA(padapter, false, 0,
6183 btdm_1AntSetPSTDMA(padapter, false, 0,
6188 if (!rtl8723a_BT_enabled(padapter)) {
6189 if (!BTDM_IsWifiConnectionExist(padapter)) {
6190 btdm_1AntPsTdma(padapter, false, 0);
6191 btdm_1AntTSFSwitch(padapter, false);
6195 btdm_1AntBtCoexistHandler(padapter);
6200 BTDM_1AntMediaStatusNotify(struct rtw_adapter *padapter,
6201 enum rt_media_status mstatus)
6203 struct bt_coexist_8723a *pBtCoex;
6205 pBtCoex = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723;
6207 RTPRINT(FBT, BT_TRACE,
6208 ("\n\n[BTCoex]******************************\n"));
6209 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatus, WiFi %s !!\n",
6210 mstatus == RT_MEDIA_CONNECT?"CONNECT":"DISCONNECT"));
6211 RTPRINT(FBT, BT_TRACE, ("[BTCoex]******************************\n"));
6213 if (RT_MEDIA_CONNECT == mstatus) {
6214 if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) {
6215 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_SCO_ONLY_BUSY ||
6216 pBtCoex->c2hBtInfo == BT_INFO_STATE_ACL_SCO_BUSY)
6217 btdm_1AntUpdateHalRAMaskForSCO(padapter, true);
6220 padapter->pwrctrlpriv.DelayLPSLastTimeStamp = jiffies;
6221 BTDM_1AntForDhcp(padapter);
6223 /* DBG_8723A("%s rtl8723a_DeinitAntenna_Selection\n",
6225 rtl8723a_DeinitAntenna_Selection(padapter);
6226 btdm_1AntBtCoexistHandler(padapter);
6227 pBtCoex->btdm1Ant.bRAChanged = false;
6231 void BTDM_1AntForDhcp(struct rtw_adapter *padapter)
6233 struct hal_data_8723a *pHalData;
6235 struct bt_coexist_8723a *pBtCoex;
6236 struct btdm_8723a_1ant *pBtdm8723;
6238 pHalData = GET_HAL_DATA(padapter);
6239 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6240 BtState = pBtCoex->c2hBtInfo;
6241 pBtdm8723 = &pBtCoex->btdm1Ant;
6243 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for DHCP\n"));
6244 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, WiFi is %s\n",
6245 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6246 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, %s\n",
6247 BtStateString[BtState]));
6249 BTDM_1AntWifiAssociateNotify(padapter, true);
6252 static void BTDM_1AntWifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
6254 struct hal_data_8723a *pHalData;
6256 struct bt_coexist_8723a *pBtCoex;
6257 struct btdm_8723a_1ant *pBtdm8723;
6259 pHalData = GET_HAL_DATA(padapter);
6260 BtState = pHalData->bt_coexist.halCoex8723.c2hBtInfo;
6261 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6262 pBtdm8723 = &pBtCoex->btdm1Ant;
6264 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for wifi scan =%d!!\n",
6266 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, WiFi is %s\n",
6267 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6268 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, %s\n",
6269 BtStateString[BtState]));
6272 rtl8723a_CheckAntenna_Selection(padapter);
6273 if (!rtl8723a_BT_enabled(padapter)) {
6274 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6275 } else if (BTDM_IsWifiConnectionExist(padapter) == false) {
6276 BTDM_1AntWifiAssociateNotify(padapter, true);
6278 if ((BtState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6279 (BtState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6280 if (pBtCoex->bC2hBtInquiryPage) {
6281 btdm_1AntSetPSTDMA(padapter, false, 0,
6284 padapter->pwrctrlpriv.btcoex_rfon =
6286 btdm_1AntSetPSTDMA(padapter, true, 0,
6289 } else if (true == pBtCoex->bC2hBtInquiryPage) {
6290 padapter->pwrctrlpriv.btcoex_rfon = true;
6291 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
6292 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY) {
6293 padapter->pwrctrlpriv.btcoex_rfon = true;
6294 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6295 btdm_1AntSetPSTDMA(padapter, true, 0,
6298 btdm_1AntSetPSTDMA(padapter, true, 0,
6301 padapter->pwrctrlpriv.btcoex_rfon = true;
6302 btdm_1AntSetPSTDMA(padapter, true, 0, true, 5);
6306 btdm_NotifyFwScan(padapter, 1);
6308 /* WiFi_Finish_Scan */
6309 btdm_NotifyFwScan(padapter, 0);
6310 btdm_1AntBtCoexistHandler(padapter);
6314 static void BTDM_1AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
6316 struct hal_data_8723a *pHalData;
6317 struct bt_30info *pBTInfo;
6318 struct bt_mgnt *pBtMgnt;
6319 struct bt_coexist_8723a *pBtCoex;
6322 pHalData = GET_HAL_DATA(padapter);
6323 pBTInfo = GET_BT_INFO(padapter);
6324 pBtMgnt = &pBTInfo->BtMgnt;
6325 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6327 u1tmp = pBtCoex->c2hBtInfoOriginal;
6328 /* sco BUSY bit is not used on voice over PCM platform */
6329 btState = u1tmp & 0xF;
6330 pBtCoex->c2hBtProfile = u1tmp & 0xE0;
6332 /* default set bt to idle state. */
6333 pBtMgnt->ExtConfig.bBTBusy = false;
6334 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
6336 /* check BIT2 first ==> check if bt is under inquiry or page scan */
6337 if (btState & BIT(2))
6338 pBtCoex->bC2hBtInquiryPage = true;
6340 pBtCoex->bC2hBtInquiryPage = false;
6343 if (!(btState & BIT(0)))
6344 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
6347 pBtCoex->c2hBtInfo = BT_INFO_STATE_CONNECT_IDLE;
6348 else if (btState == 0x9) {
6349 if (pBtCoex->bC2hBtInquiryPage == true)
6350 pBtCoex->c2hBtInfo =
6351 BT_INFO_STATE_ACL_INQ_OR_PAG;
6353 pBtCoex->c2hBtInfo =
6354 BT_INFO_STATE_ACL_ONLY_BUSY;
6355 pBtMgnt->ExtConfig.bBTBusy = true;
6356 } else if (btState == 0x3) {
6357 pBtCoex->c2hBtInfo = BT_INFO_STATE_SCO_ONLY_BUSY;
6358 pBtMgnt->ExtConfig.bBTBusy = true;
6359 } else if (btState == 0xb) {
6360 pBtCoex->c2hBtInfo = BT_INFO_STATE_ACL_SCO_BUSY;
6361 pBtMgnt->ExtConfig.bBTBusy = true;
6363 pBtCoex->c2hBtInfo = BT_INFO_STATE_MAX;
6364 if (pBtMgnt->ExtConfig.bBTBusy)
6365 pHalData->bt_coexist.CurrentState &=
6366 ~BT_COEX_STATE_BT_IDLE;
6369 if (BT_INFO_STATE_NO_CONNECTION == pBtCoex->c2hBtInfo ||
6370 BT_INFO_STATE_CONNECT_IDLE == pBtCoex->c2hBtInfo) {
6371 if (pBtCoex->bC2hBtInquiryPage)
6372 pBtCoex->c2hBtInfo = BT_INFO_STATE_INQ_OR_PAG;
6375 RTPRINT(FBT, BT_TRACE, ("[BTC2H], %s(%d)\n",
6376 BtStateString[pBtCoex->c2hBtInfo], pBtCoex->c2hBtInfo));
6378 if (pBtCoex->c2hBtProfile != BT_INFO_HID)
6379 pBtCoex->c2hBtProfile &= ~BT_INFO_HID;
6382 void BTDM_1AntBtCoexist8723A(struct rtw_adapter *padapter)
6384 struct mlme_priv *pmlmepriv;
6385 struct hal_data_8723a *pHalData;
6386 unsigned long delta_time;
6388 pmlmepriv = &padapter->mlmepriv;
6389 pHalData = GET_HAL_DATA(padapter);
6391 if (check_fwstate(pmlmepriv, WIFI_SITE_MONITOR)) {
6392 /* already done in BTDM_1AntForScan() */
6393 RTPRINT(FBT, BT_TRACE,
6394 ("[BTCoex], wifi is under scan progress!!\n"));
6398 if (check_fwstate(pmlmepriv, WIFI_UNDER_LINKING)) {
6399 RTPRINT(FBT, BT_TRACE,
6400 ("[BTCoex], wifi is under link progress!!\n"));
6404 /* under DHCP(Special packet) */
6405 delta_time = jiffies - padapter->pwrctrlpriv.DelayLPSLastTimeStamp;
6406 delta_time = jiffies_to_msecs(delta_time);
6407 if (delta_time < 500) {
6408 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is under DHCP "
6409 "progress(%li ms)!!\n", delta_time));
6413 BTDM_CheckWiFiState(padapter);
6415 btdm_1AntBtCoexistHandler(padapter);
6418 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
6420 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
6422 /* local function start with btdm_ */
6423 static u8 btdm_ActionAlgorithm(struct rtw_adapter *padapter)
6425 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
6426 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
6427 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6428 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6429 u8 bScoExist = false, bBtLinkExist = false, bBtHsModeExist = false;
6430 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
6432 if (pBtMgnt->ExtConfig.NumberOfHandle)
6433 bBtLinkExist = true;
6434 if (pBtMgnt->ExtConfig.NumberOfSCO)
6436 if (BT_HsConnectionEstablished(padapter))
6437 bBtHsModeExist = true;
6439 /* here we get BT status first */
6441 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
6443 if ((bScoExist) || (bBtHsModeExist) ||
6444 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID))) {
6445 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO or HID or HS exists, set BT non-idle !!!\n"));
6446 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6449 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6450 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP))) {
6451 if (BTDM_BtTxRxCounterL(padapter) < 100) {
6452 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx < 100, set BT connected-idle!!!\n"));
6453 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6455 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx >= 100, set BT non-idle!!!\n"));
6456 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6460 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6461 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6462 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6463 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6464 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6466 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6467 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6468 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6469 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6470 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6474 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6475 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, set BT non-idle!!!\n"));
6476 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6479 /* Pan+A2dp profile */
6480 if ((pBtMgnt->ExtConfig.NumberOfHandle == 2) &&
6481 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) &&
6482 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6483 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6484 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6485 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6487 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6488 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6489 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6490 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6491 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6495 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6496 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, set BT non-idle!!!\n"));
6497 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6501 if (BT_2ANT_BT_STATUS_IDLE != pBtdm8723->btStatus)
6502 pBtMgnt->ExtConfig.bBTBusy = true;
6504 pBtMgnt->ExtConfig.bBTBusy = false;
6506 if (!bBtLinkExist) {
6507 RTPRINT(FBT, BT_TRACE, ("[BTCoex], No profile exists!!!\n"));
6511 if (pBtMgnt->ExtConfig.NumberOfHandle == 1) {
6513 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
6514 algorithm = BT_2ANT_COEX_ALGO_SCO;
6516 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6517 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID only\n"));
6518 algorithm = BT_2ANT_COEX_ALGO_HID;
6519 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6520 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP only\n"));
6521 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6522 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6523 if (bBtHsModeExist) {
6524 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(HS) only\n"));
6525 algorithm = BT_2ANT_COEX_ALGO_PANHS;
6527 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR) only\n"));
6528 algorithm = BT_2ANT_COEX_ALGO_PANEDR;
6531 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d \n",
6532 pBtMgnt->ExtConfig.NumberOfHandle));
6535 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 2) {
6537 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6538 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
6539 algorithm = BT_2ANT_COEX_ALGO_HID;
6540 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6541 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
6542 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6543 if (bBtHsModeExist) {
6544 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
6545 algorithm = BT_2ANT_COEX_ALGO_SCO;
6547 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
6548 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6551 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched ACL profile for NumberOfHandle =%d\n",
6552 pBtMgnt->ExtConfig.NumberOfHandle));
6555 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6556 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6557 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
6558 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6559 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6560 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6561 if (bBtHsModeExist) {
6562 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
6563 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6565 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
6566 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6568 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6569 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6570 if (bBtHsModeExist) {
6571 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
6572 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6574 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
6575 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
6578 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6579 pBtMgnt->ExtConfig.NumberOfHandle));
6582 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 3) {
6584 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6585 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6586 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP\n"));
6587 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6588 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6589 if (bBtHsModeExist) {
6590 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));
6591 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6593 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));
6594 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6596 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6597 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6598 if (bBtHsModeExist) {
6599 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(HS)\n"));
6600 algorithm = BT_2ANT_COEX_ALGO_SCO;
6602 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(EDR)\n"));
6605 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6606 pBtMgnt->ExtConfig.NumberOfHandle));
6609 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6610 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6611 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6612 if (bBtHsModeExist) {
6613 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
6614 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANHS;
6616 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
6617 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
6620 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6621 pBtMgnt->ExtConfig.NumberOfHandle));
6624 } else if (pBtMgnt->ExtConfig.NumberOfHandle >= 3) {
6626 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6627 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6628 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6630 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
6632 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(EDR)\n"));
6634 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6635 pBtMgnt->ExtConfig.NumberOfHandle));
6638 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6639 pBtMgnt->ExtConfig.NumberOfHandle));
6645 static u8 btdm_NeedToDecBtPwr(struct rtw_adapter *padapter)
6647 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6650 if (BT_Operation(padapter)) {
6651 if (pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB > 47) {
6652 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for HS mode!!\n"));
6655 RTPRINT(FBT, BT_TRACE, ("NO Need to decrease bt power for HS mode!!\n"));
6658 if (BTDM_IsWifiConnectionExist(padapter)) {
6659 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for Wifi is connected!!\n"));
6667 btdm_SetCoexTable(struct rtw_adapter *padapter, u32 val0x6c0,
6668 u32 val0x6c8, u8 val0x6cc)
6670 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c0 = 0x%x\n", val0x6c0));
6671 rtl8723au_write32(padapter, 0x6c0, val0x6c0);
6673 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c8 = 0x%x\n", val0x6c8));
6674 rtl8723au_write32(padapter, 0x6c8, val0x6c8);
6676 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6cc = 0x%x\n", val0x6cc));
6677 rtl8723au_write8(padapter, 0x6cc, val0x6cc);
6681 btdm_SetSwFullTimeDacSwing(struct rtw_adapter *padapter, u8 bSwDacSwingOn,
6684 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6686 if (bSwDacSwingOn) {
6687 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing = 0x%x\n", swDacSwingLvl));
6688 PHY_SetBBReg(padapter, 0x880, 0xff000000, swDacSwingLvl);
6689 pHalData->bt_coexist.bSWCoexistAllOff = false;
6691 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing Off!\n"));
6692 PHY_SetBBReg(padapter, 0x880, 0xff000000, 0xc0);
6697 btdm_SetFwDacSwingLevel(struct rtw_adapter *padapter, u8 dacSwingLvl)
6699 u8 H2C_Parameter[1] = {0};
6701 H2C_Parameter[0] = dacSwingLvl;
6703 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Set Dac Swing Level = 0x%x\n", dacSwingLvl));
6704 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write 0x29 = 0x%x\n", H2C_Parameter[0]));
6706 FillH2CCmd(padapter, 0x29, 1, H2C_Parameter);
6709 static void btdm_2AntDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
6711 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6712 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6714 RTPRINT(FBT, BT_TRACE,
6715 ("[BTCoex], Dec BT power = %s\n",
6716 ((bDecBtPwr) ? "ON" : "OFF")));
6717 pBtdm8723->bCurDecBtPwr = bDecBtPwr;
6719 if (pBtdm8723->bPreDecBtPwr == pBtdm8723->bCurDecBtPwr)
6722 BTDM_SetFwDecBtPwr(padapter, pBtdm8723->bCurDecBtPwr);
6724 pBtdm8723->bPreDecBtPwr = pBtdm8723->bCurDecBtPwr;
6728 btdm_2AntFwDacSwingLvl(struct rtw_adapter *padapter, u8 fwDacSwingLvl)
6730 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6731 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6733 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW Dac Swing level = %d\n", fwDacSwingLvl));
6734 pBtdm8723->curFwDacSwingLvl = fwDacSwingLvl;
6736 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preFwDacSwingLvl =%d, curFwDacSwingLvl =%d\n", */
6737 /*pBtdm8723->preFwDacSwingLvl, pBtdm8723->curFwDacSwingLvl)); */
6739 if (pBtdm8723->preFwDacSwingLvl == pBtdm8723->curFwDacSwingLvl)
6742 btdm_SetFwDacSwingLevel(padapter, pBtdm8723->curFwDacSwingLvl);
6744 pBtdm8723->preFwDacSwingLvl = pBtdm8723->curFwDacSwingLvl;
6748 btdm_2AntRfShrink(struct rtw_adapter *padapter, u8 bRxRfShrinkOn)
6750 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6751 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6753 RTPRINT(FBT, BT_TRACE,
6754 ("[BTCoex], turn Rx RF Shrink = %s\n",
6755 ((bRxRfShrinkOn) ? "ON" : "OFF")));
6756 pBtdm8723->bCurRfRxLpfShrink = bRxRfShrinkOn;
6758 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreRfRxLpfShrink =%d, bCurRfRxLpfShrink =%d\n", */
6759 /*pBtdm8723->bPreRfRxLpfShrink, pBtdm8723->bCurRfRxLpfShrink)); */
6761 if (pBtdm8723->bPreRfRxLpfShrink == pBtdm8723->bCurRfRxLpfShrink)
6764 BTDM_SetSwRfRxLpfCorner(padapter, (u8)pBtdm8723->bCurRfRxLpfShrink);
6766 pBtdm8723->bPreRfRxLpfShrink = pBtdm8723->bCurRfRxLpfShrink;
6770 btdm_2AntLowPenaltyRa(struct rtw_adapter *padapter, u8 bLowPenaltyRa)
6772 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6773 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6775 RTPRINT(FBT, BT_TRACE,
6776 ("[BTCoex], turn LowPenaltyRA = %s\n",
6777 ((bLowPenaltyRa) ? "ON" : "OFF")));
6778 pBtdm8723->bCurLowPenaltyRa = bLowPenaltyRa;
6780 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreLowPenaltyRa =%d, bCurLowPenaltyRa =%d\n", */
6781 /*pBtdm8723->bPreLowPenaltyRa, pBtdm8723->bCurLowPenaltyRa)); */
6783 if (pBtdm8723->bPreLowPenaltyRa == pBtdm8723->bCurLowPenaltyRa)
6786 BTDM_SetSwPenaltyTxRateAdaptive(padapter, (u8)pBtdm8723->bCurLowPenaltyRa);
6788 pBtdm8723->bPreLowPenaltyRa = pBtdm8723->bCurLowPenaltyRa;
6792 btdm_2AntDacSwing(struct rtw_adapter *padapter,
6793 u8 bDacSwingOn, u32 dacSwingLvl)
6795 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6796 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6798 RTPRINT(FBT, BT_TRACE,
6799 ("[BTCoex], turn DacSwing =%s, dacSwingLvl = 0x%x\n",
6800 (bDacSwingOn ? "ON" : "OFF"), dacSwingLvl));
6801 pBtdm8723->bCurDacSwingOn = bDacSwingOn;
6802 pBtdm8723->curDacSwingLvl = dacSwingLvl;
6804 if ((pBtdm8723->bPreDacSwingOn == pBtdm8723->bCurDacSwingOn) &&
6805 (pBtdm8723->preDacSwingLvl == pBtdm8723->curDacSwingLvl))
6809 btdm_SetSwFullTimeDacSwing(padapter, bDacSwingOn, dacSwingLvl);
6811 pBtdm8723->bPreDacSwingOn = pBtdm8723->bCurDacSwingOn;
6812 pBtdm8723->preDacSwingLvl = pBtdm8723->curDacSwingLvl;
6815 static void btdm_2AntAdcBackOff(struct rtw_adapter *padapter, u8 bAdcBackOff)
6817 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6818 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6820 RTPRINT(FBT, BT_TRACE,
6821 ("[BTCoex], turn AdcBackOff = %s\n",
6822 ((bAdcBackOff) ? "ON" : "OFF")));
6823 pBtdm8723->bCurAdcBackOff = bAdcBackOff;
6825 if (pBtdm8723->bPreAdcBackOff == pBtdm8723->bCurAdcBackOff)
6828 BTDM_BBBackOffLevel(padapter, (u8)pBtdm8723->bCurAdcBackOff);
6830 pBtdm8723->bPreAdcBackOff = pBtdm8723->bCurAdcBackOff;
6833 static void btdm_2AntAgcTable(struct rtw_adapter *padapter, u8 bAgcTableEn)
6835 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6836 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6838 RTPRINT(FBT, BT_TRACE,
6839 ("[BTCoex], %s Agc Table\n", ((bAgcTableEn) ? "Enable" : "Disable")));
6840 pBtdm8723->bCurAgcTableEn = bAgcTableEn;
6842 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreAgcTableEn =%d, bCurAgcTableEn =%d\n", */
6843 /*pBtdm8723->bPreAgcTableEn, pBtdm8723->bCurAgcTableEn)); */
6845 if (pBtdm8723->bPreAgcTableEn == pBtdm8723->bCurAgcTableEn)
6848 BTDM_AGCTable(padapter, (u8)bAgcTableEn);
6850 pBtdm8723->bPreAgcTableEn = pBtdm8723->bCurAgcTableEn;
6854 btdm_2AntCoexTable(struct rtw_adapter *padapter,
6855 u32 val0x6c0, u32 val0x6c8, u8 val0x6cc)
6857 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6858 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6860 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write Coex Table 0x6c0 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
6861 val0x6c0, val0x6c8, val0x6cc));
6862 pBtdm8723->curVal0x6c0 = val0x6c0;
6863 pBtdm8723->curVal0x6c8 = val0x6c8;
6864 pBtdm8723->curVal0x6cc = val0x6cc;
6866 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n", */
6867 /*pBtdm8723->preVal0x6c0, pBtdm8723->preVal0x6c8, pBtdm8723->preVal0x6cc)); */
6868 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n", */
6869 /*pBtdm8723->curVal0x6c0, pBtdm8723->curVal0x6c8, pBtdm8723->curVal0x6cc)); */
6871 if ((pBtdm8723->preVal0x6c0 == pBtdm8723->curVal0x6c0) &&
6872 (pBtdm8723->preVal0x6c8 == pBtdm8723->curVal0x6c8) &&
6873 (pBtdm8723->preVal0x6cc == pBtdm8723->curVal0x6cc))
6876 btdm_SetCoexTable(padapter, val0x6c0, val0x6c8, val0x6cc);
6878 pBtdm8723->preVal0x6c0 = pBtdm8723->curVal0x6c0;
6879 pBtdm8723->preVal0x6c8 = pBtdm8723->curVal0x6c8;
6880 pBtdm8723->preVal0x6cc = pBtdm8723->curVal0x6cc;
6883 static void btdm_2AntIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
6885 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6886 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6888 RTPRINT(FBT, BT_TRACE,
6889 ("[BTCoex], turn Ignore WlanAct %s\n", (bEnable ? "ON" : "OFF")));
6890 pBtdm8723->bCurIgnoreWlanAct = bEnable;
6893 if (pBtdm8723->bPreIgnoreWlanAct == pBtdm8723->bCurIgnoreWlanAct)
6896 btdm_SetFwIgnoreWlanAct(padapter, bEnable);
6897 pBtdm8723->bPreIgnoreWlanAct = pBtdm8723->bCurIgnoreWlanAct;
6901 btdm_2AntSetFw3a(struct rtw_adapter *padapter, u8 byte1, u8 byte2,
6902 u8 byte3, u8 byte4, u8 byte5)
6904 u8 H2C_Parameter[5] = {0};
6906 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6908 /* byte1[1:0] != 0 means enable pstdma */
6909 /* for 2Ant bt coexist, if byte1 != 0 means enable pstdma */
6911 pHalData->bt_coexist.bFWCoexistAllOff = false;
6912 H2C_Parameter[0] = byte1;
6913 H2C_Parameter[1] = byte2;
6914 H2C_Parameter[2] = byte3;
6915 H2C_Parameter[3] = byte4;
6916 H2C_Parameter[4] = byte5;
6918 pHalData->bt_coexist.fw3aVal[0] = byte1;
6919 pHalData->bt_coexist.fw3aVal[1] = byte2;
6920 pHalData->bt_coexist.fw3aVal[2] = byte3;
6921 pHalData->bt_coexist.fw3aVal[3] = byte4;
6922 pHalData->bt_coexist.fw3aVal[4] = byte5;
6924 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%x%08x\n",
6926 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
6928 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
6931 static void btdm_2AntPsTdma(struct rtw_adapter *padapter, u8 bTurnOn, u8 type)
6933 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6934 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6936 u8 bTurnOnByCnt = false;
6937 u8 psTdmaTypeByCnt = 0;
6939 btTxRxCnt = BTDM_BtTxRxCounterH(padapter)+BTDM_BtTxRxCounterL(padapter);
6940 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT TxRx Counters = %d\n", btTxRxCnt));
6941 if (btTxRxCnt > 3000) {
6942 bTurnOnByCnt = true;
6943 psTdmaTypeByCnt = 8;
6945 RTPRINT(FBT, BT_TRACE,
6946 ("[BTCoex], For BTTxRxCounters, turn %s PS TDMA, type =%d\n",
6947 (bTurnOnByCnt ? "ON" : "OFF"), psTdmaTypeByCnt));
6948 pBtdm8723->bCurPsTdmaOn = bTurnOnByCnt;
6949 pBtdm8723->curPsTdma = psTdmaTypeByCnt;
6951 RTPRINT(FBT, BT_TRACE,
6952 ("[BTCoex], turn %s PS TDMA, type =%d\n",
6953 (bTurnOn ? "ON" : "OFF"), type));
6954 pBtdm8723->bCurPsTdmaOn = bTurnOn;
6955 pBtdm8723->curPsTdma = type;
6958 if ((pBtdm8723->bPrePsTdmaOn == pBtdm8723->bCurPsTdmaOn) &&
6959 (pBtdm8723->prePsTdma == pBtdm8723->curPsTdma))
6966 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
6969 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
6972 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
6975 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0xa1, 0x80);
6978 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
6981 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
6984 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
6987 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0x20, 0x80);
6990 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
6993 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
6996 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
6999 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7002 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7005 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7008 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7011 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0x20, 0x98);
7014 btdm_2AntSetFw3a(padapter, 0xa3, 0x2f, 0x2f, 0x20, 0x80);
7017 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7020 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0xa1, 0x98);
7023 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0x20, 0x98);
7027 /* disable PS tdma */
7030 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7033 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x0, 0x0);
7036 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7041 /* update pre state */
7042 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
7043 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
7046 static void btdm_2AntBtInquiryPage(struct rtw_adapter *padapter)
7048 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7049 btdm_2AntIgnoreWlanAct(padapter, false);
7050 btdm_2AntPsTdma(padapter, true, 8);
7053 static u8 btdm_HoldForBtInqPage(struct rtw_adapter *padapter)
7055 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7056 u32 curTime = jiffies;
7058 if (pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
7059 /* bt inquiry or page is started. */
7060 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime == 0) {
7061 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = curTime;
7062 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page is started at time : 0x%lx \n",
7063 pHalData->bt_coexist.halCoex8723.btInqPageStartTime));
7066 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page started time : 0x%lx, curTime : 0x%x \n",
7067 pHalData->bt_coexist.halCoex8723.btInqPageStartTime, curTime));
7069 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7070 if (((curTime - pHalData->bt_coexist.halCoex8723.btInqPageStartTime)/1000000) >= 10) {
7071 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page >= 10sec!!!"));
7072 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = 0;
7076 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7077 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7078 btdm_2AntIgnoreWlanAct(padapter, false);
7079 btdm_2AntPsTdma(padapter, true, 8);
7086 static u8 btdm_Is2Ant8723ACommonAction(struct rtw_adapter *padapter)
7088 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7089 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7092 RTPRINT(FBT, BT_TRACE, ("%s :BTDM_IsWifiConnectionExist =%x check_fwstate =%x pmlmepriv->fw_state = 0x%x\n", __func__, BTDM_IsWifiConnectionExist(padapter), check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)), padapter->mlmepriv.fw_state));
7094 if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7095 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7096 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7097 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt idle!!\n"));
7099 btdm_2AntLowPenaltyRa(padapter, false);
7100 btdm_2AntRfShrink(padapter, false);
7101 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7103 btdm_2AntIgnoreWlanAct(padapter, false);
7104 btdm_2AntPsTdma(padapter, false, 0);
7105 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7106 btdm_2AntDecBtPwr(padapter, false);
7108 btdm_2AntAgcTable(padapter, false);
7109 btdm_2AntAdcBackOff(padapter, false);
7110 btdm_2AntDacSwing(padapter, false, 0xc0);
7113 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7114 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7115 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7116 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT idle!!\n"));
7118 btdm_2AntLowPenaltyRa(padapter, true);
7119 btdm_2AntRfShrink(padapter, false);
7120 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7122 btdm_2AntIgnoreWlanAct(padapter, false);
7123 btdm_2AntPsTdma(padapter, false, 0);
7124 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7125 btdm_2AntDecBtPwr(padapter, true);
7127 btdm_2AntAgcTable(padapter, false);
7128 btdm_2AntAdcBackOff(padapter, false);
7129 btdm_2AntDacSwing(padapter, false, 0xc0);
7132 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7133 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7134 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7135 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt connected idle!!\n"));
7137 btdm_2AntLowPenaltyRa(padapter, true);
7138 btdm_2AntRfShrink(padapter, true);
7139 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7141 btdm_2AntIgnoreWlanAct(padapter, false);
7142 btdm_2AntPsTdma(padapter, false, 0);
7143 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7144 btdm_2AntDecBtPwr(padapter, false);
7146 btdm_2AntAgcTable(padapter, false);
7147 btdm_2AntAdcBackOff(padapter, false);
7148 btdm_2AntDacSwing(padapter, false, 0xc0);
7151 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7152 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7153 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7154 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + Bt connected idle!!\n"));
7156 btdm_2AntLowPenaltyRa(padapter, true);
7157 btdm_2AntRfShrink(padapter, true);
7158 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7160 btdm_2AntIgnoreWlanAct(padapter, false);
7161 btdm_2AntPsTdma(padapter, false, 0);
7162 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7163 btdm_2AntDecBtPwr(padapter, true);
7165 btdm_2AntAgcTable(padapter, false);
7166 btdm_2AntAdcBackOff(padapter, false);
7167 btdm_2AntDacSwing(padapter, false, 0xc0);
7170 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7171 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7172 (BT_2ANT_BT_STATUS_NON_IDLE == pBtdm8723->btStatus)) {
7173 RTPRINT(FBT, BT_TRACE, ("Wifi idle + BT non-idle!!\n"));
7175 btdm_2AntLowPenaltyRa(padapter, true);
7176 btdm_2AntRfShrink(padapter, true);
7177 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7179 btdm_2AntIgnoreWlanAct(padapter, false);
7180 btdm_2AntPsTdma(padapter, false, 0);
7181 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7182 btdm_2AntDecBtPwr(padapter, false);
7184 btdm_2AntAgcTable(padapter, false);
7185 btdm_2AntAdcBackOff(padapter, false);
7186 btdm_2AntDacSwing(padapter, false, 0xc0);
7190 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT non-idle!!\n"));
7191 btdm_2AntLowPenaltyRa(padapter, true);
7192 btdm_2AntRfShrink(padapter, true);
7193 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7194 btdm_2AntIgnoreWlanAct(padapter, false);
7195 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7203 btdm_2AntTdmaDurationAdjust(struct rtw_adapter *padapter, u8 bScoHid,
7204 u8 bTxPause, u8 maxInterval)
7206 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7207 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7208 static s32 up, dn, m, n, WaitCount;
7209 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
7212 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));
7214 if (pBtdm8723->bResetTdmaAdjust) {
7215 pBtdm8723->bResetTdmaAdjust = false;
7216 RTPRINT(FBT, BT_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
7219 btdm_2AntPsTdma(padapter, true, 15);
7220 pBtdm8723->psTdmaDuAdjType = 15;
7222 btdm_2AntPsTdma(padapter, true, 11);
7223 pBtdm8723->psTdmaDuAdjType = 11;
7227 btdm_2AntPsTdma(padapter, true, 7);
7228 pBtdm8723->psTdmaDuAdjType = 7;
7230 btdm_2AntPsTdma(padapter, true, 3);
7231 pBtdm8723->psTdmaDuAdjType = 3;
7241 /* accquire the BT TRx retry count from BT_Info byte2 */
7242 retryCount = pHalData->bt_coexist.halCoex8723.btRetryCnt;
7243 RTPRINT(FBT, BT_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));
7247 if (retryCount == 0) { /* no retry in the last 2-second duration */
7254 if (up >= n) { /* if ³sÄò n Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */
7260 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
7262 } else if (retryCount <= 3) { /* <= 3 retry in the last 2-second duration */
7269 if (dn == 2) { /* if ³sÄò 2 Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */
7271 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7275 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7283 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
7285 } else { /* retry count > 3, ¥un1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */
7287 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7291 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7298 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
7301 RTPRINT(FBT, BT_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));
7302 if (maxInterval == 1) {
7304 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7305 if (pBtdm8723->curPsTdma == 1) {
7306 btdm_2AntPsTdma(padapter, true, 5);
7307 pBtdm8723->psTdmaDuAdjType = 5;
7308 } else if (pBtdm8723->curPsTdma == 2) {
7309 btdm_2AntPsTdma(padapter, true, 6);
7310 pBtdm8723->psTdmaDuAdjType = 6;
7311 } else if (pBtdm8723->curPsTdma == 3) {
7312 btdm_2AntPsTdma(padapter, true, 7);
7313 pBtdm8723->psTdmaDuAdjType = 7;
7314 } else if (pBtdm8723->curPsTdma == 4) {
7315 btdm_2AntPsTdma(padapter, true, 8);
7316 pBtdm8723->psTdmaDuAdjType = 8;
7318 if (pBtdm8723->curPsTdma == 9) {
7319 btdm_2AntPsTdma(padapter, true, 13);
7320 pBtdm8723->psTdmaDuAdjType = 13;
7321 } else if (pBtdm8723->curPsTdma == 10) {
7322 btdm_2AntPsTdma(padapter, true, 14);
7323 pBtdm8723->psTdmaDuAdjType = 14;
7324 } else if (pBtdm8723->curPsTdma == 11) {
7325 btdm_2AntPsTdma(padapter, true, 15);
7326 pBtdm8723->psTdmaDuAdjType = 15;
7327 } else if (pBtdm8723->curPsTdma == 12) {
7328 btdm_2AntPsTdma(padapter, true, 16);
7329 pBtdm8723->psTdmaDuAdjType = 16;
7333 if (pBtdm8723->curPsTdma == 5) {
7334 btdm_2AntPsTdma(padapter, true, 6);
7335 pBtdm8723->psTdmaDuAdjType = 6;
7336 } else if (pBtdm8723->curPsTdma == 6) {
7337 btdm_2AntPsTdma(padapter, true, 7);
7338 pBtdm8723->psTdmaDuAdjType = 7;
7339 } else if (pBtdm8723->curPsTdma == 7) {
7340 btdm_2AntPsTdma(padapter, true, 8);
7341 pBtdm8723->psTdmaDuAdjType = 8;
7342 } else if (pBtdm8723->curPsTdma == 13) {
7343 btdm_2AntPsTdma(padapter, true, 14);
7344 pBtdm8723->psTdmaDuAdjType = 14;
7345 } else if (pBtdm8723->curPsTdma == 14) {
7346 btdm_2AntPsTdma(padapter, true, 15);
7347 pBtdm8723->psTdmaDuAdjType = 15;
7348 } else if (pBtdm8723->curPsTdma == 15) {
7349 btdm_2AntPsTdma(padapter, true, 16);
7350 pBtdm8723->psTdmaDuAdjType = 16;
7352 } else if (result == 1) {
7353 if (pBtdm8723->curPsTdma == 8) {
7354 btdm_2AntPsTdma(padapter, true, 7);
7355 pBtdm8723->psTdmaDuAdjType = 7;
7356 } else if (pBtdm8723->curPsTdma == 7) {
7357 btdm_2AntPsTdma(padapter, true, 6);
7358 pBtdm8723->psTdmaDuAdjType = 6;
7359 } else if (pBtdm8723->curPsTdma == 6) {
7360 btdm_2AntPsTdma(padapter, true, 5);
7361 pBtdm8723->psTdmaDuAdjType = 5;
7362 } else if (pBtdm8723->curPsTdma == 16) {
7363 btdm_2AntPsTdma(padapter, true, 15);
7364 pBtdm8723->psTdmaDuAdjType = 15;
7365 } else if (pBtdm8723->curPsTdma == 15) {
7366 btdm_2AntPsTdma(padapter, true, 14);
7367 pBtdm8723->psTdmaDuAdjType = 14;
7368 } else if (pBtdm8723->curPsTdma == 14) {
7369 btdm_2AntPsTdma(padapter, true, 13);
7370 pBtdm8723->psTdmaDuAdjType = 13;
7374 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7375 if (pBtdm8723->curPsTdma == 5) {
7376 btdm_2AntPsTdma(padapter, true, 1);
7377 pBtdm8723->psTdmaDuAdjType = 1;
7378 } else if (pBtdm8723->curPsTdma == 6) {
7379 btdm_2AntPsTdma(padapter, true, 2);
7380 pBtdm8723->psTdmaDuAdjType = 2;
7381 } else if (pBtdm8723->curPsTdma == 7) {
7382 btdm_2AntPsTdma(padapter, true, 3);
7383 pBtdm8723->psTdmaDuAdjType = 3;
7384 } else if (pBtdm8723->curPsTdma == 8) {
7385 btdm_2AntPsTdma(padapter, true, 4);
7386 pBtdm8723->psTdmaDuAdjType = 4;
7388 if (pBtdm8723->curPsTdma == 13) {
7389 btdm_2AntPsTdma(padapter, true, 9);
7390 pBtdm8723->psTdmaDuAdjType = 9;
7391 } else if (pBtdm8723->curPsTdma == 14) {
7392 btdm_2AntPsTdma(padapter, true, 10);
7393 pBtdm8723->psTdmaDuAdjType = 10;
7394 } else if (pBtdm8723->curPsTdma == 15) {
7395 btdm_2AntPsTdma(padapter, true, 11);
7396 pBtdm8723->psTdmaDuAdjType = 11;
7397 } else if (pBtdm8723->curPsTdma == 16) {
7398 btdm_2AntPsTdma(padapter, true, 12);
7399 pBtdm8723->psTdmaDuAdjType = 12;
7403 if (pBtdm8723->curPsTdma == 1) {
7404 btdm_2AntPsTdma(padapter, true, 2);
7405 pBtdm8723->psTdmaDuAdjType = 2;
7406 } else if (pBtdm8723->curPsTdma == 2) {
7407 btdm_2AntPsTdma(padapter, true, 3);
7408 pBtdm8723->psTdmaDuAdjType = 3;
7409 } else if (pBtdm8723->curPsTdma == 3) {
7410 btdm_2AntPsTdma(padapter, true, 4);
7411 pBtdm8723->psTdmaDuAdjType = 4;
7412 } else if (pBtdm8723->curPsTdma == 9) {
7413 btdm_2AntPsTdma(padapter, true, 10);
7414 pBtdm8723->psTdmaDuAdjType = 10;
7415 } else if (pBtdm8723->curPsTdma == 10) {
7416 btdm_2AntPsTdma(padapter, true, 11);
7417 pBtdm8723->psTdmaDuAdjType = 11;
7418 } else if (pBtdm8723->curPsTdma == 11) {
7419 btdm_2AntPsTdma(padapter, true, 12);
7420 pBtdm8723->psTdmaDuAdjType = 12;
7422 } else if (result == 1) {
7423 if (pBtdm8723->curPsTdma == 4) {
7424 btdm_2AntPsTdma(padapter, true, 3);
7425 pBtdm8723->psTdmaDuAdjType = 3;
7426 } else if (pBtdm8723->curPsTdma == 3) {
7427 btdm_2AntPsTdma(padapter, true, 2);
7428 pBtdm8723->psTdmaDuAdjType = 2;
7429 } else if (pBtdm8723->curPsTdma == 2) {
7430 btdm_2AntPsTdma(padapter, true, 1);
7431 pBtdm8723->psTdmaDuAdjType = 1;
7432 } else if (pBtdm8723->curPsTdma == 12) {
7433 btdm_2AntPsTdma(padapter, true, 11);
7434 pBtdm8723->psTdmaDuAdjType = 11;
7435 } else if (pBtdm8723->curPsTdma == 11) {
7436 btdm_2AntPsTdma(padapter, true, 10);
7437 pBtdm8723->psTdmaDuAdjType = 10;
7438 } else if (pBtdm8723->curPsTdma == 10) {
7439 btdm_2AntPsTdma(padapter, true, 9);
7440 pBtdm8723->psTdmaDuAdjType = 9;
7444 } else if (maxInterval == 2) {
7446 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7447 if (pBtdm8723->curPsTdma == 1) {
7448 btdm_2AntPsTdma(padapter, true, 6);
7449 pBtdm8723->psTdmaDuAdjType = 6;
7450 } else if (pBtdm8723->curPsTdma == 2) {
7451 btdm_2AntPsTdma(padapter, true, 6);
7452 pBtdm8723->psTdmaDuAdjType = 6;
7453 } else if (pBtdm8723->curPsTdma == 3) {
7454 btdm_2AntPsTdma(padapter, true, 7);
7455 pBtdm8723->psTdmaDuAdjType = 7;
7456 } else if (pBtdm8723->curPsTdma == 4) {
7457 btdm_2AntPsTdma(padapter, true, 8);
7458 pBtdm8723->psTdmaDuAdjType = 8;
7460 if (pBtdm8723->curPsTdma == 9) {
7461 btdm_2AntPsTdma(padapter, true, 14);
7462 pBtdm8723->psTdmaDuAdjType = 14;
7463 } else if (pBtdm8723->curPsTdma == 10) {
7464 btdm_2AntPsTdma(padapter, true, 14);
7465 pBtdm8723->psTdmaDuAdjType = 14;
7466 } else if (pBtdm8723->curPsTdma == 11) {
7467 btdm_2AntPsTdma(padapter, true, 15);
7468 pBtdm8723->psTdmaDuAdjType = 15;
7469 } else if (pBtdm8723->curPsTdma == 12) {
7470 btdm_2AntPsTdma(padapter, true, 16);
7471 pBtdm8723->psTdmaDuAdjType = 16;
7474 if (pBtdm8723->curPsTdma == 5) {
7475 btdm_2AntPsTdma(padapter, true, 6);
7476 pBtdm8723->psTdmaDuAdjType = 6;
7477 } else if (pBtdm8723->curPsTdma == 6) {
7478 btdm_2AntPsTdma(padapter, true, 7);
7479 pBtdm8723->psTdmaDuAdjType = 7;
7480 } else if (pBtdm8723->curPsTdma == 7) {
7481 btdm_2AntPsTdma(padapter, true, 8);
7482 pBtdm8723->psTdmaDuAdjType = 8;
7483 } else if (pBtdm8723->curPsTdma == 13) {
7484 btdm_2AntPsTdma(padapter, true, 14);
7485 pBtdm8723->psTdmaDuAdjType = 14;
7486 } else if (pBtdm8723->curPsTdma == 14) {
7487 btdm_2AntPsTdma(padapter, true, 15);
7488 pBtdm8723->psTdmaDuAdjType = 15;
7489 } else if (pBtdm8723->curPsTdma == 15) {
7490 btdm_2AntPsTdma(padapter, true, 16);
7491 pBtdm8723->psTdmaDuAdjType = 16;
7493 } else if (result == 1) {
7494 if (pBtdm8723->curPsTdma == 8) {
7495 btdm_2AntPsTdma(padapter, true, 7);
7496 pBtdm8723->psTdmaDuAdjType = 7;
7497 } else if (pBtdm8723->curPsTdma == 7) {
7498 btdm_2AntPsTdma(padapter, true, 6);
7499 pBtdm8723->psTdmaDuAdjType = 6;
7500 } else if (pBtdm8723->curPsTdma == 6) {
7501 btdm_2AntPsTdma(padapter, true, 6);
7502 pBtdm8723->psTdmaDuAdjType = 6;
7503 } else if (pBtdm8723->curPsTdma == 16) {
7504 btdm_2AntPsTdma(padapter, true, 15);
7505 pBtdm8723->psTdmaDuAdjType = 15;
7506 } else if (pBtdm8723->curPsTdma == 15) {
7507 btdm_2AntPsTdma(padapter, true, 14);
7508 pBtdm8723->psTdmaDuAdjType = 14;
7509 } else if (pBtdm8723->curPsTdma == 14) {
7510 btdm_2AntPsTdma(padapter, true, 14);
7511 pBtdm8723->psTdmaDuAdjType = 14;
7515 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7516 if (pBtdm8723->curPsTdma == 5) {
7517 btdm_2AntPsTdma(padapter, true, 2);
7518 pBtdm8723->psTdmaDuAdjType = 2;
7519 } else if (pBtdm8723->curPsTdma == 6) {
7520 btdm_2AntPsTdma(padapter, true, 2);
7521 pBtdm8723->psTdmaDuAdjType = 2;
7522 } else if (pBtdm8723->curPsTdma == 7) {
7523 btdm_2AntPsTdma(padapter, true, 3);
7524 pBtdm8723->psTdmaDuAdjType = 3;
7525 } else if (pBtdm8723->curPsTdma == 8) {
7526 btdm_2AntPsTdma(padapter, true, 4);
7527 pBtdm8723->psTdmaDuAdjType = 4;
7529 if (pBtdm8723->curPsTdma == 13) {
7530 btdm_2AntPsTdma(padapter, true, 10);
7531 pBtdm8723->psTdmaDuAdjType = 10;
7532 } else if (pBtdm8723->curPsTdma == 14) {
7533 btdm_2AntPsTdma(padapter, true, 10);
7534 pBtdm8723->psTdmaDuAdjType = 10;
7535 } else if (pBtdm8723->curPsTdma == 15) {
7536 btdm_2AntPsTdma(padapter, true, 11);
7537 pBtdm8723->psTdmaDuAdjType = 11;
7538 } else if (pBtdm8723->curPsTdma == 16) {
7539 btdm_2AntPsTdma(padapter, true, 12);
7540 pBtdm8723->psTdmaDuAdjType = 12;
7543 if (pBtdm8723->curPsTdma == 1) {
7544 btdm_2AntPsTdma(padapter, true, 2);
7545 pBtdm8723->psTdmaDuAdjType = 2;
7546 } else if (pBtdm8723->curPsTdma == 2) {
7547 btdm_2AntPsTdma(padapter, true, 3);
7548 pBtdm8723->psTdmaDuAdjType = 3;
7549 } else if (pBtdm8723->curPsTdma == 3) {
7550 btdm_2AntPsTdma(padapter, true, 4);
7551 pBtdm8723->psTdmaDuAdjType = 4;
7552 } else if (pBtdm8723->curPsTdma == 9) {
7553 btdm_2AntPsTdma(padapter, true, 10);
7554 pBtdm8723->psTdmaDuAdjType = 10;
7555 } else if (pBtdm8723->curPsTdma == 10) {
7556 btdm_2AntPsTdma(padapter, true, 11);
7557 pBtdm8723->psTdmaDuAdjType = 11;
7558 } else if (pBtdm8723->curPsTdma == 11) {
7559 btdm_2AntPsTdma(padapter, true, 12);
7560 pBtdm8723->psTdmaDuAdjType = 12;
7562 } else if (result == 1) {
7563 if (pBtdm8723->curPsTdma == 4) {
7564 btdm_2AntPsTdma(padapter, true, 3);
7565 pBtdm8723->psTdmaDuAdjType = 3;
7566 } else if (pBtdm8723->curPsTdma == 3) {
7567 btdm_2AntPsTdma(padapter, true, 2);
7568 pBtdm8723->psTdmaDuAdjType = 2;
7569 } else if (pBtdm8723->curPsTdma == 2) {
7570 btdm_2AntPsTdma(padapter, true, 2);
7571 pBtdm8723->psTdmaDuAdjType = 2;
7572 } else if (pBtdm8723->curPsTdma == 12) {
7573 btdm_2AntPsTdma(padapter, true, 11);
7574 pBtdm8723->psTdmaDuAdjType = 11;
7575 } else if (pBtdm8723->curPsTdma == 11) {
7576 btdm_2AntPsTdma(padapter, true, 10);
7577 pBtdm8723->psTdmaDuAdjType = 10;
7578 } else if (pBtdm8723->curPsTdma == 10) {
7579 btdm_2AntPsTdma(padapter, true, 10);
7580 pBtdm8723->psTdmaDuAdjType = 10;
7584 } else if (maxInterval == 3) {
7586 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7587 if (pBtdm8723->curPsTdma == 1) {
7588 btdm_2AntPsTdma(padapter, true, 7);
7589 pBtdm8723->psTdmaDuAdjType = 7;
7590 } else if (pBtdm8723->curPsTdma == 2) {
7591 btdm_2AntPsTdma(padapter, true, 7);
7592 pBtdm8723->psTdmaDuAdjType = 7;
7593 } else if (pBtdm8723->curPsTdma == 3) {
7594 btdm_2AntPsTdma(padapter, true, 7);
7595 pBtdm8723->psTdmaDuAdjType = 7;
7596 } else if (pBtdm8723->curPsTdma == 4) {
7597 btdm_2AntPsTdma(padapter, true, 8);
7598 pBtdm8723->psTdmaDuAdjType = 8;
7600 if (pBtdm8723->curPsTdma == 9) {
7601 btdm_2AntPsTdma(padapter, true, 15);
7602 pBtdm8723->psTdmaDuAdjType = 15;
7603 } else if (pBtdm8723->curPsTdma == 10) {
7604 btdm_2AntPsTdma(padapter, true, 15);
7605 pBtdm8723->psTdmaDuAdjType = 15;
7606 } else if (pBtdm8723->curPsTdma == 11) {
7607 btdm_2AntPsTdma(padapter, true, 15);
7608 pBtdm8723->psTdmaDuAdjType = 15;
7609 } else if (pBtdm8723->curPsTdma == 12) {
7610 btdm_2AntPsTdma(padapter, true, 16);
7611 pBtdm8723->psTdmaDuAdjType = 16;
7614 if (pBtdm8723->curPsTdma == 5) {
7615 btdm_2AntPsTdma(padapter, true, 7);
7616 pBtdm8723->psTdmaDuAdjType = 7;
7617 } else if (pBtdm8723->curPsTdma == 6) {
7618 btdm_2AntPsTdma(padapter, true, 7);
7619 pBtdm8723->psTdmaDuAdjType = 7;
7620 } else if (pBtdm8723->curPsTdma == 7) {
7621 btdm_2AntPsTdma(padapter, true, 8);
7622 pBtdm8723->psTdmaDuAdjType = 8;
7623 } else if (pBtdm8723->curPsTdma == 13) {
7624 btdm_2AntPsTdma(padapter, true, 15);
7625 pBtdm8723->psTdmaDuAdjType = 15;
7626 } else if (pBtdm8723->curPsTdma == 14) {
7627 btdm_2AntPsTdma(padapter, true, 15);
7628 pBtdm8723->psTdmaDuAdjType = 15;
7629 } else if (pBtdm8723->curPsTdma == 15) {
7630 btdm_2AntPsTdma(padapter, true, 16);
7631 pBtdm8723->psTdmaDuAdjType = 16;
7633 } else if (result == 1) {
7634 if (pBtdm8723->curPsTdma == 8) {
7635 btdm_2AntPsTdma(padapter, true, 7);
7636 pBtdm8723->psTdmaDuAdjType = 7;
7637 } else if (pBtdm8723->curPsTdma == 7) {
7638 btdm_2AntPsTdma(padapter, true, 7);
7639 pBtdm8723->psTdmaDuAdjType = 7;
7640 } else if (pBtdm8723->curPsTdma == 6) {
7641 btdm_2AntPsTdma(padapter, true, 7);
7642 pBtdm8723->psTdmaDuAdjType = 7;
7643 } else if (pBtdm8723->curPsTdma == 16) {
7644 btdm_2AntPsTdma(padapter, true, 15);
7645 pBtdm8723->psTdmaDuAdjType = 15;
7646 } else if (pBtdm8723->curPsTdma == 15) {
7647 btdm_2AntPsTdma(padapter, true, 15);
7648 pBtdm8723->psTdmaDuAdjType = 15;
7649 } else if (pBtdm8723->curPsTdma == 14) {
7650 btdm_2AntPsTdma(padapter, true, 15);
7651 pBtdm8723->psTdmaDuAdjType = 15;
7655 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7656 if (pBtdm8723->curPsTdma == 5) {
7657 btdm_2AntPsTdma(padapter, true, 3);
7658 pBtdm8723->psTdmaDuAdjType = 3;
7659 } else if (pBtdm8723->curPsTdma == 6) {
7660 btdm_2AntPsTdma(padapter, true, 3);
7661 pBtdm8723->psTdmaDuAdjType = 3;
7662 } else if (pBtdm8723->curPsTdma == 7) {
7663 btdm_2AntPsTdma(padapter, true, 3);
7664 pBtdm8723->psTdmaDuAdjType = 3;
7665 } else if (pBtdm8723->curPsTdma == 8) {
7666 btdm_2AntPsTdma(padapter, true, 4);
7667 pBtdm8723->psTdmaDuAdjType = 4;
7669 if (pBtdm8723->curPsTdma == 13) {
7670 btdm_2AntPsTdma(padapter, true, 11);
7671 pBtdm8723->psTdmaDuAdjType = 11;
7672 } else if (pBtdm8723->curPsTdma == 14) {
7673 btdm_2AntPsTdma(padapter, true, 11);
7674 pBtdm8723->psTdmaDuAdjType = 11;
7675 } else if (pBtdm8723->curPsTdma == 15) {
7676 btdm_2AntPsTdma(padapter, true, 11);
7677 pBtdm8723->psTdmaDuAdjType = 11;
7678 } else if (pBtdm8723->curPsTdma == 16) {
7679 btdm_2AntPsTdma(padapter, true, 12);
7680 pBtdm8723->psTdmaDuAdjType = 12;
7683 if (pBtdm8723->curPsTdma == 1) {
7684 btdm_2AntPsTdma(padapter, true, 3);
7685 pBtdm8723->psTdmaDuAdjType = 3;
7686 } else if (pBtdm8723->curPsTdma == 2) {
7687 btdm_2AntPsTdma(padapter, true, 3);
7688 pBtdm8723->psTdmaDuAdjType = 3;
7689 } else if (pBtdm8723->curPsTdma == 3) {
7690 btdm_2AntPsTdma(padapter, true, 4);
7691 pBtdm8723->psTdmaDuAdjType = 4;
7692 } else if (pBtdm8723->curPsTdma == 9) {
7693 btdm_2AntPsTdma(padapter, true, 11);
7694 pBtdm8723->psTdmaDuAdjType = 11;
7695 } else if (pBtdm8723->curPsTdma == 10) {
7696 btdm_2AntPsTdma(padapter, true, 11);
7697 pBtdm8723->psTdmaDuAdjType = 11;
7698 } else if (pBtdm8723->curPsTdma == 11) {
7699 btdm_2AntPsTdma(padapter, true, 12);
7700 pBtdm8723->psTdmaDuAdjType = 12;
7702 } else if (result == 1) {
7703 if (pBtdm8723->curPsTdma == 4) {
7704 btdm_2AntPsTdma(padapter, true, 3);
7705 pBtdm8723->psTdmaDuAdjType = 3;
7706 } else if (pBtdm8723->curPsTdma == 3) {
7707 btdm_2AntPsTdma(padapter, true, 3);
7708 pBtdm8723->psTdmaDuAdjType = 3;
7709 } else if (pBtdm8723->curPsTdma == 2) {
7710 btdm_2AntPsTdma(padapter, true, 3);
7711 pBtdm8723->psTdmaDuAdjType = 3;
7712 } else if (pBtdm8723->curPsTdma == 12) {
7713 btdm_2AntPsTdma(padapter, true, 11);
7714 pBtdm8723->psTdmaDuAdjType = 11;
7715 } else if (pBtdm8723->curPsTdma == 11) {
7716 btdm_2AntPsTdma(padapter, true, 11);
7717 pBtdm8723->psTdmaDuAdjType = 11;
7718 } else if (pBtdm8723->curPsTdma == 10) {
7719 btdm_2AntPsTdma(padapter, true, 11);
7720 pBtdm8723->psTdmaDuAdjType = 11;
7726 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type : recordPsTdma =%d\n", pBtdm8723->psTdmaDuAdjType));
7727 /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
7728 /* then we have to adjust it back to the previous record one. */
7729 if (pBtdm8723->curPsTdma != pBtdm8723->psTdmaDuAdjType) {
7730 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma =%d, recordPsTdma =%d\n",
7731 pBtdm8723->curPsTdma, pBtdm8723->psTdmaDuAdjType));
7733 if (!check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
7734 btdm_2AntPsTdma(padapter, true, pBtdm8723->psTdmaDuAdjType);
7736 RTPRINT(FBT, BT_TRACE, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
7740 /* default Action */
7741 /* SCO only or SCO+PAN(HS) */
7742 static void btdm_2Ant8723ASCOAction(struct rtw_adapter *padapter)
7744 u8 btRssiState, btRssiState1;
7746 if (btdm_NeedToDecBtPwr(padapter))
7747 btdm_2AntDecBtPwr(padapter, true);
7749 btdm_2AntDecBtPwr(padapter, false);
7751 if (BTDM_IsHT40(padapter)) {
7752 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7753 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7755 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7756 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7757 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7758 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7759 btdm_2AntPsTdma(padapter, true, 11);
7761 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7762 btdm_2AntPsTdma(padapter, true, 15);
7766 btdm_2AntAgcTable(padapter, false);
7767 btdm_2AntAdcBackOff(padapter, true);
7768 btdm_2AntDacSwing(padapter, false, 0xc0);
7770 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7771 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7772 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7775 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7776 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7777 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7778 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7779 btdm_2AntPsTdma(padapter, true, 11);
7781 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7782 btdm_2AntPsTdma(padapter, true, 15);
7786 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7787 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7788 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7789 btdm_2AntAgcTable(padapter, true);
7790 btdm_2AntAdcBackOff(padapter, true);
7791 btdm_2AntDacSwing(padapter, false, 0xc0);
7793 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7794 btdm_2AntAgcTable(padapter, false);
7795 btdm_2AntAdcBackOff(padapter, false);
7796 btdm_2AntDacSwing(padapter, false, 0xc0);
7801 static void btdm_2Ant8723AHIDAction(struct rtw_adapter *padapter)
7803 u8 btRssiState, btRssiState1;
7805 if (btdm_NeedToDecBtPwr(padapter))
7806 btdm_2AntDecBtPwr(padapter, true);
7808 btdm_2AntDecBtPwr(padapter, false);
7810 if (BTDM_IsHT40(padapter)) {
7811 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7812 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7814 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7815 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7816 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7817 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7818 btdm_2AntPsTdma(padapter, true, 9);
7820 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7821 btdm_2AntPsTdma(padapter, true, 13);
7825 btdm_2AntAgcTable(padapter, false);
7826 btdm_2AntAdcBackOff(padapter, false);
7827 btdm_2AntDacSwing(padapter, false, 0xc0);
7829 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7830 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7831 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7834 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7835 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7836 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7837 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7838 btdm_2AntPsTdma(padapter, true, 9);
7840 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7841 btdm_2AntPsTdma(padapter, true, 13);
7845 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7846 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7847 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7848 btdm_2AntAgcTable(padapter, true);
7849 btdm_2AntAdcBackOff(padapter, true);
7850 btdm_2AntDacSwing(padapter, false, 0xc0);
7852 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7853 btdm_2AntAgcTable(padapter, false);
7854 btdm_2AntAdcBackOff(padapter, false);
7855 btdm_2AntDacSwing(padapter, false, 0xc0);
7860 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
7861 static void btdm_2Ant8723AA2DPAction(struct rtw_adapter *padapter)
7863 u8 btRssiState, btRssiState1;
7864 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7865 u8 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
7867 if (btdm_NeedToDecBtPwr(padapter))
7868 btdm_2AntDecBtPwr(padapter, true);
7870 btdm_2AntDecBtPwr(padapter, false);
7872 if (BTDM_IsHT40(padapter)) {
7873 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7874 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7877 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7878 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7879 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7880 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7882 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7883 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7884 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
7886 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7887 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
7890 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7891 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7892 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7893 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
7895 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7896 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
7901 btdm_2AntAgcTable(padapter, false);
7902 btdm_2AntAdcBackOff(padapter, true);
7903 btdm_2AntDacSwing(padapter, false, 0xc0);
7905 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7906 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7907 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7910 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7911 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7912 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7913 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7914 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7915 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7916 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
7918 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7919 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
7922 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7923 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7924 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7925 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
7927 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7928 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
7933 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7934 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7935 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7936 btdm_2AntAgcTable(padapter, true);
7937 btdm_2AntAdcBackOff(padapter, true);
7938 btdm_2AntDacSwing(padapter, false, 0xc0);
7940 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7941 btdm_2AntAgcTable(padapter, false);
7942 btdm_2AntAdcBackOff(padapter, false);
7943 btdm_2AntDacSwing(padapter, false, 0xc0);
7948 static void btdm_2Ant8723APANEDRAction(struct rtw_adapter *padapter)
7950 u8 btRssiState, btRssiState1;
7952 if (btdm_NeedToDecBtPwr(padapter))
7953 btdm_2AntDecBtPwr(padapter, true);
7955 btdm_2AntDecBtPwr(padapter, false);
7957 if (BTDM_IsHT40(padapter)) {
7958 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7959 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7962 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7963 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7964 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7965 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7966 btdm_2AntPsTdma(padapter, true, 2);
7968 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7969 btdm_2AntPsTdma(padapter, true, 6);
7973 btdm_2AntAgcTable(padapter, false);
7974 btdm_2AntAdcBackOff(padapter, true);
7975 btdm_2AntDacSwing(padapter, false, 0xc0);
7977 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7978 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7979 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7982 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7983 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7984 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7985 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7986 btdm_2AntPsTdma(padapter, true, 2);
7988 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7989 btdm_2AntPsTdma(padapter, true, 6);
7993 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7994 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7995 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7996 btdm_2AntAgcTable(padapter, true);
7997 btdm_2AntAdcBackOff(padapter, true);
7998 btdm_2AntDacSwing(padapter, false, 0xc0);
8000 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8001 btdm_2AntAgcTable(padapter, false);
8002 btdm_2AntAdcBackOff(padapter, false);
8003 btdm_2AntDacSwing(padapter, false, 0xc0);
8009 static void btdm_2Ant8723APANHSAction(struct rtw_adapter *padapter)
8013 if (BTDM_IsHT40(padapter)) {
8014 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8015 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8017 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8018 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8019 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8020 btdm_2AntDecBtPwr(padapter, true);
8022 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8023 btdm_2AntDecBtPwr(padapter, false);
8025 btdm_2AntPsTdma(padapter, false, 0);
8028 btdm_2AntAgcTable(padapter, false);
8029 btdm_2AntAdcBackOff(padapter, true);
8030 btdm_2AntDacSwing(padapter, false, 0xc0);
8032 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8033 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8035 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8036 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8037 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high\n"));
8039 btdm_2AntDecBtPwr(padapter, true);
8040 btdm_2AntPsTdma(padapter, false, 0);
8043 btdm_2AntAgcTable(padapter, true);
8044 btdm_2AntAdcBackOff(padapter, true);
8045 btdm_2AntDacSwing(padapter, false, 0xc0);
8047 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low\n"));
8049 btdm_2AntDecBtPwr(padapter, false);
8050 btdm_2AntPsTdma(padapter, false, 0);
8053 btdm_2AntAgcTable(padapter, false);
8054 btdm_2AntAdcBackOff(padapter, false);
8055 btdm_2AntDacSwing(padapter, false, 0xc0);
8061 static void btdm_2Ant8723APANEDRA2DPAction(struct rtw_adapter *padapter)
8063 u8 btRssiState, btRssiState1, btInfoExt;
8064 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8066 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8068 if (btdm_NeedToDecBtPwr(padapter))
8069 btdm_2AntDecBtPwr(padapter, true);
8071 btdm_2AntDecBtPwr(padapter, false);
8073 if (BTDM_IsHT40(padapter)) {
8074 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8075 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8077 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8078 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8079 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8081 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8083 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8084 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8085 btdm_2AntPsTdma(padapter, true, 4);
8087 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8088 btdm_2AntPsTdma(padapter, true, 2);
8091 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8093 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8094 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8095 btdm_2AntPsTdma(padapter, true, 8);
8097 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8098 btdm_2AntPsTdma(padapter, true, 6);
8103 btdm_2AntAgcTable(padapter, false);
8104 btdm_2AntAdcBackOff(padapter, true);
8105 btdm_2AntDacSwing(padapter, false, 0xc0);
8107 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8108 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8109 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8111 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8112 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8113 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8114 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8116 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8117 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8118 btdm_2AntPsTdma(padapter, true, 4);
8120 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8121 btdm_2AntPsTdma(padapter, true, 2);
8124 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8126 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8127 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8128 btdm_2AntPsTdma(padapter, true, 8);
8130 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8131 btdm_2AntPsTdma(padapter, true, 6);
8136 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8137 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8138 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8139 btdm_2AntAgcTable(padapter, true);
8140 btdm_2AntAdcBackOff(padapter, true);
8141 btdm_2AntDacSwing(padapter, false, 0xc0);
8143 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8144 btdm_2AntAgcTable(padapter, false);
8145 btdm_2AntAdcBackOff(padapter, false);
8146 btdm_2AntDacSwing(padapter, false, 0xc0);
8151 static void btdm_2Ant8723APANEDRHIDAction(struct rtw_adapter *padapter)
8153 u8 btRssiState, btRssiState1;
8155 if (btdm_NeedToDecBtPwr(padapter))
8156 btdm_2AntDecBtPwr(padapter, true);
8158 btdm_2AntDecBtPwr(padapter, false);
8160 if (BTDM_IsHT40(padapter)) {
8161 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8162 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8164 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8165 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8166 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8167 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8168 btdm_2AntPsTdma(padapter, true, 10);
8170 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8171 btdm_2AntPsTdma(padapter, true, 14);
8175 btdm_2AntAgcTable(padapter, false);
8176 btdm_2AntAdcBackOff(padapter, true);
8177 btdm_2AntDacSwing(padapter, false, 0xc0);
8179 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8180 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8181 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8184 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8185 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8186 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8187 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8188 btdm_2AntPsTdma(padapter, true, 10);
8190 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8191 btdm_2AntPsTdma(padapter, true, 14);
8195 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8196 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8197 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8198 btdm_2AntAgcTable(padapter, true);
8199 btdm_2AntAdcBackOff(padapter, true);
8200 btdm_2AntDacSwing(padapter, false, 0xc0);
8202 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8203 btdm_2AntAgcTable(padapter, false);
8204 btdm_2AntAdcBackOff(padapter, false);
8205 btdm_2AntDacSwing(padapter, false, 0xc0);
8210 /* HID+A2DP+PAN(EDR) */
8211 static void btdm_2Ant8723AHIDA2DPPANEDRAction(struct rtw_adapter *padapter)
8213 u8 btRssiState, btRssiState1, btInfoExt;
8214 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8216 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8218 if (btdm_NeedToDecBtPwr(padapter))
8219 btdm_2AntDecBtPwr(padapter, true);
8221 btdm_2AntDecBtPwr(padapter, false);
8223 if (BTDM_IsHT40(padapter)) {
8224 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8225 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8226 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8227 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8228 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8229 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8231 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8232 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8233 btdm_2AntPsTdma(padapter, true, 12);
8235 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8236 btdm_2AntPsTdma(padapter, true, 10);
8239 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8240 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8241 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8242 btdm_2AntPsTdma(padapter, true, 16);
8244 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8245 btdm_2AntPsTdma(padapter, true, 14);
8250 btdm_2AntAgcTable(padapter, false);
8251 btdm_2AntAdcBackOff(padapter, true);
8252 btdm_2AntDacSwing(padapter, false, 0xc0);
8254 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8255 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 37, 0);
8256 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8257 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8258 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8259 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8260 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8262 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8263 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8264 btdm_2AntPsTdma(padapter, true, 12);
8266 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8267 btdm_2AntPsTdma(padapter, true, 10);
8270 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8271 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8272 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8273 btdm_2AntPsTdma(padapter, true, 16);
8275 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8276 btdm_2AntPsTdma(padapter, true, 14);
8281 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8282 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8283 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8284 btdm_2AntAgcTable(padapter, true);
8285 btdm_2AntAdcBackOff(padapter, true);
8286 btdm_2AntDacSwing(padapter, false, 0xc0);
8288 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8289 btdm_2AntAgcTable(padapter, false);
8290 btdm_2AntAdcBackOff(padapter, false);
8291 btdm_2AntDacSwing(padapter, false, 0xc0);
8296 static void btdm_2Ant8723AHIDA2DPAction(struct rtw_adapter *padapter)
8298 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8299 u8 btRssiState, btRssiState1, btInfoExt;
8301 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8303 if (btdm_NeedToDecBtPwr(padapter))
8304 btdm_2AntDecBtPwr(padapter, true);
8306 btdm_2AntDecBtPwr(padapter, false);
8308 if (BTDM_IsHT40(padapter)) {
8309 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8310 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8311 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8312 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8313 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8314 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8316 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8317 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8318 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8320 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8321 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8324 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8325 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8326 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8327 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8329 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8330 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8334 btdm_2AntAgcTable(padapter, false);
8335 btdm_2AntAdcBackOff(padapter, true);
8336 btdm_2AntDacSwing(padapter, false, 0xc0);
8338 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8339 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8340 btRssiState1 = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8342 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8343 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8344 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8345 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8347 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8348 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8349 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8351 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8352 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8355 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8356 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8357 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8358 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8360 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8361 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8364 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8365 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8366 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8368 btdm_2AntAgcTable(padapter, true);
8369 btdm_2AntAdcBackOff(padapter, true);
8370 btdm_2AntDacSwing(padapter, false, 0xc0);
8372 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8374 btdm_2AntAgcTable(padapter, false);
8375 btdm_2AntAdcBackOff(padapter, false);
8376 btdm_2AntDacSwing(padapter, false, 0xc0);
8381 static void btdm_2Ant8723AA2dp(struct rtw_adapter *padapter)
8383 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8384 u8 btRssiState, btRssiState1, btInfoExt;
8386 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8388 if (btdm_NeedToDecBtPwr(padapter))
8389 btdm_2AntDecBtPwr(padapter, true);
8391 btdm_2AntDecBtPwr(padapter, false);
8393 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8394 btdm_2AntIgnoreWlanAct(padapter, false);
8396 if (BTDM_IsHT40(padapter)) {
8397 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8398 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8400 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8401 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8402 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8403 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8404 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8406 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8407 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8411 btdm_2AntAgcTable(padapter, false);
8412 btdm_2AntAdcBackOff(padapter, true);
8413 btdm_2AntDacSwing(padapter, false, 0xc0);
8415 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8416 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8417 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8420 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8421 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8422 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8423 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8424 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8426 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8427 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8431 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8432 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8433 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8434 btdm_2AntAgcTable(padapter, true);
8435 btdm_2AntAdcBackOff(padapter, true);
8436 btdm_2AntDacSwing(padapter, false, 0xc0);
8438 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8439 btdm_2AntAgcTable(padapter, false);
8440 btdm_2AntAdcBackOff(padapter, false);
8441 btdm_2AntDacSwing(padapter, false, 0xc0);
8446 /* extern function start with BTDM_ */
8447 static void BTDM_2AntParaInit(struct rtw_adapter *padapter)
8450 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8451 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8453 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2Ant Parameter Init!!\n"));
8455 /* Enable counter statistics */
8456 rtl8723au_write8(padapter, 0x76e, 0x4);
8457 rtl8723au_write8(padapter, 0x778, 0x3);
8458 rtl8723au_write8(padapter, 0x40, 0x20);
8460 /* force to reset coex mechanism */
8461 pBtdm8723->preVal0x6c0 = 0x0;
8462 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8464 pBtdm8723->bPrePsTdmaOn = true;
8465 btdm_2AntPsTdma(padapter, false, 0);
8467 pBtdm8723->preFwDacSwingLvl = 0x10;
8468 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8470 pBtdm8723->bPreDecBtPwr = true;
8471 btdm_2AntDecBtPwr(padapter, false);
8473 pBtdm8723->bPreAgcTableEn = true;
8474 btdm_2AntAgcTable(padapter, false);
8476 pBtdm8723->bPreAdcBackOff = true;
8477 btdm_2AntAdcBackOff(padapter, false);
8479 pBtdm8723->bPreLowPenaltyRa = true;
8480 btdm_2AntLowPenaltyRa(padapter, false);
8482 pBtdm8723->bPreRfRxLpfShrink = true;
8483 btdm_2AntRfShrink(padapter, false);
8485 pBtdm8723->bPreDacSwingOn = true;
8486 btdm_2AntDacSwing(padapter, false, 0xc0);
8488 pBtdm8723->bPreIgnoreWlanAct = true;
8489 btdm_2AntIgnoreWlanAct(padapter, false);
8492 static void BTDM_2AntHwCoexAllOff8723A(struct rtw_adapter *padapter)
8494 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8497 static void BTDM_2AntFwCoexAllOff8723A(struct rtw_adapter *padapter)
8499 btdm_2AntIgnoreWlanAct(padapter, false);
8500 btdm_2AntPsTdma(padapter, false, 0);
8501 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8502 btdm_2AntDecBtPwr(padapter, false);
8505 static void BTDM_2AntSwCoexAllOff8723A(struct rtw_adapter *padapter)
8507 btdm_2AntAgcTable(padapter, false);
8508 btdm_2AntAdcBackOff(padapter, false);
8509 btdm_2AntLowPenaltyRa(padapter, false);
8510 btdm_2AntRfShrink(padapter, false);
8511 btdm_2AntDacSwing(padapter, false, 0xc0);
8514 static void BTDM_2AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
8516 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8517 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8518 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8519 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8521 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
8522 u8 bBtLinkExist = false, bBtHsModeExist = false;
8524 btInfo = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8525 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8527 /* check BIT2 first ==> check if bt is under inquiry or page scan */
8528 if (btInfo & BIT(2)) {
8529 if (!pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
8530 pBtMgnt->ExtConfig.bHoldForBtOperation = true;
8531 pBtMgnt->ExtConfig.bHoldPeriodCnt = 1;
8532 btdm_2AntBtInquiryPage(padapter);
8534 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8535 btdm_HoldForBtInqPage(padapter);
8537 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = true;
8540 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = false;
8541 pBtMgnt->ExtConfig.bHoldForBtOperation = false;
8542 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8545 RTPRINT(FBT, BT_TRACE,
8546 ("[BTC2H], pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage =%x pBtMgnt->ExtConfig.bHoldPeriodCnt =%x pBtMgnt->ExtConfig.bHoldForBtOperation =%x\n",
8547 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage,
8548 pBtMgnt->ExtConfig.bHoldPeriodCnt,
8549 pBtMgnt->ExtConfig.bHoldForBtOperation));
8551 RTPRINT(FBT, BT_TRACE,
8552 ("[BTC2H], btInfo =%x pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal =%x\n",
8553 btInfo, pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal));
8554 if (btInfo&BT_INFO_ACL) {
8555 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = true btInfo =%x\n", btInfo));
8556 bBtLinkExist = true;
8557 if (((btInfo&(BT_INFO_FTP|BT_INFO_A2DP|BT_INFO_HID|BT_INFO_SCO_BUSY)) != 0) ||
8558 pHalData->bt_coexist.halCoex8723.btRetryCnt > 0) {
8559 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
8561 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
8564 if (btInfo&BT_INFO_SCO || btInfo&BT_INFO_SCO_BUSY) {
8565 if (btInfo&BT_INFO_FTP || btInfo&BT_INFO_A2DP || btInfo&BT_INFO_HID) {
8566 switch (btInfo&0xe0) {
8568 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
8569 algorithm = BT_2ANT_COEX_ALGO_HID;
8572 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
8575 if (bBtHsModeExist) {
8576 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
8577 algorithm = BT_2ANT_COEX_ALGO_SCO;
8579 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
8580 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8583 case (BT_INFO_HID | BT_INFO_A2DP):
8584 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8585 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8587 case (BT_INFO_HID | BT_INFO_FTP):
8588 if (bBtHsModeExist) {
8589 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8590 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8592 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8593 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8596 case (BT_INFO_A2DP | BT_INFO_FTP):
8597 if (bBtHsModeExist) {
8598 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8599 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8601 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8602 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8605 case (BT_INFO_HID | BT_INFO_A2DP | BT_INFO_FTP):
8606 if (bBtHsModeExist) {
8607 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8608 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8610 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8611 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8616 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
8617 algorithm = BT_2ANT_COEX_ALGO_SCO;
8620 RTPRINT(FBT, BT_TRACE, ("[BTCoex], non SCO\n"));
8621 switch (btInfo&0xe0) {
8623 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID\n"));
8624 algorithm = BT_2ANT_COEX_ALGO_HID;
8627 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP\n"));
8628 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8631 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR)\n"));
8632 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8634 case (BT_INFO_HID | BT_INFO_A2DP):
8635 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8636 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8638 case (BT_INFO_HID|BT_INFO_FTP):
8639 if (bBtHsModeExist) {
8640 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8641 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8643 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8644 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8647 case (BT_INFO_A2DP|BT_INFO_FTP):
8648 if (bBtHsModeExist) {
8649 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8650 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8652 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8653 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8656 case (BT_INFO_HID|BT_INFO_A2DP|BT_INFO_FTP):
8657 if (bBtHsModeExist) {
8658 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8659 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8661 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8662 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8669 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = false\n"));
8670 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8673 pBtdm8723->curAlgorithm = algorithm;
8674 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8677 BTDM_CheckWiFiState(padapter);
8678 if (pBtMgnt->ExtConfig.bManualControl) {
8679 RTPRINT(FBT, BT_TRACE, ("Action Manual control, won't execute bt coexist mechanism!!\n"));
8684 void BTDM_2AntBtCoexist8723A(struct rtw_adapter *padapter)
8686 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8687 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8688 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
8689 u8 btInfoOriginal = 0;
8690 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8691 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8693 if (BTDM_BtProfileSupport(padapter)) {
8694 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8695 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8698 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8699 RTPRINT(FBT, BT_TRACE, ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8700 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8701 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8702 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8703 /* next time the coexist parameters should be reset again. */
8705 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8710 if (pBtDbg->dbgCtrl)
8711 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8713 pBtdm8723->curAlgorithm = btdm_ActionAlgorithm(padapter);
8714 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8716 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8717 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8718 pBtdm8723->bResetTdmaAdjust = true;
8720 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8721 RTPRINT(FBT, BT_TRACE, ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8722 pBtdm8723->preAlgorithm, pBtdm8723->curAlgorithm));
8723 pBtdm8723->bResetTdmaAdjust = true;
8725 switch (pBtdm8723->curAlgorithm) {
8726 case BT_2ANT_COEX_ALGO_SCO:
8727 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8728 btdm_2Ant8723ASCOAction(padapter);
8730 case BT_2ANT_COEX_ALGO_HID:
8731 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8732 btdm_2Ant8723AHIDAction(padapter);
8734 case BT_2ANT_COEX_ALGO_A2DP:
8735 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8736 btdm_2Ant8723AA2DPAction(padapter);
8738 case BT_2ANT_COEX_ALGO_PANEDR:
8739 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8740 btdm_2Ant8723APANEDRAction(padapter);
8742 case BT_2ANT_COEX_ALGO_PANHS:
8743 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8744 btdm_2Ant8723APANHSAction(padapter);
8746 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8747 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8748 btdm_2Ant8723APANEDRA2DPAction(padapter);
8750 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8751 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8752 btdm_2Ant8723APANEDRHIDAction(padapter);
8754 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8755 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8756 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8758 case BT_2ANT_COEX_ALGO_HID_A2DP:
8759 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8760 btdm_2Ant8723AHIDA2DPAction(padapter);
8763 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8764 btdm_2Ant8723AA2DPAction(padapter);
8767 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8770 RTPRINT(FBT, BT_TRACE, ("[BTCoex] Get bt info by fw!!\n"));
8771 /* msg shows c2h rsp for bt_info is received or not. */
8772 if (pHalData->bt_coexist.halCoex8723.bC2hBtInfoReqSent)
8773 RTPRINT(FBT, BT_TRACE, ("[BTCoex] c2h for btInfo not rcvd yet!!\n"));
8775 btInfoOriginal = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8777 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8778 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8781 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8782 RTPRINT(FBT, BT_TRACE,
8783 ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8784 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8785 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8786 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8787 /* next time the coexist parameters should be reset again. */
8789 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8794 if (pBtDbg->dbgCtrl)
8795 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8796 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8797 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8798 pBtdm8723->bResetTdmaAdjust = true;
8800 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8801 RTPRINT(FBT, BT_TRACE,
8802 ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8803 pBtdm8723->preAlgorithm,
8804 pBtdm8723->curAlgorithm));
8805 pBtdm8723->bResetTdmaAdjust = true;
8807 switch (pBtdm8723->curAlgorithm) {
8808 case BT_2ANT_COEX_ALGO_SCO:
8809 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8810 btdm_2Ant8723ASCOAction(padapter);
8812 case BT_2ANT_COEX_ALGO_HID:
8813 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8814 btdm_2Ant8723AHIDAction(padapter);
8816 case BT_2ANT_COEX_ALGO_A2DP:
8817 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8818 btdm_2Ant8723AA2dp(padapter);
8820 case BT_2ANT_COEX_ALGO_PANEDR:
8821 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8822 btdm_2Ant8723APANEDRAction(padapter);
8824 case BT_2ANT_COEX_ALGO_PANHS:
8825 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8826 btdm_2Ant8723APANHSAction(padapter);
8828 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8829 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8830 btdm_2Ant8723APANEDRA2DPAction(padapter);
8832 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8833 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8834 btdm_2Ant8723APANEDRHIDAction(padapter);
8836 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8837 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8838 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8840 case BT_2ANT_COEX_ALGO_HID_A2DP:
8841 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8842 btdm_2Ant8723AHIDA2DPAction(padapter);
8845 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8846 btdm_2Ant8723AA2DPAction(padapter);
8849 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8854 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
8856 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
8858 static u8 btCoexDbgBuf[BT_TMP_BUF_SIZE];
8860 static const char *const BtProfileString[] = {
8868 static const char *const BtSpecString[] = {
8878 static const char *const BtLinkRoleString[] = {
8883 static u8 btdm_BtWifiAntNum(struct rtw_adapter *padapter)
8885 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8886 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
8888 if (Ant_x2 == pHalData->bt_coexist.BT_Ant_Num) {
8889 if (Ant_x2 == pBtCoex->TotalAntNum)
8899 static void btdm_BtHwCountersMonitor(struct rtw_adapter *padapter)
8901 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8902 u32 regHPTxRx, regLPTxRx, u4Tmp;
8903 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
8905 regHPTxRx = REG_HIGH_PRIORITY_TXRX;
8906 regLPTxRx = REG_LOW_PRIORITY_TXRX;
8908 u4Tmp = rtl8723au_read32(padapter, regHPTxRx);
8909 regHPTx = u4Tmp & bMaskLWord;
8910 regHPRx = (u4Tmp & bMaskHWord)>>16;
8912 u4Tmp = rtl8723au_read32(padapter, regLPTxRx);
8913 regLPTx = u4Tmp & bMaskLWord;
8914 regLPRx = (u4Tmp & bMaskHWord)>>16;
8916 pHalData->bt_coexist.halCoex8723.highPriorityTx = regHPTx;
8917 pHalData->bt_coexist.halCoex8723.highPriorityRx = regHPRx;
8918 pHalData->bt_coexist.halCoex8723.lowPriorityTx = regLPTx;
8919 pHalData->bt_coexist.halCoex8723.lowPriorityRx = regLPRx;
8921 RTPRINT(FBT, BT_TRACE, ("High Priority Tx/Rx = %d / %d\n", regHPTx, regHPRx));
8922 RTPRINT(FBT, BT_TRACE, ("Low Priority Tx/Rx = %d / %d\n", regLPTx, regLPRx));
8925 rtl8723au_write8(padapter, 0x76e, 0xc);
8928 /* This function check if 8723 bt is disabled */
8929 static void btdm_BtEnableDisableCheck8723A(struct rtw_adapter *padapter)
8932 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8934 #ifdef CHECK_BT_EXIST_FROM_REG
8937 /* ox68[28]= 1 => BT enable; otherwise disable */
8938 val8 = rtl8723au_read8(padapter, 0x6B);
8939 if (!(val8 & BIT(4)))
8943 pHalData->bt_coexist.bCurBtDisabled = false;
8945 pHalData->bt_coexist.bCurBtDisabled = true;
8947 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0 &&
8948 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0 &&
8949 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0 &&
8950 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0)
8952 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xeaea &&
8953 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xeaea &&
8954 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xeaea &&
8955 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xeaea)
8957 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xffff &&
8958 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xffff &&
8959 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xffff &&
8960 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xffff)
8963 pHalData->bt_coexist.btActiveZeroCnt = 0;
8964 pHalData->bt_coexist.bCurBtDisabled = false;
8965 RTPRINT(FBT, BT_TRACE, ("8723A BT is enabled !!\n"));
8967 pHalData->bt_coexist.btActiveZeroCnt++;
8968 RTPRINT(FBT, BT_TRACE, ("8723A bt all counters = 0, %d times!!\n",
8969 pHalData->bt_coexist.btActiveZeroCnt));
8970 if (pHalData->bt_coexist.btActiveZeroCnt >= 2) {
8971 pHalData->bt_coexist.bCurBtDisabled = true;
8972 RTPRINT(FBT, BT_TRACE, ("8723A BT is disabled !!\n"));
8977 if (!pHalData->bt_coexist.bCurBtDisabled) {
8978 if (BTDM_IsWifiConnectionExist(padapter))
8979 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
8981 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_DISCONNECT);
8984 if (pHalData->bt_coexist.bPreBtDisabled !=
8985 pHalData->bt_coexist.bCurBtDisabled) {
8986 RTPRINT(FBT, BT_TRACE, ("8723A BT is from %s to %s!!\n",
8987 (pHalData->bt_coexist.bPreBtDisabled ? "disabled":"enabled"),
8988 (pHalData->bt_coexist.bCurBtDisabled ? "disabled":"enabled")));
8989 pHalData->bt_coexist.bPreBtDisabled = pHalData->bt_coexist.bCurBtDisabled;
8993 static void btdm_BTCoexist8723AHandler(struct rtw_adapter *padapter)
8995 struct hal_data_8723a *pHalData;
8997 pHalData = GET_HAL_DATA(padapter);
8999 if (btdm_BtWifiAntNum(padapter) == Ant_x2) {
9000 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2 Ant mechanism\n"));
9001 BTDM_2AntBtCoexist8723A(padapter);
9003 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1 Ant mechanism\n"));
9004 BTDM_1AntBtCoexist8723A(padapter);
9007 if (!BTDM_IsSameCoexistState(padapter)) {
9008 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x\n",
9009 pHalData->bt_coexist.PreviousState,
9010 pHalData->bt_coexist.CurrentState));
9011 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
9013 RTPRINT(FBT, BT_TRACE, ("["));
9014 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT30)
9015 RTPRINT(FBT, BT_TRACE, ("BT 3.0, "));
9016 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT20)
9017 RTPRINT(FBT, BT_TRACE, ("HT20, "));
9018 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT40)
9019 RTPRINT(FBT, BT_TRACE, ("HT40, "));
9020 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_LEGACY)
9021 RTPRINT(FBT, BT_TRACE, ("Legacy, "));
9022 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_LOW)
9023 RTPRINT(FBT, BT_TRACE, ("Rssi_Low, "));
9024 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_MEDIUM)
9025 RTPRINT(FBT, BT_TRACE, ("Rssi_Mid, "));
9026 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_HIGH)
9027 RTPRINT(FBT, BT_TRACE, ("Rssi_High, "));
9028 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_IDLE)
9029 RTPRINT(FBT, BT_TRACE, ("Wifi_Idle, "));
9030 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_UPLINK)
9031 RTPRINT(FBT, BT_TRACE, ("Wifi_Uplink, "));
9032 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_DOWNLINK)
9033 RTPRINT(FBT, BT_TRACE, ("Wifi_Downlink, "));
9034 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)
9035 RTPRINT(FBT, BT_TRACE, ("BT_idle, "));
9036 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_HID)
9037 RTPRINT(FBT, BT_TRACE, ("PRO_HID, "));
9038 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_A2DP)
9039 RTPRINT(FBT, BT_TRACE, ("PRO_A2DP, "));
9040 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_PAN)
9041 RTPRINT(FBT, BT_TRACE, ("PRO_PAN, "));
9042 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_SCO)
9043 RTPRINT(FBT, BT_TRACE, ("PRO_SCO, "));
9044 RTPRINT(FBT, BT_TRACE, ("]\n"));
9048 /* extern function start with BTDM_ */
9049 u32 BTDM_BtTxRxCounterH(struct rtw_adapter *padapter)
9051 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9054 counters = pHalData->bt_coexist.halCoex8723.highPriorityTx+
9055 pHalData->bt_coexist.halCoex8723.highPriorityRx;
9059 u32 BTDM_BtTxRxCounterL(struct rtw_adapter *padapter)
9061 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9064 counters = pHalData->bt_coexist.halCoex8723.lowPriorityTx+
9065 pHalData->bt_coexist.halCoex8723.lowPriorityRx;
9069 void BTDM_SetFwChnlInfo(struct rtw_adapter *padapter, enum rt_media_status mstatus)
9071 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9072 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9073 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9074 u8 H2C_Parameter[3] = {0};
9078 if (RT_MEDIA_CONNECT == mstatus)
9079 H2C_Parameter[0] = 0x1; /* 0: disconnected, 1:connected */
9081 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) {
9083 chnl = pmlmeext->cur_channel;
9084 if (BTDM_IsHT40(padapter)) {
9085 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
9087 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
9090 H2C_Parameter[1] = chnl;
9091 } else { /* check if HS link is exists */
9093 if (BT_Operation(padapter))
9094 H2C_Parameter[1] = pBtMgnt->BTChannel;
9096 H2C_Parameter[1] = pmlmeext->cur_channel;
9099 if (BTDM_IsHT40(padapter))
9100 H2C_Parameter[2] = 0x30;
9102 H2C_Parameter[2] = 0x20;
9104 FillH2CCmd(padapter, 0x19, 3, H2C_Parameter);
9107 u8 BTDM_IsWifiConnectionExist(struct rtw_adapter *padapter)
9111 if (BTHCI_HsConnectionEstablished(padapter))
9114 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true)
9121 struct rtw_adapter *padapter,
9129 u8 H2C_Parameter[5] = {0};
9131 if (rtl8723a_BT_using_antenna_1(padapter)) {
9132 if ((!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
9133 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
9134 /* for softap mode */
9135 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9136 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9137 u8 BtState = pBtCoex->c2hBtInfo;
9139 if ((BtState != BT_INFO_STATE_NO_CONNECTION) &&
9140 (BtState != BT_INFO_STATE_CONNECT_IDLE)) {
9141 if (byte1 & BIT(4)) {
9153 H2C_Parameter[0] = byte1;
9154 H2C_Parameter[1] = byte2;
9155 H2C_Parameter[2] = byte3;
9156 H2C_Parameter[3] = byte4;
9157 H2C_Parameter[4] = byte5;
9159 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%02x%08x\n",
9161 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
9163 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
9166 void BTDM_QueryBtInformation(struct rtw_adapter *padapter)
9168 u8 H2C_Parameter[1] = {0};
9169 struct hal_data_8723a *pHalData;
9170 struct bt_coexist_8723a *pBtCoex;
9172 pHalData = GET_HAL_DATA(padapter);
9173 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9175 if (!rtl8723a_BT_enabled(padapter)) {
9176 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9177 pBtCoex->bC2hBtInfoReqSent = false;
9181 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9182 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9184 if (pBtCoex->bC2hBtInfoReqSent == true)
9185 RTPRINT(FBT, BT_TRACE, ("[BTCoex], didn't recv previous BtInfo report!\n"));
9187 pBtCoex->bC2hBtInfoReqSent = true;
9189 H2C_Parameter[0] |= BIT(0); /* trigger */
9191 /*RTPRINT(FBT, BT_TRACE, ("[BTCoex], Query Bt information, write 0x38 = 0x%x\n", */
9192 /*H2C_Parameter[0])); */
9194 FillH2CCmd(padapter, 0x38, 1, H2C_Parameter);
9197 void BTDM_SetSwRfRxLpfCorner(struct rtw_adapter *padapter, u8 type)
9199 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9201 if (BT_RF_RX_LPF_CORNER_SHRINK == type) {
9202 /* Shrink RF Rx LPF corner */
9203 RTPRINT(FBT, BT_TRACE, ("Shrink RF Rx LPF corner!!\n"));
9204 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, 0xf0ff7);
9205 pHalData->bt_coexist.bSWCoexistAllOff = false;
9206 } else if (BT_RF_RX_LPF_CORNER_RESUME == type) {
9207 /* Resume RF Rx LPF corner */
9208 RTPRINT(FBT, BT_TRACE, ("Resume RF Rx LPF corner!!\n"));
9209 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, pHalData->bt_coexist.BtRfRegOrigin1E);
9214 BTDM_SetSwPenaltyTxRateAdaptive(
9215 struct rtw_adapter *padapter,
9219 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9222 tmpU1 = rtl8723au_read8(padapter, 0x4fd);
9224 if (BT_TX_RATE_ADAPTIVE_LOW_PENALTY == raType) {
9226 pHalData->bt_coexist.bSWCoexistAllOff = false;
9227 } else if (BT_TX_RATE_ADAPTIVE_NORMAL == raType) {
9231 rtl8723au_write8(padapter, 0x4fd, tmpU1);
9234 void BTDM_SetFwDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
9236 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9237 u8 H2C_Parameter[1] = {0};
9239 H2C_Parameter[0] = 0;
9242 H2C_Parameter[0] |= BIT(1);
9243 pHalData->bt_coexist.bFWCoexistAllOff = false;
9246 RTPRINT(FBT, BT_TRACE, ("[BTCoex], decrease Bt Power : %s, write 0x21 = 0x%x\n",
9247 (bDecBtPwr ? "Yes!!" : "No!!"), H2C_Parameter[0]));
9249 FillH2CCmd(padapter, 0x21, 1, H2C_Parameter);
9252 u8 BTDM_BtProfileSupport(struct rtw_adapter *padapter)
9255 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9256 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9257 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9259 if (pBtMgnt->bSupportProfile &&
9260 !pHalData->bt_coexist.halCoex8723.bForceFwBtInfo)
9266 static void BTDM_AdjustForBtOperation8723A(struct rtw_adapter *padapter)
9268 /* BTDM_2AntAdjustForBtOperation8723(padapter); */
9271 static void BTDM_FwC2hBtRssi8723A(struct rtw_adapter *padapter, u8 *tmpBuf)
9273 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9277 percent = u1tmp*2+10;
9279 pHalData->bt_coexist.halCoex8723.btRssi = percent;
9280 /*RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", percent)); */
9284 rtl8723a_fw_c2h_BT_info(struct rtw_adapter *padapter, u8 *tmpBuf, u8 length)
9286 struct hal_data_8723a *pHalData;
9287 struct bt_30info *pBTInfo;
9288 struct bt_mgnt *pBtMgnt;
9289 struct bt_coexist_8723a *pBtCoex;
9292 pHalData = GET_HAL_DATA(padapter);
9293 pBTInfo = GET_BT_INFO(padapter);
9294 pBtMgnt = &pBTInfo->BtMgnt;
9295 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9297 pBtCoex->bC2hBtInfoReqSent = false;
9299 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT info[%d]=[", length));
9301 pBtCoex->btRetryCnt = 0;
9302 for (i = 0; i < length; i++) {
9305 pBtCoex->c2hBtInfoOriginal = tmpBuf[i];
9308 pBtCoex->btRetryCnt = tmpBuf[i];
9311 BTDM_FwC2hBtRssi8723A(padapter, &tmpBuf[i]);
9314 pBtCoex->btInfoExt = tmpBuf[i]&BIT(0);
9319 RTPRINT(FBT, BT_TRACE, ("0x%02x]\n", tmpBuf[i]));
9321 RTPRINT(FBT, BT_TRACE, ("0x%02x, ", tmpBuf[i]));
9323 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", pBtCoex->btRssi));
9324 if (pBtCoex->btInfoExt)
9325 RTPRINT(FBT, BT_TRACE, ("[BTC2H], pBtCoex->btInfoExt =%x\n", pBtCoex->btInfoExt));
9327 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9328 BTDM_1AntFwC2hBtInfo8723A(padapter);
9330 BTDM_2AntFwC2hBtInfo8723A(padapter);
9332 if (pBtMgnt->ExtConfig.bManualControl) {
9333 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9337 btdm_BTCoexist8723AHandler(padapter);
9340 static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
9342 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9343 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9344 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9345 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9346 u8 u1Tmp, u1Tmp1, u1Tmp2, i, btInfoExt, psTdmaCase = 0;
9350 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
9351 DCMD_Printf(btCoexDbgBuf);
9353 if (!rtl8723a_BT_coexist(padapter)) {
9354 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");
9355 DCMD_Printf(btCoexDbgBuf);
9359 antNum = btdm_BtWifiAntNum(padapter);
9360 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/%d ", "Ant mechanism PG/Now run :", \
9361 ((pHalData->bt_coexist.BT_Ant_Num == Ant_x2) ? 2 : 1), ((antNum == Ant_x2) ? 2 : 1));
9362 DCMD_Printf(btCoexDbgBuf);
9364 if (pBtMgnt->ExtConfig.bManualControl) {
9365 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
9366 DCMD_Printf(btCoexDbgBuf);
9368 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
9369 ((pBtMgnt->bSupportProfile) ? "Yes" : "No"), pBtMgnt->ExtConfig.HCIExtensionVer);
9370 DCMD_Printf(btCoexDbgBuf);
9373 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = / %d", "Dot11 channel / BT channel", \
9374 pBtMgnt->BTChannel);
9375 DCMD_Printf(btCoexDbgBuf);
9377 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %d / %d / %d", "Wifi/BT/HS rssi", \
9378 BTDM_GetRxSS(padapter),
9379 pHalData->bt_coexist.halCoex8723.btRssi,
9380 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB);
9381 DCMD_Printf(btCoexDbgBuf);
9383 if (!pBtMgnt->ExtConfig.bManualControl) {
9384 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %s / %s ", "WIfi status",
9385 ((BTDM_Legacy(padapter)) ? "Legacy" : (((BTDM_IsHT40(padapter)) ? "HT40" : "HT20"))),
9386 ((!BTDM_IsWifiBusy(padapter)) ? "idle" : ((BTDM_IsWifiUplink(padapter)) ? "uplink" : "downlink")));
9387 DCMD_Printf(btCoexDbgBuf);
9389 if (pBtMgnt->bSupportProfile) {
9390 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
9391 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_SCO)) ? 1 : 0),
9392 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) ? 1 : 0),
9393 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) ? 1 : 0),
9394 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) ? 1 : 0));
9395 DCMD_Printf(btCoexDbgBuf);
9397 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
9398 if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
9399 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role",
9400 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9401 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec],
9402 BtLinkRoleString[pBtMgnt->ExtConfig.linkInfo[i].linkRole]);
9403 DCMD_Printf(btCoexDbgBuf);
9405 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
9406 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "A2DP rate", \
9407 (btInfoExt & BIT(0)) ?
9408 "Basic rate" : "EDR rate");
9409 DCMD_Printf(btCoexDbgBuf);
9411 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
9412 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9413 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec]);
9414 DCMD_Printf(btCoexDbgBuf);
9421 if (!pBtMgnt->ExtConfig.bManualControl) {
9422 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw BT Coex mechanism]============");
9423 DCMD_Printf(btCoexDbgBuf);
9424 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "AGC Table", \
9425 pBtCoex->btdm2Ant.bCurAgcTableEn);
9426 DCMD_Printf(btCoexDbgBuf);
9427 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "ADC Backoff", \
9428 pBtCoex->btdm2Ant.bCurAdcBackOff);
9429 DCMD_Printf(btCoexDbgBuf);
9430 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Low penalty RA", \
9431 pBtCoex->btdm2Ant.bCurLowPenaltyRa);
9432 DCMD_Printf(btCoexDbgBuf);
9433 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "RF Rx LPF Shrink", \
9434 pBtCoex->btdm2Ant.bCurRfRxLpfShrink);
9435 DCMD_Printf(btCoexDbgBuf);
9437 u4Tmp[0] = PHY_QueryRFReg(padapter, PathA, 0x1e, 0xff0);
9438 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "RF-A, 0x1e[11:4]/original val", \
9439 u4Tmp[0], pHalData->bt_coexist.BtRfRegOrigin1E);
9440 DCMD_Printf(btCoexDbgBuf);
9443 if (!pBtMgnt->ExtConfig.bManualControl) {
9444 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw BT Coex mechanism]============");
9445 DCMD_Printf(btCoexDbgBuf);
9447 if (!pBtMgnt->ExtConfig.bManualControl) {
9448 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9449 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm1Ant.curPsTdma;
9451 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm2Ant.curPsTdma;
9452 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %*ph case-%d",
9453 "PS TDMA(0x3a)", 5, pHalData->bt_coexist.fw3aVal, psTdmaCase);
9454 DCMD_Printf(btCoexDbgBuf);
9456 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Decrease Bt Power", \
9457 pBtCoex->btdm2Ant.bCurDecBtPwr);
9458 DCMD_Printf(btCoexDbgBuf);
9460 u1Tmp = rtl8723au_read8(padapter, 0x778);
9461 u1Tmp1 = rtl8723au_read8(padapter, 0x783);
9462 u1Tmp2 = rtl8723au_read8(padapter, 0x796);
9463 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
9464 u1Tmp, u1Tmp1, u1Tmp2);
9465 DCMD_Printf(btCoexDbgBuf);
9467 if (!pBtMgnt->ExtConfig.bManualControl) {
9468 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "Sw DacSwing Ctrl/Val", \
9469 pBtCoex->btdm2Ant.bCurDacSwingOn, pBtCoex->btdm2Ant.curDacSwingLvl);
9470 DCMD_Printf(btCoexDbgBuf);
9472 u4Tmp[0] = rtl8723au_read32(padapter, 0x880);
9473 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \
9475 DCMD_Printf(btCoexDbgBuf);
9478 if (!pBtMgnt->ExtConfig.bManualControl) {
9479 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw BT Coex mechanism]============");
9480 DCMD_Printf(btCoexDbgBuf);
9483 u1Tmp = rtl8723au_read8(padapter, 0x40);
9484 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
9486 DCMD_Printf(btCoexDbgBuf);
9488 u4Tmp[0] = rtl8723au_read32(padapter, 0x550);
9489 u1Tmp = rtl8723au_read8(padapter, 0x522);
9490 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x", "0x550(bcn contrl)/0x522", \
9492 DCMD_Printf(btCoexDbgBuf);
9494 u4Tmp[0] = rtl8723au_read32(padapter, 0x484);
9495 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
9497 DCMD_Printf(btCoexDbgBuf);
9499 u4Tmp[0] = rtl8723au_read32(padapter, 0x50);
9500 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
9502 DCMD_Printf(btCoexDbgBuf);
9504 u4Tmp[0] = rtl8723au_read32(padapter, 0xda0);
9505 u4Tmp[1] = rtl8723au_read32(padapter, 0xda4);
9506 u4Tmp[2] = rtl8723au_read32(padapter, 0xda8);
9507 u4Tmp[3] = rtl8723au_read32(padapter, 0xdac);
9508 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
9509 u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);
9510 DCMD_Printf(btCoexDbgBuf);
9512 u4Tmp[0] = rtl8723au_read32(padapter, 0x6c0);
9513 u4Tmp[1] = rtl8723au_read32(padapter, 0x6c4);
9514 u4Tmp[2] = rtl8723au_read32(padapter, 0x6c8);
9515 u1Tmp = rtl8723au_read8(padapter, 0x6cc);
9516 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
9517 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp);
9518 DCMD_Printf(btCoexDbgBuf);
9520 /* u4Tmp = rtl8723au_read32(padapter, 0x770); */
9521 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x770(Hi pri Rx[31:16]/Tx[15:0])", \
9522 pHalData->bt_coexist.halCoex8723.highPriorityRx,
9523 pHalData->bt_coexist.halCoex8723.highPriorityTx);
9524 DCMD_Printf(btCoexDbgBuf);
9525 /* u4Tmp = rtl8723au_read32(padapter, 0x774); */
9526 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x774(Lo pri Rx[31:16]/Tx[15:0])", \
9527 pHalData->bt_coexist.halCoex8723.lowPriorityRx,
9528 pHalData->bt_coexist.halCoex8723.lowPriorityTx);
9529 DCMD_Printf(btCoexDbgBuf);
9531 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang */
9532 u1Tmp = rtl8723au_read8(padapter, 0x41b);
9533 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x41b (hang chk == 0xf)", \
9535 DCMD_Printf(btCoexDbgBuf);
9536 snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
9537 pHalData->LastHMEBoxNum);
9538 DCMD_Printf(btCoexDbgBuf);
9542 BTDM_8723ASignalCompensation(struct rtw_adapter *padapter,
9543 u8 *rssi_wifi, u8 *rssi_bt)
9545 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9546 BTDM_1AntSignalCompensation(padapter, rssi_wifi, rssi_bt);
9549 static void BTDM_8723AInit(struct rtw_adapter *padapter)
9551 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9552 BTDM_2AntParaInit(padapter);
9554 BTDM_1AntParaInit(padapter);
9557 static void BTDM_HWCoexAllOff8723A(struct rtw_adapter *padapter)
9559 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9560 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9562 if (pBtMgnt->ExtConfig.bManualControl)
9565 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9566 BTDM_2AntHwCoexAllOff8723A(padapter);
9569 static void BTDM_FWCoexAllOff8723A(struct rtw_adapter *padapter)
9571 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9572 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9574 if (pBtMgnt->ExtConfig.bManualControl)
9577 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9578 BTDM_2AntFwCoexAllOff8723A(padapter);
9581 static void BTDM_SWCoexAllOff8723A(struct rtw_adapter *padapter)
9583 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9584 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9586 if (pBtMgnt->ExtConfig.bManualControl)
9589 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9590 BTDM_2AntSwCoexAllOff8723A(padapter);
9594 BTDM_Set8723ABtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
9596 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9597 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9600 pBtCoex->TotalAntNum = Ant_x1;
9601 else if (antNum == 2)
9602 pBtCoex->TotalAntNum = Ant_x2;
9605 void rtl8723a_BT_lps_leave(struct rtw_adapter *padapter)
9607 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9608 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9610 if (pBtMgnt->ExtConfig.bManualControl)
9613 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9614 BTDM_1AntLpsLeave(padapter);
9617 static void BTDM_ForHalt8723A(struct rtw_adapter *padapter)
9619 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9620 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9622 if (pBtMgnt->ExtConfig.bManualControl)
9625 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9626 BTDM_1AntForHalt(padapter);
9629 static void BTDM_WifiScanNotify8723A(struct rtw_adapter *padapter, u8 scanType)
9631 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9632 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9634 if (pBtMgnt->ExtConfig.bManualControl)
9637 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9638 BTDM_1AntWifiScanNotify(padapter, scanType);
9642 BTDM_WifiAssociateNotify8723A(struct rtw_adapter *padapter, u8 action)
9644 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9645 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9647 if (pBtMgnt->ExtConfig.bManualControl)
9650 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9651 BTDM_1AntWifiAssociateNotify(padapter, action);
9655 BTDM_MediaStatusNotify8723A(struct rtw_adapter *padapter,
9656 enum rt_media_status mstatus)
9658 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9659 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9661 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatusNotify, %s\n",
9662 mstatus?"connect":"disconnect"));
9664 BTDM_SetFwChnlInfo(padapter, mstatus);
9666 if (pBtMgnt->ExtConfig.bManualControl)
9669 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9670 BTDM_1AntMediaStatusNotify(padapter, mstatus);
9673 static void BTDM_ForDhcp8723A(struct rtw_adapter *padapter)
9675 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9676 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9678 if (pBtMgnt->ExtConfig.bManualControl)
9681 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9682 BTDM_1AntForDhcp(padapter);
9685 bool rtl8723a_BT_using_antenna_1(struct rtw_adapter *padapter)
9687 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9693 static void BTDM_BTCoexist8723A(struct rtw_adapter *padapter)
9695 struct hal_data_8723a *pHalData;
9696 struct bt_30info *pBTInfo;
9697 struct bt_mgnt *pBtMgnt;
9698 struct bt_coexist_8723a *pBtCoex;
9700 pHalData = GET_HAL_DATA(padapter);
9701 pBTInfo = GET_BT_INFO(padapter);
9702 pBtMgnt = &pBTInfo->BtMgnt;
9703 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9705 RTPRINT(FBT, BT_TRACE, ("[BTCoex], beacon RSSI = 0x%x(%d)\n",
9706 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB,
9707 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB));
9709 btdm_BtHwCountersMonitor(padapter);
9710 btdm_BtEnableDisableCheck8723A(padapter);
9712 if (pBtMgnt->ExtConfig.bManualControl) {
9713 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9717 if (pBtCoex->bC2hBtInfoReqSent) {
9718 if (!rtl8723a_BT_enabled(padapter)) {
9719 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9721 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9722 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9725 btdm_BTCoexist8723AHandler(padapter);
9726 } else if (!rtl8723a_BT_enabled(padapter)) {
9727 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9728 btdm_BTCoexist8723AHandler(padapter);
9731 BTDM_QueryBtInformation(padapter);
9734 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
9736 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
9738 /* local function start with btdm_ */
9739 /* extern function start with BTDM_ */
9741 static void BTDM_SetAntenna(struct rtw_adapter *padapter, u8 who)
9747 struct rtw_adapter *padapter,
9753 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9754 u8 H2C_Parameter[3] = {0};
9756 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9759 H2C_Parameter[2] = 0;
9760 H2C_Parameter[1] = 0;
9761 H2C_Parameter[0] = 0;
9764 H2C_Parameter[2] |= 0x02; /* BIT1 */
9765 pHalData->bt_coexist.bFWCoexistAllOff = false;
9767 pHalData->bt_coexist.bInterruptOn = bInterruptOn;
9770 H2C_Parameter[2] |= 0x10; /* BIT4 */
9771 pHalData->bt_coexist.bFWCoexistAllOff = false;
9773 pHalData->bt_coexist.bSingleAntOn = bSingleAntOn;
9776 H2C_Parameter[2] |= 0x20; /* BIT5 */
9777 pHalData->bt_coexist.bFWCoexistAllOff = false;
9779 pHalData->bt_coexist.bMultiNAVOn = bMultiNAVOn;
9781 RTPRINT(FBT, BT_TRACE, ("[DM][BT], SingleAntenna =[%s:%s:%s], write 0xe = 0x%x\n",
9782 bSingleAntOn?"ON":"OFF", bInterruptOn?"ON":"OFF", bMultiNAVOn?"ON":"OFF",
9783 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
9786 void BTDM_CheckBTIdleChange1Ant(struct rtw_adapter *padapter)
9788 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9789 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9790 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9791 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
9792 u8 stateChange = false;
9793 u32 BT_Polling, Ratio_Act, Ratio_STA;
9794 u32 BT_Active, BT_State;
9795 u32 regBTActive = 0, regBTState = 0, regBTPolling = 0;
9797 if (!rtl8723a_BT_coexist(padapter))
9799 if (pBtMgnt->ExtConfig.bManualControl)
9801 if (pHalData->bt_coexist.BT_CoexistType != BT_CSR_BC8)
9803 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9806 /* The following we only consider CSR BC8 and fw version should be >= 62 */
9807 RTPRINT(FBT, BT_TRACE, ("[DM][BT], FirmwareVersion = 0x%x(%d)\n",
9808 pHalData->FirmwareVersion, pHalData->FirmwareVersion));
9809 regBTActive = REG_BT_ACTIVE;
9810 regBTState = REG_BT_STATE;
9811 if (pHalData->FirmwareVersion >= FW_VER_BT_REG1)
9812 regBTPolling = REG_BT_POLLING1;
9814 regBTPolling = REG_BT_POLLING;
9816 BT_Active = rtl8723au_read32(padapter, regBTActive);
9817 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Active(0x%x) =%x\n", regBTActive, BT_Active));
9818 BT_Active = BT_Active & 0x00ffffff;
9820 BT_State = rtl8723au_read32(padapter, regBTState);
9821 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_State(0x%x) =%x\n", regBTState, BT_State));
9822 BT_State = BT_State & 0x00ffffff;
9824 BT_Polling = rtl8723au_read32(padapter, regBTPolling);
9825 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Polling(0x%x) =%x\n", regBTPolling, BT_Polling));
9827 if (BT_Active == 0x00ffffff && BT_State == 0x00ffffff && BT_Polling == 0xffffffff)
9829 if (BT_Polling == 0)
9832 Ratio_Act = BT_Active*1000/BT_Polling;
9833 Ratio_STA = BT_State*1000/BT_Polling;
9835 pHalData->bt_coexist.Ratio_Tx = Ratio_Act;
9836 pHalData->bt_coexist.Ratio_PRI = Ratio_STA;
9838 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_Act =%d\n", Ratio_Act));
9839 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_STA =%d\n", Ratio_STA));
9841 if (Ratio_STA < 60 && Ratio_Act < 500) { /* BT PAN idle */
9842 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_IDLE;
9843 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9844 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9846 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_IDLE;
9849 /* Check if BT PAN (under BT 2.1) is uplink or downlink */
9850 if ((Ratio_Act/Ratio_STA) < 2) {
9852 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = true;
9853 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_UPLINK;
9854 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = false;
9855 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9857 /* BT PAN downlink */
9858 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9859 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9860 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9861 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9864 /* BT PAN downlink */
9865 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9866 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9867 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9868 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9872 /* Check BT is idle or not */
9873 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9874 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9875 pBtMgnt->ExtConfig.bBTBusy = false;
9876 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9878 if (Ratio_STA < 60) {
9879 pBtMgnt->ExtConfig.bBTBusy = false;
9880 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9882 pBtMgnt->ExtConfig.bBTBusy = true;
9883 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_IDLE;
9887 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9888 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9889 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
9890 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
9891 BTDM_SetAntenna(padapter, BTDM_ANT_BT_IDLE);
9893 if (pBtMgnt->ExtConfig.MIN_BT_RSSI <= -5) {
9894 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_RSSI_LOW;
9895 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Low\n"));
9897 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
9898 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Normal\n"));
9902 if (pHalData->bt_coexist.bBTBusyTraffic != pBtMgnt->ExtConfig.bBTBusy) {
9903 /* BT idle or BT non-idle */
9904 pHalData->bt_coexist.bBTBusyTraffic = pBtMgnt->ExtConfig.bBTBusy;
9909 if (!pBtMgnt->ExtConfig.bBTBusy)
9910 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
9912 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is non-idle\n"));
9914 if (!pBtMgnt->ExtConfig.bBTBusy) {
9915 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
9916 if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING|WIFI_SITE_MONITOR) == true)
9917 BTDM_SetAntenna(padapter, BTDM_ANT_WIFI);
9921 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
9923 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
9925 /* local function start with btdm_ */
9928 /* In the following, FW should be done before SW mechanism. */
9929 /* BTDM_Balance(), BTDM_DiminishWiFi(), BT_NAV() should be done */
9930 /* before BTDM_AGCTable(), BTDM_BBBackOffLevel(), btdm_DacSwing(). */
9932 /* extern function start with BTDM_ */
9936 struct rtw_adapter *padapter,
9943 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9944 u8 H2C_Parameter[3] = {0};
9946 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x2)
9949 if ((pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_RSSI_LOW) &&
9950 (DACSwingLevel == 0x20)) {
9951 RTPRINT(FBT, BT_TRACE, ("[BT]DiminishWiFi 0x20 original, but set 0x18 for Low RSSI!\n"));
9952 DACSwingLevel = 0x18;
9955 H2C_Parameter[2] = 0;
9956 H2C_Parameter[1] = DACSwingLevel;
9957 H2C_Parameter[0] = 0;
9959 H2C_Parameter[2] |= 0x01; /* BIT0 */
9961 H2C_Parameter[2] |= 0x02; /* BIT1 */
9962 pHalData->bt_coexist.bFWCoexistAllOff = false;
9965 H2C_Parameter[2] |= 0x08; /* BIT3 */
9966 pHalData->bt_coexist.bFWCoexistAllOff = false;
9969 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bDACOn = %s, bInterruptOn = %s, write 0xe = 0x%x\n",
9970 bDACOn?"ON":"OFF", bInterruptOn?"ON":"OFF",
9971 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
9972 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bNAVOn = %s\n",
9973 bNAVOn?"ON":"OFF"));
9976 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
9978 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
9980 /* local function */
9981 static void btdm_ResetFWCoexState(struct rtw_adapter *padapter)
9983 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9985 pHalData->bt_coexist.CurrentState = 0;
9986 pHalData->bt_coexist.PreviousState = 0;
9989 static void btdm_InitBtCoexistDM(struct rtw_adapter *padapter)
9991 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9993 /* 20100415 Joseph: Restore RF register 0x1E and 0x1F value for further usage. */
9994 pHalData->bt_coexist.BtRfRegOrigin1E = PHY_QueryRFReg(padapter, PathA, RF_RCK1, bRFRegOffsetMask);
9995 pHalData->bt_coexist.BtRfRegOrigin1F = PHY_QueryRFReg(padapter, PathA, RF_RCK2, 0xf0);
9997 pHalData->bt_coexist.CurrentState = 0;
9998 pHalData->bt_coexist.PreviousState = 0;
10000 BTDM_8723AInit(padapter);
10001 pHalData->bt_coexist.bInitlized = true;
10005 /* extern function */
10007 void BTDM_CheckAntSelMode(struct rtw_adapter *padapter)
10011 void BTDM_FwC2hBtRssi(struct rtw_adapter *padapter, u8 *tmpBuf)
10013 BTDM_FwC2hBtRssi8723A(padapter, tmpBuf);
10016 void BTDM_DisplayBtCoexInfo(struct rtw_adapter *padapter)
10018 BTDM_Display8723ABtCoexInfo(padapter);
10021 void BTDM_RejectAPAggregatedPacket(struct rtw_adapter *padapter, u8 bReject)
10025 u8 BTDM_IsHT40(struct rtw_adapter *padapter)
10028 enum ht_channel_width bw;
10030 bw = padapter->mlmeextpriv.cur_bwmode;
10032 if (bw == HT_CHANNEL_WIDTH_20)
10034 else if (bw == HT_CHANNEL_WIDTH_40)
10040 u8 BTDM_Legacy(struct rtw_adapter *padapter)
10042 struct mlme_ext_priv *pmlmeext;
10043 u8 isLegacy = false;
10045 pmlmeext = &padapter->mlmeextpriv;
10046 if ((pmlmeext->cur_wireless_mode == WIRELESS_11B) ||
10047 (pmlmeext->cur_wireless_mode == WIRELESS_11G) ||
10048 (pmlmeext->cur_wireless_mode == WIRELESS_11BG))
10054 void BTDM_CheckWiFiState(struct rtw_adapter *padapter)
10056 struct hal_data_8723a *pHalData;
10057 struct mlme_priv *pmlmepriv;
10058 struct bt_30info *pBTInfo;
10059 struct bt_mgnt *pBtMgnt;
10061 pHalData = GET_HAL_DATA(padapter);
10062 pmlmepriv = &padapter->mlmepriv;
10063 pBTInfo = GET_BT_INFO(padapter);
10064 pBtMgnt = &pBTInfo->BtMgnt;
10066 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
10067 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_IDLE;
10069 if (pmlmepriv->LinkDetectInfo.bTxBusyTraffic)
10070 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_UPLINK;
10072 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10074 if (pmlmepriv->LinkDetectInfo.bRxBusyTraffic)
10075 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_DOWNLINK;
10077 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10079 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_IDLE;
10080 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10081 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10084 if (BTDM_Legacy(padapter)) {
10085 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_LEGACY;
10086 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10087 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10089 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_LEGACY;
10090 if (BTDM_IsHT40(padapter)) {
10091 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT40;
10092 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10094 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT20;
10095 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10099 if (pBtMgnt->BtOperationOn)
10100 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT30;
10102 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT30;
10105 s32 BTDM_GetRxSS(struct rtw_adapter *padapter)
10107 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10108 struct mlme_priv *pmlmepriv;
10109 struct hal_data_8723a *pHalData;
10110 s32 UndecoratedSmoothedPWDB = 0;
10112 pmlmepriv = &padapter->mlmepriv;
10113 pHalData = GET_HAL_DATA(padapter);
10115 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10116 UndecoratedSmoothedPWDB = GET_UNDECORATED_AVERAGE_RSSI(padapter);
10117 } else { /* associated entry pwdb */
10118 UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10119 /* pHalData->BT_EntryMinUndecoratedSmoothedPWDB */
10121 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxSS() = %d\n", UndecoratedSmoothedPWDB));
10122 return UndecoratedSmoothedPWDB;
10125 static s32 BTDM_GetRxBeaconSS(struct rtw_adapter *padapter)
10127 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10128 struct mlme_priv *pmlmepriv;
10129 struct hal_data_8723a *pHalData;
10130 s32 pwdbBeacon = 0;
10132 pmlmepriv = &padapter->mlmepriv;
10133 pHalData = GET_HAL_DATA(padapter);
10135 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10136 /* pwdbBeacon = pHalData->dmpriv.UndecoratedSmoothedBeacon; */
10137 pwdbBeacon = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10139 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxBeaconSS() = %d\n", pwdbBeacon));
10143 /* Get beacon rssi state */
10144 u8 BTDM_CheckCoexBcnRssiState(struct rtw_adapter *padapter, u8 levelNum,
10145 u8 RssiThresh, u8 RssiThresh1)
10147 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10148 s32 pwdbBeacon = 0;
10149 u8 bcnRssiState = 0;
10151 pwdbBeacon = BTDM_GetRxBeaconSS(padapter);
10153 if (levelNum == 2) {
10154 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10156 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10157 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10158 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10159 bcnRssiState = BT_RSSI_STATE_HIGH;
10160 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10161 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10162 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10164 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10165 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10168 if (pwdbBeacon < RssiThresh) {
10169 bcnRssiState = BT_RSSI_STATE_LOW;
10170 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10171 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10172 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10174 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10175 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10178 } else if (levelNum == 3) {
10179 if (RssiThresh > RssiThresh1) {
10180 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON thresh error!!\n"));
10181 return pHalData->bt_coexist.preRssiStateBeacon;
10184 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10185 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10186 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10187 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10188 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10189 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10190 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10191 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10193 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10194 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10196 } else if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_MEDIUM) ||
10197 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_MEDIUM)) {
10198 if (pwdbBeacon >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10199 bcnRssiState = BT_RSSI_STATE_HIGH;
10200 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10201 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10202 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10203 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10204 } else if (pwdbBeacon < RssiThresh) {
10205 bcnRssiState = BT_RSSI_STATE_LOW;
10206 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10207 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10208 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10209 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10211 bcnRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10212 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Medium\n"));
10215 if (pwdbBeacon < RssiThresh1) {
10216 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10217 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10218 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10219 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10220 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10222 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10223 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10228 pHalData->bt_coexist.preRssiStateBeacon = bcnRssiState;
10230 return bcnRssiState;
10233 u8 BTDM_CheckCoexRSSIState1(struct rtw_adapter *padapter, u8 levelNum,
10234 u8 RssiThresh, u8 RssiThresh1)
10236 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10237 s32 UndecoratedSmoothedPWDB = 0;
10238 u8 btRssiState = 0;
10240 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10242 if (levelNum == 2) {
10243 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10245 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10246 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10247 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10248 btRssiState = BT_RSSI_STATE_HIGH;
10249 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10250 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10251 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10253 btRssiState = BT_RSSI_STATE_STAY_LOW;
10254 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10257 if (UndecoratedSmoothedPWDB < RssiThresh) {
10258 btRssiState = BT_RSSI_STATE_LOW;
10259 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10260 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10261 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10263 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10264 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10267 } else if (levelNum == 3) {
10268 if (RssiThresh > RssiThresh1) {
10269 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 thresh error!!\n"));
10270 return pHalData->bt_coexist.preRssiState1;
10273 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10274 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10275 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10276 btRssiState = BT_RSSI_STATE_MEDIUM;
10277 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10278 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10279 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10280 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10282 btRssiState = BT_RSSI_STATE_STAY_LOW;
10283 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10285 } else if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_MEDIUM) ||
10286 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_MEDIUM)) {
10287 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10288 btRssiState = BT_RSSI_STATE_HIGH;
10289 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10290 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10291 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10292 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10293 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10294 btRssiState = BT_RSSI_STATE_LOW;
10295 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10296 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10297 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10298 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10300 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10301 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Medium\n"));
10304 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10305 btRssiState = BT_RSSI_STATE_MEDIUM;
10306 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10307 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10308 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10309 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10311 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10312 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10317 pHalData->bt_coexist.preRssiState1 = btRssiState;
10319 return btRssiState;
10322 u8 BTDM_CheckCoexRSSIState(struct rtw_adapter *padapter, u8 levelNum,
10323 u8 RssiThresh, u8 RssiThresh1)
10325 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10326 s32 UndecoratedSmoothedPWDB = 0;
10327 u8 btRssiState = 0;
10329 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10331 if (levelNum == 2) {
10332 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10334 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10335 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10336 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10337 btRssiState = BT_RSSI_STATE_HIGH;
10338 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10339 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10340 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10342 btRssiState = BT_RSSI_STATE_STAY_LOW;
10343 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10346 if (UndecoratedSmoothedPWDB < RssiThresh) {
10347 btRssiState = BT_RSSI_STATE_LOW;
10348 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10349 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10350 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10352 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10353 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10356 } else if (levelNum == 3) {
10357 if (RssiThresh > RssiThresh1) {
10358 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI thresh error!!\n"));
10359 return pHalData->bt_coexist.preRssiState;
10362 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10363 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10364 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10365 btRssiState = BT_RSSI_STATE_MEDIUM;
10366 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10367 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10368 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10369 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10371 btRssiState = BT_RSSI_STATE_STAY_LOW;
10372 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10374 } else if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_MEDIUM) ||
10375 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_MEDIUM)) {
10376 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10377 btRssiState = BT_RSSI_STATE_HIGH;
10378 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10379 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10380 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10381 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10382 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10383 btRssiState = BT_RSSI_STATE_LOW;
10384 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10385 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10386 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10387 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10389 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10390 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Medium\n"));
10393 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10394 btRssiState = BT_RSSI_STATE_MEDIUM;
10395 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10396 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10397 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10398 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10400 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10401 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10406 pHalData->bt_coexist.preRssiState = btRssiState;
10408 return btRssiState;
10411 bool rtl8723a_BT_disable_EDCA_turbo(struct rtw_adapter *padapter)
10413 struct bt_mgnt *pBtMgnt;
10414 struct hal_data_8723a *pHalData;
10415 u8 bBtChangeEDCA = false;
10416 u32 EDCA_BT_BE = 0x5ea42b, cur_EDCA_reg;
10419 pHalData = GET_HAL_DATA(padapter);
10420 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10422 if (!rtl8723a_BT_coexist(padapter)) {
10424 pHalData->bt_coexist.lastBtEdca = 0;
10427 if (!((pBtMgnt->bSupportProfile) ||
10428 (pHalData->bt_coexist.BT_CoexistType == BT_CSR_BC8))) {
10430 pHalData->bt_coexist.lastBtEdca = 0;
10434 if (rtl8723a_BT_using_antenna_1(padapter)) {
10436 pHalData->bt_coexist.lastBtEdca = 0;
10440 if (pHalData->bt_coexist.exec_cnt < 3)
10441 pHalData->bt_coexist.exec_cnt++;
10443 pHalData->bt_coexist.bEDCAInitialized = true;
10445 /* When BT is non idle */
10446 if (!(pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)) {
10447 RTPRINT(FBT, BT_TRACE, ("BT state non idle, set bt EDCA\n"));
10449 /* aggr_num = 0x0909; */
10450 if (pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA) {
10451 bBtChangeEDCA = true;
10452 pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA = false;
10453 pHalData->dmpriv.prv_traffic_idx = 3;
10455 cur_EDCA_reg = rtl8723au_read32(padapter, REG_EDCA_BE_PARAM);
10457 if (cur_EDCA_reg != EDCA_BT_BE)
10458 bBtChangeEDCA = true;
10459 if (bBtChangeEDCA || !pHalData->bt_coexist.bEDCAInitialized) {
10460 rtl8723au_write32(padapter, REG_EDCA_BE_PARAM,
10462 pHalData->bt_coexist.lastBtEdca = EDCA_BT_BE;
10466 RTPRINT(FBT, BT_TRACE, ("BT state idle, set original EDCA\n"));
10467 pHalData->bt_coexist.lastBtEdca = 0;
10475 struct rtw_adapter *padapter,
10481 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10482 u8 H2C_Parameter[3] = {0};
10485 H2C_Parameter[2] = 1;
10486 H2C_Parameter[1] = ms1;
10487 H2C_Parameter[0] = ms0;
10488 pHalData->bt_coexist.bFWCoexistAllOff = false;
10490 H2C_Parameter[2] = 0;
10491 H2C_Parameter[1] = 0;
10492 H2C_Parameter[0] = 0;
10494 pHalData->bt_coexist.bBalanceOn = bBalanceOn;
10496 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Balance =[%s:%dms:%dms], write 0xc = 0x%x\n",
10497 bBalanceOn?"ON":"OFF", ms0, ms1,
10498 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10500 FillH2CCmd(padapter, 0xc, 3, H2C_Parameter);
10503 void BTDM_AGCTable(struct rtw_adapter *padapter, u8 type)
10505 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10506 if (type == BT_AGCTABLE_OFF) {
10507 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable Off!\n"));
10508 rtl8723au_write32(padapter, 0xc78, 0x641c0001);
10509 rtl8723au_write32(padapter, 0xc78, 0x631d0001);
10510 rtl8723au_write32(padapter, 0xc78, 0x621e0001);
10511 rtl8723au_write32(padapter, 0xc78, 0x611f0001);
10512 rtl8723au_write32(padapter, 0xc78, 0x60200001);
10514 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x32000);
10515 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x71000);
10516 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xb0000);
10517 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xfc000);
10518 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x30355);
10520 pHalData->bt_coexist.b8723aAgcTableOn = false;
10521 } else if (type == BT_AGCTABLE_ON) {
10522 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable On!\n"));
10523 rtl8723au_write32(padapter, 0xc78, 0x4e1c0001);
10524 rtl8723au_write32(padapter, 0xc78, 0x4d1d0001);
10525 rtl8723au_write32(padapter, 0xc78, 0x4c1e0001);
10526 rtl8723au_write32(padapter, 0xc78, 0x4b1f0001);
10527 rtl8723au_write32(padapter, 0xc78, 0x4a200001);
10529 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xdc000);
10530 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x90000);
10531 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x51000);
10532 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x12000);
10533 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x00355);
10535 pHalData->bt_coexist.b8723aAgcTableOn = true;
10537 pHalData->bt_coexist.bSWCoexistAllOff = false;
10541 void BTDM_BBBackOffLevel(struct rtw_adapter *padapter, u8 type)
10543 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10545 if (type == BT_BB_BACKOFF_OFF) {
10546 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel Off!\n"));
10547 rtl8723au_write32(padapter, 0xc04, 0x3a05611);
10548 } else if (type == BT_BB_BACKOFF_ON) {
10549 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel On!\n"));
10550 rtl8723au_write32(padapter, 0xc04, 0x3a07611);
10551 pHalData->bt_coexist.bSWCoexistAllOff = false;
10555 void BTDM_FWCoexAllOff(struct rtw_adapter *padapter)
10557 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10559 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff()\n"));
10560 if (pHalData->bt_coexist.bFWCoexistAllOff)
10562 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff(), real Do\n"));
10564 BTDM_FWCoexAllOff8723A(padapter);
10566 pHalData->bt_coexist.bFWCoexistAllOff = true;
10569 void BTDM_SWCoexAllOff(struct rtw_adapter *padapter)
10571 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10573 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff()\n"));
10574 if (pHalData->bt_coexist.bSWCoexistAllOff)
10576 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff(), real Do\n"));
10577 BTDM_SWCoexAllOff8723A(padapter);
10579 pHalData->bt_coexist.bSWCoexistAllOff = true;
10582 void BTDM_HWCoexAllOff(struct rtw_adapter *padapter)
10584 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10586 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff()\n"));
10587 if (pHalData->bt_coexist.bHWCoexistAllOff)
10589 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff(), real Do\n"));
10591 BTDM_HWCoexAllOff8723A(padapter);
10593 pHalData->bt_coexist.bHWCoexistAllOff = true;
10596 void BTDM_CoexAllOff(struct rtw_adapter *padapter)
10598 BTDM_FWCoexAllOff(padapter);
10599 BTDM_SWCoexAllOff(padapter);
10600 BTDM_HWCoexAllOff(padapter);
10603 void rtl8723a_BT_disable_coexist(struct rtw_adapter *padapter)
10605 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
10607 if (!rtl8723a_BT_coexist(padapter))
10610 /* 8723 1Ant doesn't need to turn off bt coexist mechanism. */
10611 if (rtl8723a_BT_using_antenna_1(padapter))
10614 /* Before enter IPS, turn off FW BT Co-exist mechanism */
10615 if (ppwrctrl->reg_rfoff == rf_on) {
10616 RTPRINT(FBT, BT_TRACE, ("[BT][DM], Before enter IPS, turn off all Coexist DM\n"));
10617 btdm_ResetFWCoexState(padapter);
10618 BTDM_CoexAllOff(padapter);
10619 BTDM_SetAntenna(padapter, BTDM_ANT_BT);
10623 void BTDM_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
10625 BTDM_8723ASignalCompensation(padapter, rssi_wifi, rssi_bt);
10628 void rtl8723a_BT_do_coexist(struct rtw_adapter *padapter)
10630 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10632 if (!rtl8723a_BT_coexist(padapter)) {
10633 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT not exists!!\n"));
10637 if (!pHalData->bt_coexist.bInitlized) {
10638 RTPRINT(FBT, BT_TRACE, ("[DM][BT], btdm_InitBtCoexistDM()\n"));
10639 btdm_InitBtCoexistDM(padapter);
10642 RTPRINT(FBT, BT_TRACE, ("\n\n[DM][BT], BTDM start!!\n"));
10644 BTDM_PWDBMonitor(padapter);
10646 RTPRINT(FBT, BT_TRACE, ("[DM][BT], HW type is 8723\n"));
10647 BTDM_BTCoexist8723A(padapter);
10648 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BTDM end!!\n\n"));
10651 void BTDM_UpdateCoexState(struct rtw_adapter *padapter)
10653 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10655 if (!BTDM_IsSameCoexistState(padapter)) {
10656 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x, changeBits = 0x%"i64fmt"x\n",
10657 pHalData->bt_coexist.PreviousState,
10658 pHalData->bt_coexist.CurrentState,
10659 (pHalData->bt_coexist.PreviousState^pHalData->bt_coexist.CurrentState)));
10660 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
10664 u8 BTDM_IsSameCoexistState(struct rtw_adapter *padapter)
10666 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10668 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState) {
10671 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Coexist state changed!!\n"));
10676 void BTDM_PWDBMonitor(struct rtw_adapter *padapter)
10678 struct bt_30info *pBTInfo = GET_BT_INFO(GetDefaultAdapter(padapter));
10679 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10680 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10681 u8 H2C_Parameter[3] = {0};
10682 s32 tmpBTEntryMaxPWDB = 0, tmpBTEntryMinPWDB = 0xff;
10685 if (pBtMgnt->BtOperationOn) {
10686 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
10687 if (pBTInfo->BtAsocEntry[i].bUsed) {
10688 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB < tmpBTEntryMinPWDB)
10689 tmpBTEntryMinPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10690 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB > tmpBTEntryMaxPWDB)
10691 tmpBTEntryMaxPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10692 /* Report every BT connection (HS mode) RSSI to FW */
10693 H2C_Parameter[2] = (u8)(pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB & 0xFF);
10694 H2C_Parameter[0] = (MAX_FW_SUPPORT_MACID_NUM-1-i);
10695 RTPRINT(FDM, DM_BT30, ("RSSI report for BT[%d], H2C_Par = 0x%x\n", i, H2C_Parameter[0]));
10696 FillH2CCmd(padapter, RSSI_SETTING_EID, 3, H2C_Parameter);
10697 RTPRINT_ADDR(FDM, (DM_PWDB|DM_BT30), ("BT_Entry Mac :"),
10698 pBTInfo->BtAsocEntry[i].BTRemoteMACAddr)
10699 RTPRINT(FDM, (DM_PWDB|DM_BT30),
10700 ("BT rx pwdb[%d] = 0x%x(%d)\n", i,
10701 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB,
10702 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB));
10705 if (tmpBTEntryMaxPWDB != 0) { /* If associated entry is found */
10706 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = tmpBTEntryMaxPWDB;
10707 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMaxPWDB = 0x%x(%d)\n",
10708 tmpBTEntryMaxPWDB, tmpBTEntryMaxPWDB));
10710 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = 0;
10712 if (tmpBTEntryMinPWDB != 0xff) { /* If associated entry is found */
10713 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = tmpBTEntryMinPWDB;
10714 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMinPWDB = 0x%x(%d)\n",
10715 tmpBTEntryMinPWDB, tmpBTEntryMinPWDB));
10717 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = 0;
10722 u8 BTDM_IsBTBusy(struct rtw_adapter *padapter)
10724 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10725 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10727 if (pBtMgnt->ExtConfig.bBTBusy)
10733 u8 BTDM_IsWifiBusy(struct rtw_adapter *padapter)
10735 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10736 struct mlme_priv *pmlmepriv = &GetDefaultAdapter(padapter)->mlmepriv;
10737 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10738 struct bt_traffic *pBtTraffic = &pBTInfo->BtTraffic;
10740 if (pmlmepriv->LinkDetectInfo.bBusyTraffic ||
10741 pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic ||
10742 pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic)
10748 u8 BTDM_IsCoexistStateChanged(struct rtw_adapter *padapter)
10750 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10752 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState)
10758 u8 BTDM_IsWifiUplink(struct rtw_adapter *padapter)
10760 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10761 struct mlme_priv *pmlmepriv;
10762 struct bt_30info *pBTInfo;
10763 struct bt_traffic *pBtTraffic;
10765 pmlmepriv = &padapter->mlmepriv;
10766 pBTInfo = GET_BT_INFO(padapter);
10767 pBtTraffic = &pBTInfo->BtTraffic;
10769 if ((pmlmepriv->LinkDetectInfo.bTxBusyTraffic) ||
10770 (pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic))
10776 u8 BTDM_IsWifiDownlink(struct rtw_adapter *padapter)
10778 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10779 struct mlme_priv *pmlmepriv;
10780 struct bt_30info *pBTInfo;
10781 struct bt_traffic *pBtTraffic;
10783 pmlmepriv = &padapter->mlmepriv;
10784 pBTInfo = GET_BT_INFO(padapter);
10785 pBtTraffic = &pBTInfo->BtTraffic;
10787 if ((pmlmepriv->LinkDetectInfo.bRxBusyTraffic) ||
10788 (pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic))
10794 u8 BTDM_IsBTHSMode(struct rtw_adapter *padapter)
10796 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10797 struct hal_data_8723a *pHalData;
10798 struct bt_mgnt *pBtMgnt;
10800 pHalData = GET_HAL_DATA(padapter);
10801 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10803 if (pBtMgnt->BtOperationOn)
10809 u8 BTDM_IsBTUplink(struct rtw_adapter *padapter)
10811 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10813 if (pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic)
10819 u8 BTDM_IsBTDownlink(struct rtw_adapter *padapter)
10821 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10823 if (pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic)
10829 void BTDM_AdjustForBtOperation(struct rtw_adapter *padapter)
10831 RTPRINT(FBT, BT_TRACE, ("[BT][DM], BTDM_AdjustForBtOperation()\n"));
10832 BTDM_AdjustForBtOperation8723A(padapter);
10835 void BTDM_SetBtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
10837 BTDM_Set8723ABtCoexCurrAntNum(padapter, antNum);
10840 void BTDM_ForHalt(struct rtw_adapter *padapter)
10842 if (!rtl8723a_BT_coexist(padapter))
10845 BTDM_ForHalt8723A(padapter);
10846 GET_HAL_DATA(padapter)->bt_coexist.bInitlized = false;
10849 void BTDM_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
10851 if (!rtl8723a_BT_coexist(padapter))
10854 BTDM_WifiScanNotify8723A(padapter, scanType);
10857 void BTDM_WifiAssociateNotify(struct rtw_adapter *padapter, u8 action)
10859 if (!rtl8723a_BT_coexist(padapter))
10862 BTDM_WifiAssociateNotify8723A(padapter, action);
10865 void rtl8723a_BT_mediastatus_notify(struct rtw_adapter *padapter,
10866 enum rt_media_status mstatus)
10868 if (!rtl8723a_BT_coexist(padapter))
10871 BTDM_MediaStatusNotify8723A(padapter, mstatus);
10874 void rtl8723a_BT_specialpacket_notify(struct rtw_adapter *padapter)
10876 if (!rtl8723a_BT_coexist(padapter))
10879 BTDM_ForDhcp8723A(padapter);
10882 void BTDM_ResetActionProfileState(struct rtw_adapter *padapter)
10884 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10886 pHalData->bt_coexist.CurrentState &= ~\
10887 (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP|
10888 BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_SCO);
10891 u8 BTDM_IsActionSCO(struct rtw_adapter *padapter)
10893 struct hal_data_8723a *pHalData;
10894 struct bt_30info *pBTInfo;
10895 struct bt_mgnt *pBtMgnt;
10896 struct bt_dgb *pBtDbg;
10899 pHalData = GET_HAL_DATA(padapter);
10900 pBTInfo = GET_BT_INFO(padapter);
10901 pBtMgnt = &pBTInfo->BtMgnt;
10902 pBtDbg = &pBTInfo->BtDbg;
10905 if (pBtDbg->dbgCtrl) {
10906 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_SCO) {
10907 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
10911 if (pBtMgnt->ExtConfig.NumberOfSCO > 0) {
10912 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
10919 u8 BTDM_IsActionHID(struct rtw_adapter *padapter)
10921 struct bt_30info *pBTInfo;
10922 struct hal_data_8723a *pHalData;
10923 struct bt_mgnt *pBtMgnt;
10924 struct bt_dgb *pBtDbg;
10927 pHalData = GET_HAL_DATA(padapter);
10928 pBTInfo = GET_BT_INFO(padapter);
10929 pBtMgnt = &pBTInfo->BtMgnt;
10930 pBtDbg = &pBTInfo->BtDbg;
10933 if (pBtDbg->dbgCtrl) {
10934 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID) {
10935 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
10939 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
10940 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
10941 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
10948 u8 BTDM_IsActionA2DP(struct rtw_adapter *padapter)
10950 struct hal_data_8723a *pHalData;
10951 struct bt_30info *pBTInfo;
10952 struct bt_mgnt *pBtMgnt;
10953 struct bt_dgb *pBtDbg;
10956 pHalData = GET_HAL_DATA(padapter);
10957 pBTInfo = GET_BT_INFO(padapter);
10958 pBtMgnt = &pBTInfo->BtMgnt;
10959 pBtDbg = &pBTInfo->BtDbg;
10962 if (pBtDbg->dbgCtrl) {
10963 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_A2DP) {
10964 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
10968 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP) &&
10969 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
10970 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
10977 u8 BTDM_IsActionPAN(struct rtw_adapter *padapter)
10979 struct hal_data_8723a *pHalData;
10980 struct bt_30info *pBTInfo;
10981 struct bt_mgnt *pBtMgnt;
10982 struct bt_dgb *pBtDbg;
10985 pHalData = GET_HAL_DATA(padapter);
10986 pBTInfo = GET_BT_INFO(padapter);
10987 pBtMgnt = &pBTInfo->BtMgnt;
10988 pBtDbg = &pBTInfo->BtDbg;
10991 if (pBtDbg->dbgCtrl) {
10992 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN) {
10993 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
10997 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
10998 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
10999 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11006 u8 BTDM_IsActionHIDA2DP(struct rtw_adapter *padapter)
11008 struct hal_data_8723a *pHalData;
11009 struct bt_30info *pBTInfo;
11010 struct bt_mgnt *pBtMgnt;
11011 struct bt_dgb *pBtDbg;
11014 pHalData = GET_HAL_DATA(padapter);
11015 pBTInfo = GET_BT_INFO(padapter);
11016 pBtMgnt = &pBTInfo->BtMgnt;
11017 pBtDbg = &pBTInfo->BtDbg;
11020 if (pBtDbg->dbgCtrl) {
11021 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_A2DP) {
11022 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11026 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11027 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11028 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11035 u8 BTDM_IsActionHIDPAN(struct rtw_adapter *padapter)
11037 struct hal_data_8723a *pHalData;
11038 struct bt_30info *pBTInfo;
11039 struct bt_dgb *pBtDbg;
11042 pHalData = GET_HAL_DATA(padapter);
11043 pBTInfo = GET_BT_INFO(padapter);
11044 pBtDbg = &pBTInfo->BtDbg;
11047 if (pBtDbg->dbgCtrl) {
11048 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_PAN) {
11049 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11053 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11054 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
11055 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11062 u8 BTDM_IsActionPANA2DP(struct rtw_adapter *padapter)
11064 struct hal_data_8723a *pHalData;
11065 struct bt_30info *pBTInfo;
11066 struct bt_dgb *pBtDbg;
11069 pHalData = GET_HAL_DATA(padapter);
11070 pBTInfo = GET_BT_INFO(padapter);
11071 pBtDbg = &pBTInfo->BtDbg;
11074 if (pBtDbg->dbgCtrl) {
11075 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN_A2DP) {
11076 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11080 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) && BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11081 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11088 bool rtl8723a_BT_enabled(struct rtw_adapter *padapter)
11090 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11092 if (pHalData->bt_coexist.bCurBtDisabled)
11098 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
11100 /* ===== Below this line is sync from SD7 driver HAL/HalBT.c ===== */
11103 /*local function */
11106 static void halbt_InitHwConfig8723A(struct rtw_adapter *padapter)
11111 /*extern function */
11113 u8 HALBT_GetPGAntNum(struct rtw_adapter *padapter)
11115 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11117 return pHalData->bt_coexist.BT_Ant_Num;
11120 void HALBT_SetKey(struct rtw_adapter *padapter, u8 EntryNum)
11122 struct bt_30info *pBTinfo;
11123 struct bt_asoc_entry *pBtAssocEntry;
11126 pBTinfo = GET_BT_INFO(padapter);
11127 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11129 pBtAssocEntry->HwCAMIndex = BT_HWCAM_STAR + EntryNum;
11131 usConfig = CAM_VALID | (CAM_AES << 2);
11132 rtl8723a_cam_write(padapter, pBtAssocEntry->HwCAMIndex, usConfig,
11133 pBtAssocEntry->BTRemoteMACAddr,
11134 pBtAssocEntry->PTK + TKIP_ENC_KEY_POS);
11137 void HALBT_RemoveKey(struct rtw_adapter *padapter, u8 EntryNum)
11139 struct bt_30info *pBTinfo;
11140 struct bt_asoc_entry *pBtAssocEntry;
11142 pBTinfo = GET_BT_INFO(padapter);
11143 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11145 if (pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex != 0) {
11146 /* ToDo : add New HALBT_RemoveKey function !! */
11147 if (pBtAssocEntry->HwCAMIndex >= BT_HWCAM_STAR &&
11148 pBtAssocEntry->HwCAMIndex < HALF_CAM_ENTRY)
11149 rtl8723a_cam_empty_entry(padapter,
11150 pBtAssocEntry->HwCAMIndex);
11151 pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex = 0;
11155 void rtl8723a_BT_init_hal_vars(struct rtw_adapter *padapter)
11157 struct hal_data_8723a *pHalData;
11159 pHalData = GET_HAL_DATA(padapter);
11161 pHalData->bt_coexist.BluetoothCoexist = pHalData->EEPROMBluetoothCoexist;
11162 pHalData->bt_coexist.BT_Ant_Num = pHalData->EEPROMBluetoothAntNum;
11163 pHalData->bt_coexist.BT_CoexistType = pHalData->EEPROMBluetoothType;
11164 pHalData->bt_coexist.BT_Ant_isolation = pHalData->EEPROMBluetoothAntIsolation;
11165 pHalData->bt_coexist.bt_radiosharedtype = pHalData->EEPROMBluetoothRadioShared;
11167 RT_TRACE(_module_hal_init_c_, _drv_info_,
11168 "BT Coexistance = 0x%x\n", rtl8723a_BT_coexist(padapter));
11170 if (rtl8723a_BT_coexist(padapter)) {
11171 if (pHalData->bt_coexist.BT_Ant_Num == Ant_x2) {
11172 BTDM_SetBtCoexCurrAntNum(padapter, 2);
11173 RT_TRACE(_module_hal_init_c_, _drv_info_,
11174 "BlueTooth BT_Ant_Num = Antx2\n");
11175 } else if (pHalData->bt_coexist.BT_Ant_Num == Ant_x1) {
11176 BTDM_SetBtCoexCurrAntNum(padapter, 1);
11177 RT_TRACE(_module_hal_init_c_, _drv_info_,
11178 "BlueTooth BT_Ant_Num = Antx1\n");
11180 pHalData->bt_coexist.bBTBusyTraffic = false;
11181 pHalData->bt_coexist.bBTTrafficModeSet = false;
11182 pHalData->bt_coexist.bBTNonTrafficModeSet = false;
11183 pHalData->bt_coexist.CurrentState = 0;
11184 pHalData->bt_coexist.PreviousState = 0;
11186 RT_TRACE(_module_hal_init_c_, _drv_info_,
11187 "bt_radiosharedType = 0x%x\n",
11188 pHalData->bt_coexist.bt_radiosharedtype);
11192 bool rtl8723a_BT_coexist(struct rtw_adapter *padapter)
11194 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11196 if (pHalData->bt_coexist.BluetoothCoexist)
11202 u8 HALBT_BTChipType(struct rtw_adapter *padapter)
11204 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11206 return pHalData->bt_coexist.BT_CoexistType;
11209 void rtl8723a_BT_init_hwconfig(struct rtw_adapter *padapter)
11211 halbt_InitHwConfig8723A(padapter);
11212 rtl8723a_BT_do_coexist(padapter);
11215 void HALBT_SetRtsCtsNoLenLimit(struct rtw_adapter *padapter)
11219 /* ===== End of sync from SD7 driver HAL/HalBT.c ===== */
11221 void rtl8723a_dual_antenna_detection(struct rtw_adapter *padapter)
11223 struct hal_data_8723a *pHalData;
11224 struct dm_odm_t *pDM_Odm;
11225 struct sw_ant_sw *pDM_SWAT_Table;
11228 pHalData = GET_HAL_DATA(padapter);
11229 pDM_Odm = &pHalData->odmpriv;
11230 pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
11233 /* <Roger_Notes> RTL8723A Single and Dual antenna dynamic detection
11234 mechanism when RF power state is on. */
11235 /* We should take power tracking, IQK, LCK, RCK RF read/write
11236 operation into consideration. */
11239 if (!pHalData->bAntennaDetected) {
11240 u8 btAntNum = BT_GetPGAntNum(padapter);
11242 /* Set default antenna B status */
11243 if (btAntNum == Ant_x2)
11244 pDM_SWAT_Table->ANTB_ON = true;
11245 else if (btAntNum == Ant_x1)
11246 pDM_SWAT_Table->ANTB_ON = false;
11248 pDM_SWAT_Table->ANTB_ON = true;
11250 if (pHalData->CustomerID != RT_CID_TOSHIBA) {
11251 for (i = 0; i < MAX_ANTENNA_DETECTION_CNT; i++) {
11252 if (ODM_SingleDualAntennaDetection
11253 (&pHalData->odmpriv, ANTTESTALL) == true)
11257 /* Set default antenna number for BT coexistence */
11258 if (btAntNum == Ant_x2)
11259 BT_SetBtCoexCurrAntNum(padapter,
11263 pHalData->bAntennaDetected = true;