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(...)
75 #define rsprintf snprintf
77 #define GetDefaultAdapter(padapter) padapter
79 #define PlatformZeroMemory(ptr, sz) memset(ptr, 0, sz)
81 #define PlatformProcessHCICommands(...)
82 #define PlatformTxBTQueuedPackets(...)
83 #define PlatformIndicateBTACLData(...) (RT_STATUS_SUCCESS)
84 #define PlatformAcquireSpinLock(padapter, type)
85 #define PlatformReleaseSpinLock(padapter, type)
87 #define GET_UNDECORATED_AVERAGE_RSSI(padapter) \
88 (GET_HAL_DATA(padapter)->dmpriv.EntryMinUndecoratedSmoothedPWDB)
89 #define RT_RF_CHANGE_SOURCE u32
100 /* ===== Below this line is sync from SD7 driver COMMOM/BT.c ===== */
102 static u8 BT_Operation(struct rtw_adapter *padapter)
104 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
105 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
107 if (pBtMgnt->BtOperationOn)
113 static u8 BT_IsLegalChannel(struct rtw_adapter *padapter, u8 channel)
115 struct rt_channel_info *pChanneList = NULL;
118 pChanneList = padapter->mlmeextpriv.channel_set;
119 channelLen = padapter->mlmeextpriv.max_chan_nums;
121 for (i = 0; i < channelLen; i++) {
122 RTPRINT(FIOCTL, IOCTL_STATE,
123 ("Check if chnl(%d) in channel plan contains bt target chnl(%d) for BT connection\n",
124 pChanneList[i].ChannelNum, channel));
125 if ((channel == pChanneList[i].ChannelNum) ||
126 (channel == pChanneList[i].ChannelNum + 2))
132 void BT_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
134 BTDM_SignalCompensation(padapter, rssi_wifi, rssi_bt);
137 void rtl8723a_BT_wifiscan_notify(struct rtw_adapter *padapter, u8 scanType)
139 BTHCI_WifiScanNotify(padapter, scanType);
140 BTDM_CheckAntSelMode(padapter);
141 BTDM_WifiScanNotify(padapter, scanType);
144 void rtl8723a_BT_wifiassociate_notify(struct rtw_adapter *padapter, u8 action)
147 /* true = associate start */
148 /* false = associate finished */
150 BTDM_CheckAntSelMode(padapter);
152 BTDM_WifiAssociateNotify(padapter, action);
155 void BT_HaltProcess(struct rtw_adapter *padapter)
157 BTDM_ForHalt(padapter);
160 /* ===== End of sync from SD7 driver COMMOM/BT.c ===== */
163 #define UINT64_C(v) (v)
165 #define FillOctetString(_os, _octet, _len) \
166 (_os).Octet = (u8 *)(_octet); \
167 (_os).Length = (_len);
169 static enum rt_status PlatformIndicateBTEvent(
170 struct rtw_adapter *padapter,
175 enum rt_status rt_status = RT_STATUS_FAILURE;
177 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event start, %d bytes data to Transferred!!\n", dataLen));
178 RTPRINT_DATA(FIOCTL, IOCTL_BT_EVENT_DETAIL, "To transfer Hex Data :\n",
181 BT_EventParse(padapter, pEvntData, dataLen);
183 printk(KERN_WARNING "%s: Linux has no way to report BT event!!\n", __func__);
185 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event end, %s\n",
186 (rt_status == RT_STATUS_SUCCESS) ? "SUCCESS" : "FAIL"));
191 /* ===== Below this line is sync from SD7 driver COMMOM/bt_hci.c ===== */
193 static u8 bthci_GetLocalChannel(struct rtw_adapter *padapter)
195 return padapter->mlmeextpriv.cur_channel;
198 static u8 bthci_GetCurrentEntryNum(struct rtw_adapter *padapter, u8 PhyHandle)
200 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
203 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
204 if ((pBTInfo->BtAsocEntry[i].bUsed) &&
205 (pBTInfo->BtAsocEntry[i].PhyLinkCmdData.BtPhyLinkhandle == PhyHandle))
212 static void bthci_DecideBTChannel(struct rtw_adapter *padapter, u8 EntryNum)
214 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
215 struct mlme_priv *pmlmepriv;
216 struct bt_30info *pBTInfo;
217 struct bt_mgnt *pBtMgnt;
218 struct bt_hci_info *pBtHciInfo;
219 struct chnl_txpower_triple *pTriple_subband = NULL;
220 struct common_triple *pTriple;
221 u8 i, j, localchnl, firstRemoteLegalChnlInTriplet = 0;
222 u8 regulatory_skipLen = 0;
223 u8 subbandTripletCnt = 0;
225 pmlmepriv = &padapter->mlmepriv;
226 pBTInfo = GET_BT_INFO(padapter);
227 pBtMgnt = &pBTInfo->BtMgnt;
228 pBtHciInfo = &pBTInfo->BtHciInfo;
230 pBtMgnt->CheckChnlIsSuit = true;
231 localchnl = bthci_GetLocalChannel(padapter);
233 pTriple = (struct common_triple *)
234 &pBtHciInfo->BTPreChnllist[COUNTRY_STR_LEN];
236 /* contains country string, len is 3 */
237 for (i = 0; i < (pBtHciInfo->BtPreChnlListLen-COUNTRY_STR_LEN); i += 3, pTriple++) {
239 /* check every triplet, an triplet may be */
240 /* regulatory extension identifier or sub-band triplet */
242 if (pTriple->byte_1st == 0xc9) {
243 /* Regulatory Extension Identifier, skip it */
244 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
245 ("Find Regulatory ID, regulatory class = %d\n", pTriple->byte_2nd));
246 regulatory_skipLen += 3;
247 pTriple_subband = NULL;
249 } else { /* Sub-band triplet */
250 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Find Sub-band triplet \n"));
252 pTriple_subband = (struct chnl_txpower_triple *)pTriple;
253 /* if remote first legal channel not found, then find first remote channel */
254 /* and it's legal for our channel plan. */
256 /* search the sub-band triplet and find if remote channel is legal to our channel plan. */
257 for (j = pTriple_subband->FirstChnl; j < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls); j++) {
258 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), (" Check if chnl(%d) is legal\n", j));
259 if (BT_IsLegalChannel(padapter, j)) {
260 /* remote channel is legal for our channel plan. */
261 firstRemoteLegalChnlInTriplet = j;
262 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
263 ("Find first remote legal channel : %d\n",
264 firstRemoteLegalChnlInTriplet));
266 /* If we find a remote legal channel in the sub-band triplet */
267 /* and only BT connection is established(local not connect to any AP or IBSS), */
268 /* then we just switch channel to remote channel. */
269 if (!(check_fwstate(pmlmepriv, WIFI_ASOC_STATE|WIFI_ADHOC_STATE|WIFI_AP_STATE) ||
270 BTHCI_HsConnectionEstablished(padapter))) {
271 pBtMgnt->BTChannel = firstRemoteLegalChnlInTriplet;
272 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Remote legal channel (%d) is selected, Local not connect to any!!\n", pBtMgnt->BTChannel));
275 if ((localchnl >= firstRemoteLegalChnlInTriplet) &&
276 (localchnl < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls))) {
277 pBtMgnt->BTChannel = localchnl;
278 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected, wifi or BT connection exists\n", pBtMgnt->BTChannel));
288 if (subbandTripletCnt) {
289 /* if any preferred channel triplet exists */
290 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("There are %d sub band triplet exists, ", subbandTripletCnt));
291 if (firstRemoteLegalChnlInTriplet == 0) {
292 /* no legal channel is found, reject the connection. */
293 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("no legal channel is found!!\n"));
295 /* Remote Legal channel is found but not match to local */
296 /* wifi connection exists), so reject the connection. */
297 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
298 ("Remote Legal channel is found but not match to local(wifi connection exists)!!\n"));
300 pBtMgnt->CheckChnlIsSuit = false;
302 /* There are not any preferred channel triplet exists */
303 /* Use current legal channel as the bt channel. */
304 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("No sub band triplet exists!!\n"));
306 pBtMgnt->BTChannel = localchnl;
307 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected!!\n", pBtMgnt->BTChannel));
310 /* Success:return true */
311 /* Fail:return false */
312 static u8 bthci_GetAssocInfo(struct rtw_adapter *padapter, u8 EntryNum)
314 struct bt_30info *pBTInfo;
315 struct bt_hci_info *pBtHciInfo;
318 u8 BaseMemoryShift = 0;
320 struct amp_assoc_structure *pAmpAsoc;
322 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo start\n"));
323 pBTInfo = GET_BT_INFO(padapter);
324 pBtHciInfo = &pBTInfo->BtHciInfo;
326 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar == 0) {
327 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen < (MAX_AMP_ASSOC_FRAG_LEN))
328 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen;
329 else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen == (MAX_AMP_ASSOC_FRAG_LEN))
330 TotalLen = MAX_AMP_ASSOC_FRAG_LEN;
331 } else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar > 0)
332 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar;
334 while ((pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar >= BaseMemoryShift) || TotalLen > BaseMemoryShift) {
335 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("GetAssocInfo, TotalLen =%d, BaseMemoryShift =%d\n", TotalLen, BaseMemoryShift));
337 (u8 *)pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment+BaseMemoryShift,
338 TotalLen-BaseMemoryShift);
339 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, "GetAssocInfo :\n",
340 tempBuf, TotalLen-BaseMemoryShift);
342 pAmpAsoc = (struct amp_assoc_structure *)tempBuf;
343 pAmpAsoc->Length = le16_to_cpu(pAmpAsoc->Length);
344 BaseMemoryShift += 3 + pAmpAsoc->Length;
346 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TypeID = 0x%x, ", pAmpAsoc->TypeID));
347 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Hex Data: \n", pAmpAsoc->Data, pAmpAsoc->Length);
348 switch (pAmpAsoc->TypeID) {
350 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_MAC_ADDR\n"));
351 if (pAmpAsoc->Length > 6)
353 memcpy(pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, pAmpAsoc->Data, 6);
354 RTPRINT_ADDR(FIOCTL, IOCTL_BT_HCICMD, ("Remote Mac address \n"), pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr);
356 case AMP_PREFERRED_CHANNEL_LIST:
357 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_PREFERRED_CHANNEL_LIST\n"));
358 pBtHciInfo->BtPreChnlListLen = pAmpAsoc->Length;
359 memcpy(pBtHciInfo->BTPreChnllist,
361 pBtHciInfo->BtPreChnlListLen);
362 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Preferred channel list : \n", pBtHciInfo->BTPreChnllist, pBtHciInfo->BtPreChnlListLen);
363 bthci_DecideBTChannel(padapter, EntryNum);
365 case AMP_CONNECTED_CHANNEL:
366 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_CONNECTED_CHANNEL\n"));
367 pBtHciInfo->BTConnectChnlListLen = pAmpAsoc->Length;
368 memcpy(pBtHciInfo->BTConnectChnllist,
370 pBtHciInfo->BTConnectChnlListLen);
372 case AMP_80211_PAL_CAP_LIST:
373 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_80211_PAL_CAP_LIST\n"));
374 pBTInfo->BtAsocEntry[EntryNum].BTCapability = *(u32 *)(pAmpAsoc->Data);
375 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000001) {
378 /* Signifies PAL capable of utilizing received activity reports. */
380 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000002) {
382 /* Signifies PAL is capable of utilizing scheduling information received in an activity reports. */
385 case AMP_80211_PAL_VISION:
386 pBtHciInfo->BTPalVersion = *(u8 *)(pAmpAsoc->Data);
387 pBtHciInfo->BTPalCompanyID = *(u16 *)(((u8 *)(pAmpAsoc->Data))+1);
388 pBtHciInfo->BTPalsubversion = *(u16 *)(((u8 *)(pAmpAsoc->Data))+3);
389 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("==> AMP_80211_PAL_VISION PalVersion 0x%x, PalCompanyID 0x%x, Palsubversion 0x%x\n",
390 pBtHciInfo->BTPalVersion,
391 pBtHciInfo->BTPalCompanyID,
392 pBtHciInfo->BTPalsubversion));
395 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> Unsupport TypeID !!\n"));
400 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo end\n"));
405 static u8 bthci_AddEntry(struct rtw_adapter *padapter)
407 struct bt_30info *pBTInfo;
408 struct bt_mgnt *pBtMgnt;
411 pBTInfo = GET_BT_INFO(padapter);
412 pBtMgnt = &pBTInfo->BtMgnt;
414 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
415 if (pBTInfo->BtAsocEntry[i].bUsed == false) {
416 pBTInfo->BtAsocEntry[i].bUsed = true;
417 pBtMgnt->CurrentConnectEntryNum = i;
422 if (i == MAX_BT_ASOC_ENTRY_NUM) {
423 RTPRINT(FIOCTL, IOCTL_STATE, ("bthci_AddEntry(), Add entry fail!!\n"));
429 static u8 bthci_DiscardTxPackets(struct rtw_adapter *padapter, u16 LLH)
435 bthci_CheckLogLinkBehavior(
436 struct rtw_adapter *padapter,
437 struct hci_flow_spec TxFlowSpec
440 u8 ID = TxFlowSpec.Identifier;
441 u8 ServiceType = TxFlowSpec.ServiceType;
442 u16 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
443 u32 SDUInterArrivatime = TxFlowSpec.SDUInterArrivalTime;
448 if (ServiceType == BT_LL_BE) {
450 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX best effort flowspec\n"));
451 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 0xffff)) {
453 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed latency flowspec\n"));
454 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
455 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed Large latency flowspec\n"));
459 if (ServiceType == BT_LL_BE) {
461 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX best effort flowspec\n"));
466 if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 1492)) {
468 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed latency flowspec\n"));
469 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
470 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed Large latency flowspec\n"));
474 if (ServiceType == BT_LL_BE) {
475 if ((SDUInterArrivatime == 0xffffffff) && (ServiceType == BT_LL_BE) && (MaxSDUSize == 1492)) {
477 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX aggregated best effort flowspec\n"));
479 } else if (ServiceType == BT_LL_GU) {
480 if (SDUInterArrivatime == 100) {
482 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX guaranteed bandwidth flowspec\n"));
487 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = Unknow Type !!!!!!!!\n"));
491 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
492 ("ID = 0x%x, ServiceType = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, AccessLatency = 0x%x, FlushTimeout = 0x%x\n",
493 TxFlowSpec.Identifier, TxFlowSpec.ServiceType, MaxSDUSize,
494 SDUInterArrivatime, TxFlowSpec.AccessLatency, TxFlowSpec.FlushTimeout));
498 static u16 bthci_AssocMACAddr(struct rtw_adapter *padapter, void *pbuf)
500 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
501 pAssoStrc->TypeID = AMP_MAC_ADDR;
502 pAssoStrc->Length = 0x06;
503 memcpy(&pAssoStrc->Data[0], padapter->eeprompriv.mac_addr, 6);
504 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
505 ("AssocMACAddr : \n"), pAssoStrc, pAssoStrc->Length+3);
507 return pAssoStrc->Length + 3;
511 bthci_PALCapabilities(
512 struct rtw_adapter *padapter,
516 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
518 pAssoStrc->TypeID = AMP_80211_PAL_CAP_LIST;
519 pAssoStrc->Length = 0x04;
521 pAssoStrc->Data[0] = 0x00;
522 pAssoStrc->Data[1] = 0x00;
524 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("PALCapabilities:\n"), pAssoStrc, pAssoStrc->Length+3);
525 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("PALCapabilities \n"));
527 RTPRINT(FIOCTL, IOCTL_BT_LOGO, (" TypeID = 0x%x,\n Length = 0x%x,\n Content = 0x0000\n",
531 return pAssoStrc->Length + 3;
534 static u16 bthci_AssocPreferredChannelList(struct rtw_adapter *padapter,
535 void *pbuf, u8 EntryNum)
537 struct bt_30info *pBTInfo;
538 struct amp_assoc_structure *pAssoStrc;
539 struct amp_pref_chnl_regulatory *pReg;
540 struct chnl_txpower_triple *pTriple;
541 char ctrString[3] = {'X', 'X', 'X'};
545 pBTInfo = GET_BT_INFO(padapter);
546 pAssoStrc = (struct amp_assoc_structure *)pbuf;
547 pReg = (struct amp_pref_chnl_regulatory *)&pAssoStrc->Data[3];
549 preferredChnl = bthci_GetLocalChannel(padapter);
550 pAssoStrc->TypeID = AMP_PREFERRED_CHANNEL_LIST;
553 memcpy(&pAssoStrc->Data[0], &ctrString[0], 3);
555 pReg->regulatoryClass = 254;
556 pReg->coverageClass = 0;
558 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("PREFERRED_CHNL_LIST\n"));
559 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("XXX, 201, 254, 0\n"));
560 /* at the following, chnl 1~11 should be contained */
561 pTriple = (struct chnl_txpower_triple *)&pAssoStrc->Data[len];
563 /* (1) if any wifi or bt HS connection exists */
564 if ((pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR) ||
565 (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE |
566 WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE |
568 BTHCI_HsConnectionEstablished(padapter)) {
569 pTriple->FirstChnl = preferredChnl;
570 pTriple->NumChnls = 1;
571 pTriple->MaxTxPowerInDbm = 20;
573 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("First Channel = %d, Channel Num = %d, MaxDbm = %d\n",
576 pTriple->MaxTxPowerInDbm));
579 pAssoStrc->Length = (u16)len;
580 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, ("AssocPreferredChannelList : \n"), pAssoStrc, pAssoStrc->Length+3);
582 return pAssoStrc->Length + 3;
585 static u16 bthci_AssocPALVer(struct rtw_adapter *padapter, void *pbuf)
587 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
591 pAssoStrc->TypeID = AMP_80211_PAL_VISION;
592 pAssoStrc->Length = 0x5;
593 pu1Tmp = &pAssoStrc->Data[0];
594 *pu1Tmp = 0x1; /* PAL Version */
595 pu2Tmp = (u16 *)&pAssoStrc->Data[1];
596 *pu2Tmp = 0x5D; /* SIG Company identifier of 802.11 PAL vendor */
597 pu2Tmp = (u16 *)&pAssoStrc->Data[3];
598 *pu2Tmp = 0x1; /* PAL Sub-version specifier */
600 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("AssocPALVer : \n"), pAssoStrc, pAssoStrc->Length+3);
601 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("AssocPALVer \n"));
603 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",
606 return pAssoStrc->Length + 3;
609 static u8 bthci_CheckRfStateBeforeConnect(struct rtw_adapter *padapter)
611 struct bt_30info *pBTInfo;
612 enum rt_rf_power_state RfState;
614 pBTInfo = GET_BT_INFO(padapter);
616 RfState = padapter->pwrctrlpriv.rf_pwrstate;
618 if (RfState != rf_on) {
619 mod_timer(&pBTInfo->BTPsDisableTimer,
620 jiffies + msecs_to_jiffies(50));
626 static void bthci_ResponderStartToScan(struct rtw_adapter *padapter)
630 static u8 bthci_PhyLinkConnectionInProgress(struct rtw_adapter *padapter, u8 PhyLinkHandle)
632 struct bt_30info *pBTInfo;
633 struct bt_mgnt *pBtMgnt;
635 pBTInfo = GET_BT_INFO(padapter);
636 pBtMgnt = &pBTInfo->BtMgnt;
638 if (pBtMgnt->bPhyLinkInProgress &&
639 (pBtMgnt->BtCurrentPhyLinkhandle == PhyLinkHandle))
644 static void bthci_ResetFlowSpec(struct rtw_adapter *padapter, u8 EntryNum, u8 index)
646 struct bt_30info *pBTinfo;
648 pBTinfo = GET_BT_INFO(padapter);
650 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtLogLinkhandle = 0;
651 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtPhyLinkhandle = 0;
652 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCompleteEventIsSet = false;
653 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCancelCMDIsSetandComplete = false;
654 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtTxFlowSpecID = 0;
655 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].TxPacketCount = 0;
657 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.Identifier = 0x01;
658 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
659 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.MaximumSDUSize = 0xffff;
660 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
661 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.AccessLatency = 0xffffffff;
662 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.FlushTimeout = 0xffffffff;
664 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.Identifier = 0x01;
665 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
666 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.MaximumSDUSize = 0xffff;
667 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
668 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.AccessLatency = 0xffffffff;
669 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.FlushTimeout = 0xffffffff;
672 static void bthci_ResetEntry(struct rtw_adapter *padapter, u8 EntryNum)
674 struct bt_30info *pBTinfo;
675 struct bt_mgnt *pBtMgnt;
678 pBTinfo = GET_BT_INFO(padapter);
679 pBtMgnt = &pBTinfo->BtMgnt;
681 pBTinfo->BtAsocEntry[EntryNum].bUsed = false;
682 pBTinfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_DISCONNECTED;
683 pBTinfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED;
685 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen = 0;
686 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = 0;
687 if (pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment != NULL)
688 memset(pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment, 0, TOTAL_ALLOCIATE_ASSOC_LEN);
689 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = 0;
691 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = 0;
692 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = 0;
693 memset(pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, 0,
694 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
695 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = 0;
697 /* 0x640; 0.625ms*1600 = 1000ms, 0.625ms*16000 = 10000ms */
698 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = 0x3e80;
700 pBTinfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_NONE;
702 pBTinfo->BtAsocEntry[EntryNum].mAssoc = false;
703 pBTinfo->BtAsocEntry[EntryNum].b4waySuccess = false;
706 pBTinfo->BtAsocEntry[EntryNum].KeyReplayCounter = 0;
707 pBTinfo->BtAsocEntry[EntryNum].BTWPAAuthState = STATE_WPA_AUTH_UNINITIALIZED;
709 pBTinfo->BtAsocEntry[EntryNum].bSendSupervisionPacket = false;
710 pBTinfo->BtAsocEntry[EntryNum].NoRxPktCnt = 0;
711 pBTinfo->BtAsocEntry[EntryNum].ShortRangeMode = 0;
712 pBTinfo->BtAsocEntry[EntryNum].rxSuvpPktCnt = 0;
714 for (j = 0; j < MAX_LOGICAL_LINK_NUM; j++)
715 bthci_ResetFlowSpec(padapter, EntryNum, j);
717 pBtMgnt->BTAuthCount = 0;
718 pBtMgnt->BTAsocCount = 0;
719 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
720 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
722 HALBT_RemoveKey(padapter, EntryNum);
725 static void bthci_RemoveEntryByEntryNum(struct rtw_adapter *padapter, u8 EntryNum)
727 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
728 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
730 bthci_ResetEntry(padapter, EntryNum);
732 if (pBtMgnt->CurrentBTConnectionCnt > 0)
733 pBtMgnt->CurrentBTConnectionCnt--;
735 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d!!\n",
736 pBtMgnt->CurrentBTConnectionCnt));
738 if (pBtMgnt->CurrentBTConnectionCnt > 0) {
739 pBtMgnt->BtOperationOn = true;
741 pBtMgnt->BtOperationOn = false;
742 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation OFF!!\n"));
745 if (!pBtMgnt->BtOperationOn) {
746 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
747 del_timer_sync(&pBTInfo->BTBeaconTimer);
748 pBtMgnt->bStartSendSupervisionPkt = false;
753 bthci_CommandCompleteHeader(
757 enum hci_status status
760 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
761 u8 NumHCI_Comm = 0x1;
763 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
764 PPacketIrpEvent->Data[0] = NumHCI_Comm; /* packet # */
765 PPacketIrpEvent->Data[1] = HCIOPCODELOW(OCF, OGF);
766 PPacketIrpEvent->Data[2] = HCIOPCODEHIGHT(OCF, OGF);
768 if (OGF == OGF_EXTENSION) {
769 if (OCF == HCI_SET_RSSI_VALUE) {
770 RTPRINT(FIOCTL, (IOCTL_BT_EVENT_PERIODICAL),
771 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
772 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
774 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_EXT),
775 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
776 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
779 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
780 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
781 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
786 static u8 bthci_ExtensionEventHeaderRtk(u8 *pbuf, u8 extensionEvent)
788 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
789 PPacketIrpEvent->EventCode = HCI_EVENT_EXTENSION_RTK;
790 PPacketIrpEvent->Data[0] = extensionEvent; /* extension event code */
795 static enum rt_status
797 struct rtw_adapter *padapter,
802 enum rt_status rt_status;
804 rt_status = PlatformIndicateBTEvent(padapter, pEvntData, dataLen);
810 bthci_EventWriteRemoteAmpAssoc(
811 struct rtw_adapter *padapter,
812 enum hci_status status,
816 u8 localBuf[TmpLocalBufSize] = "";
819 struct packet_irp_hcievent_data *PPacketIrpEvent;
821 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
822 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
824 len += bthci_CommandCompleteHeader(&localBuf[0],
825 OGF_STATUS_PARAMETERS,
826 HCI_WRITE_REMOTE_AMP_ASSOC,
828 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("PhyLinkHandle = 0x%x, status = %d\n", PLHandle, status));
829 /* Return parameters starts from here */
830 pRetPar = &PPacketIrpEvent->Data[len];
831 pRetPar[0] = status; /* status */
832 pRetPar[1] = PLHandle;
834 PPacketIrpEvent->Length = len;
836 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
840 bthci_EventEnhancedFlushComplete(
841 struct rtw_adapter *padapter,
846 struct packet_irp_hcievent_data *PPacketIrpEvent;
848 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("EventEnhancedFlushComplete, LLH = 0x%x\n", LLH));
850 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
851 PPacketIrpEvent->EventCode = HCI_EVENT_ENHANCED_FLUSH_COMPLETE;
852 PPacketIrpEvent->Length = 2;
853 /* Logical link handle */
854 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LLH);
855 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LLH);
857 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
861 bthci_EventShortRangeModeChangeComplete(
862 struct rtw_adapter *padapter,
863 enum hci_status HciStatus,
868 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
869 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
871 struct packet_irp_hcievent_data *PPacketIrpEvent;
873 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE)) {
874 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
875 ("[BT event], Short Range Mode Change Complete, Ignore to send this event due to event mask page 2\n"));
878 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",
879 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, ShortRangeState));
881 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
882 PPacketIrpEvent->EventCode = HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE;
883 PPacketIrpEvent->Length = 3;
884 PPacketIrpEvent->Data[0] = HciStatus;
885 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
886 PPacketIrpEvent->Data[2] = ShortRangeState;
887 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
890 static void bthci_EventSendFlowSpecModifyComplete(struct rtw_adapter *padapter,
891 enum hci_status HciStatus,
895 struct packet_irp_hcievent_data *PPacketIrpEvent;
896 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
897 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
899 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE)) {
900 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
901 ("[BT event], Flow Spec Modify Complete, Ignore to send this event due to event mask page 2\n"));
904 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
905 ("[BT event], Flow Spec Modify Complete, status = 0x%x, LLH = 0x%x\n", HciStatus, logicHandle));
906 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
907 PPacketIrpEvent->EventCode = HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE;
908 PPacketIrpEvent->Length = 3;
910 PPacketIrpEvent->Data[0] = HciStatus;
911 /* Logical link handle */
912 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(logicHandle);
913 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(logicHandle);
915 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
919 bthci_EventExtWifiScanNotify(
920 struct rtw_adapter *padapter,
924 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
925 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
930 struct packet_irp_hcievent_data *PPacketIrpEvent;
932 if (!pBtMgnt->BtOperationOn)
935 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
937 len += bthci_ExtensionEventHeaderRtk(&localBuf[0], HCI_EVENT_EXT_WIFI_SCAN_NOTIFY);
939 /* Return parameters starts from here */
940 pRetPar = &PPacketIrpEvent->Data[len];
941 pu1Temp = (u8 *)&pRetPar[0];
945 PPacketIrpEvent->Length = len;
947 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS) {
948 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Wifi scan notify, scan type = %d\n",
954 bthci_EventAMPReceiverReport(
955 struct rtw_adapter *padapter,
959 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
960 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
962 if (pBtHciInfo->bTestNeedReport) {
963 u8 localBuf[20] = "";
966 struct packet_irp_hcievent_data *PPacketIrpEvent;
968 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_EVENT_AMP_RECEIVER_REPORT\n"));
969 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
970 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_RECEIVER_REPORT;
971 PPacketIrpEvent->Length = 2;
973 PPacketIrpEvent->Data[0] = pBtHciInfo->TestCtrType;
975 PPacketIrpEvent->Data[1] = Reason;
977 pu4Temp = (u32 *)&PPacketIrpEvent->Data[2];
978 *pu4Temp = pBtHciInfo->TestEventType;
980 pu2Temp = (u16 *)&PPacketIrpEvent->Data[6];
981 *pu2Temp = pBtHciInfo->TestNumOfFrame;
983 pu2Temp = (u16 *)&PPacketIrpEvent->Data[8];
984 *pu2Temp = pBtHciInfo->TestNumOfErrFrame;
986 pu4Temp = (u32 *)&PPacketIrpEvent->Data[10];
987 *pu4Temp = pBtHciInfo->TestNumOfBits;
989 pu4Temp = (u32 *)&PPacketIrpEvent->Data[14];
990 *pu4Temp = pBtHciInfo->TestNumOfErrBits;
992 bthci_IndicateEvent(padapter, PPacketIrpEvent, 20);
994 /* Return to Idel state with RX and TX off. */
998 pBtHciInfo->TestNumOfFrame = 0x00;
1002 bthci_EventChannelSelected(
1003 struct rtw_adapter *padapter,
1007 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1008 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1009 u8 localBuf[3] = "";
1010 struct packet_irp_hcievent_data *PPacketIrpEvent;
1012 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_CHANNEL_SELECT)) {
1013 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1014 ("[BT event], Channel Selected, Ignore to send this event due to event mask page 2\n"));
1018 RTPRINT(FIOCTL, IOCTL_BT_EVENT|IOCTL_STATE,
1019 ("[BT event], Channel Selected, PhyLinkHandle %d\n",
1020 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle));
1022 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1023 PPacketIrpEvent->EventCode = HCI_EVENT_CHANNEL_SELECT;
1024 PPacketIrpEvent->Length = 1;
1025 PPacketIrpEvent->Data[0] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1026 bthci_IndicateEvent(padapter, PPacketIrpEvent, 3);
1030 bthci_EventDisconnectPhyLinkComplete(
1031 struct rtw_adapter *padapter,
1032 enum hci_status HciStatus,
1033 enum hci_status Reason,
1037 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1038 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1039 u8 localBuf[5] = "";
1040 struct packet_irp_hcievent_data *PPacketIrpEvent;
1042 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE)) {
1043 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1044 ("[BT event], Disconnect Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1047 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1048 ("[BT event], Disconnect Physical Link Complete, Status = 0x%x, PLH = 0x%x Reason = 0x%x\n",
1049 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, Reason));
1050 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1051 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE;
1052 PPacketIrpEvent->Length = 3;
1053 PPacketIrpEvent->Data[0] = HciStatus;
1054 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1055 PPacketIrpEvent->Data[2] = Reason;
1056 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
1060 bthci_EventPhysicalLinkComplete(
1061 struct rtw_adapter *padapter,
1062 enum hci_status HciStatus,
1067 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1068 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1069 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1070 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1071 u8 localBuf[4] = "";
1072 struct packet_irp_hcievent_data *PPacketIrpEvent;
1075 pBtMgnt->bPhyLinkInProgress = false;
1076 pBtDbg->dbgHciInfo.hciCmdPhyLinkStatus = HciStatus;
1077 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_PHY_LINK_COMPLETE)) {
1078 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1079 ("[BT event], Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1083 if (EntryNum == 0xff) {
1084 /* connection not started yet, just use the input physical link handle to response. */
1085 PL_handle = PLHandle;
1087 /* connection is under progress, use the phy link handle we recorded. */
1088 PL_handle = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1089 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = false;
1092 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Physical Link Complete, Status = 0x%x PhyLinkHandle = 0x%x\n", HciStatus,
1095 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1096 PPacketIrpEvent->EventCode = HCI_EVENT_PHY_LINK_COMPLETE;
1097 PPacketIrpEvent->Length = 2;
1099 PPacketIrpEvent->Data[0] = HciStatus;
1100 PPacketIrpEvent->Data[1] = PL_handle;
1101 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1106 bthci_EventCommandStatus(
1107 struct rtw_adapter *padapter,
1110 enum hci_status HciStatus
1114 u8 localBuf[6] = "";
1115 struct packet_irp_hcievent_data *PPacketIrpEvent;
1116 u8 Num_Hci_Comm = 0x1;
1117 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1118 ("[BT event], CommandStatus, Opcode = 0x%02x%02x, OGF = 0x%x, OCF = 0x%x, Status = 0x%x, Num_HCI_COMM = 0x%x\n",
1119 (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), OGF, OCF, HciStatus, Num_Hci_Comm));
1121 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1122 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_STATUS;
1123 PPacketIrpEvent->Length = 4;
1124 PPacketIrpEvent->Data[0] = HciStatus; /* current pending */
1125 PPacketIrpEvent->Data[1] = Num_Hci_Comm; /* packet # */
1126 PPacketIrpEvent->Data[2] = HCIOPCODELOW(OCF, OGF);
1127 PPacketIrpEvent->Data[3] = HCIOPCODEHIGHT(OCF, OGF);
1129 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1134 bthci_EventLogicalLinkComplete(
1135 struct rtw_adapter *padapter,
1136 enum hci_status HciStatus,
1143 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1144 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1145 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1146 u8 localBuf[7] = "";
1147 struct packet_irp_hcievent_data *PPacketIrpEvent;
1149 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_LOGICAL_LINK_COMPLETE)) {
1150 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1151 ("[BT event], Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1154 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Logical Link Complete, PhyLinkHandle = 0x%x, LogLinkHandle = 0x%x, Status = 0x%x\n",
1155 PhyLinkHandle, LogLinkHandle, HciStatus));
1157 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1158 PPacketIrpEvent->EventCode = HCI_EVENT_LOGICAL_LINK_COMPLETE;
1159 PPacketIrpEvent->Length = 5;
1161 PPacketIrpEvent->Data[0] = HciStatus;/* status code */
1162 /* Logical link handle */
1163 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1164 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1165 /* Physical link handle */
1166 PPacketIrpEvent->Data[3] = TWOBYTE_LOWBYTE(PhyLinkHandle);
1167 /* corresponding Tx flow spec ID */
1168 if (HciStatus == HCI_STATUS_SUCCESS) {
1169 PPacketIrpEvent->Data[4] =
1170 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData[LogLinkIndex].Tx_Flow_Spec.Identifier;
1172 PPacketIrpEvent->Data[4] = 0x0;
1175 bthci_IndicateEvent(padapter, PPacketIrpEvent, 7);
1179 bthci_EventDisconnectLogicalLinkComplete(
1180 struct rtw_adapter *padapter,
1181 enum hci_status HciStatus,
1183 enum hci_status Reason
1186 u8 localBuf[6] = "";
1187 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1188 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1189 struct packet_irp_hcievent_data *PPacketIrpEvent;
1191 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE)) {
1192 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1195 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Status = 0x%x, LLH = 0x%x Reason = 0x%x\n", HciStatus, LogLinkHandle, Reason));
1197 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1198 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE;
1199 PPacketIrpEvent->Length = 4;
1201 PPacketIrpEvent->Data[0] = HciStatus;
1202 /* Logical link handle */
1203 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1204 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1205 /* Disconnect reason */
1206 PPacketIrpEvent->Data[3] = Reason;
1208 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1212 bthci_EventFlushOccurred(
1213 struct rtw_adapter *padapter,
1217 u8 localBuf[4] = "";
1218 struct packet_irp_hcievent_data *PPacketIrpEvent;
1219 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("bthci_EventFlushOccurred(), LLH = 0x%x\n", LogLinkHandle));
1221 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1222 PPacketIrpEvent->EventCode = HCI_EVENT_FLUSH_OCCRUED;
1223 PPacketIrpEvent->Length = 2;
1224 /* Logical link handle */
1225 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LogLinkHandle);
1226 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1228 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1231 static enum hci_status
1232 bthci_BuildPhysicalLink(
1233 struct rtw_adapter *padapter,
1234 struct packet_irp_hcicmd_data *pHciCmd,
1238 enum hci_status status = HCI_STATUS_SUCCESS;
1239 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1240 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1243 /* Send HCI Command status event to AMP. */
1244 bthci_EventCommandStatus(padapter,
1245 LINK_CONTROL_COMMANDS,
1247 HCI_STATUS_SUCCESS);
1249 PLH = *((u8 *)pHciCmd->Data);
1251 /* Check if resource or bt connection is under progress, if yes, reject the link creation. */
1252 if (!bthci_AddEntry(padapter)) {
1253 status = HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE;
1254 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1258 EntryNum = pBtMgnt->CurrentConnectEntryNum;
1259 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = PLH;
1260 pBtMgnt->BtCurrentPhyLinkhandle = PLH;
1262 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1263 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Create/Accept PhysicalLink, AMP controller is busy\n"));
1264 status = HCI_STATUS_CONTROLLER_BUSY;
1265 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1269 /* Record Key and the info */
1270 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = (*((u8 *)pHciCmd->Data+1));
1271 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = (*((u8 *)pHciCmd->Data+2));
1272 memcpy(pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1273 (((u8 *)pHciCmd->Data+3)), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1274 memcpy(pBTInfo->BtAsocEntry[EntryNum].PMK, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, PMK_LEN);
1275 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildPhysicalLink, EntryNum = %d, PLH = 0x%x KeyLen = 0x%x, KeyType = 0x%x\n",
1276 EntryNum, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1277 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen,
1278 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType));
1279 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("BtAMPKey\n"), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1280 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1281 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("PMK\n"), pBTInfo->BtAsocEntry[EntryNum].PMK,
1284 if (OCF == HCI_CREATE_PHYSICAL_LINK) {
1285 /* These macros require braces */
1286 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_CREATE_PHY_LINK, EntryNum);
1287 } else if (OCF == HCI_ACCEPT_PHYSICAL_LINK) {
1288 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ACCEPT_PHY_LINK, EntryNum);
1295 bthci_BuildLogicalLink(
1296 struct rtw_adapter *padapter,
1297 struct packet_irp_hcicmd_data *pHciCmd,
1301 enum hci_status status = HCI_STATUS_SUCCESS;
1302 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1303 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
1304 u8 PhyLinkHandle, EntryNum;
1305 static u16 AssignLogHandle = 1;
1307 struct hci_flow_spec TxFlowSpec;
1308 struct hci_flow_spec RxFlowSpec;
1309 u32 MaxSDUSize, ArriveTime, Bandwidth;
1311 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1313 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1316 &pHciCmd->Data[1], sizeof(struct hci_flow_spec));
1318 &pHciCmd->Data[17], sizeof(struct hci_flow_spec));
1320 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
1321 ArriveTime = TxFlowSpec.SDUInterArrivalTime;
1323 if (bthci_CheckLogLinkBehavior(padapter, TxFlowSpec) && bthci_CheckLogLinkBehavior(padapter, RxFlowSpec))
1324 Bandwidth = BTTOTALBANDWIDTH;
1325 else if (MaxSDUSize == 0xffff && ArriveTime == 0xffffffff)
1326 Bandwidth = BTTOTALBANDWIDTH;
1328 Bandwidth = MaxSDUSize*8*1000/(ArriveTime+244);
1330 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
1331 ("BuildLogicalLink, PhyLinkHandle = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, Bandwidth = 0x%x\n",
1332 PhyLinkHandle, MaxSDUSize, ArriveTime, Bandwidth));
1334 if (EntryNum == 0xff) {
1335 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Invalid Physical Link handle = 0x%x, status = HCI_STATUS_UNKNOW_CONNECT_ID, return\n", PhyLinkHandle));
1336 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1338 /* When we receive Create/Accept logical link command, we should send command status event first. */
1339 bthci_EventCommandStatus(padapter,
1340 LINK_CONTROL_COMMANDS,
1346 if (!pBtMgnt->bLogLinkInProgress) {
1347 if (bthci_PhyLinkConnectionInProgress(padapter, PhyLinkHandle)) {
1348 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Physical link connection in progress, status = HCI_STATUS_CMD_DISALLOW, return\n"));
1349 status = HCI_STATUS_CMD_DISALLOW;
1351 pBtMgnt->bPhyLinkInProgressStartLL = true;
1352 /* When we receive Create/Accept logical link command, we should send command status event first. */
1353 bthci_EventCommandStatus(padapter,
1354 LINK_CONTROL_COMMANDS,
1361 if (Bandwidth > BTTOTALBANDWIDTH) {
1362 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_QOS_REJECT, Bandwidth = 0x%x, return\n", Bandwidth));
1363 status = HCI_STATUS_QOS_REJECT;
1365 /* When we receive Create/Accept logical link command, we should send command status event first. */
1366 bthci_EventCommandStatus(padapter,
1367 LINK_CONTROL_COMMANDS,
1371 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_SUCCESS\n"));
1372 status = HCI_STATUS_SUCCESS;
1374 /* When we receive Create/Accept logical link command, we should send command status event first. */
1375 bthci_EventCommandStatus(padapter,
1376 LINK_CONTROL_COMMANDS,
1382 if (pBTinfo->BtAsocEntry[EntryNum].BtCurrentState != HCI_STATE_CONNECTED) {
1383 bthci_EventLogicalLinkComplete(padapter,
1384 HCI_STATUS_CMD_DISALLOW, 0, 0, 0, EntryNum);
1388 pBtMgnt->bLogLinkInProgress = true;
1390 /* find an unused logical link index and copy the data */
1391 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
1392 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle == 0) {
1393 enum hci_status LogCompEventstatus = HCI_STATUS_SUCCESS;
1395 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
1396 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle = AssignLogHandle;
1397 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildLogicalLink, EntryNum = %d, physical link handle = 0x%x, logical link handle = 0x%x\n",
1398 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1399 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle));
1400 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Tx_Flow_Spec,
1401 &TxFlowSpec, sizeof(struct hci_flow_spec));
1402 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Rx_Flow_Spec,
1403 &RxFlowSpec, sizeof(struct hci_flow_spec));
1405 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = false;
1407 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCancelCMDIsSetandComplete)
1408 LogCompEventstatus = HCI_STATUS_UNKNOW_CONNECT_ID;
1409 bthci_EventLogicalLinkComplete(padapter,
1411 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle,
1412 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle, i, EntryNum);
1414 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = true;
1417 pBtMgnt->BtCurrentLogLinkhandle = AssignLogHandle;
1424 bthci_EventLogicalLinkComplete(padapter,
1425 HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE, 0, 0, 0, EntryNum);
1427 pBtMgnt->bLogLinkInProgress = false;
1430 bthci_EventLogicalLinkComplete(padapter,
1431 HCI_STATUS_CONTROLLER_BUSY, 0, 0, 0, EntryNum);
1437 bthci_StartBeaconAndConnect(
1438 struct rtw_adapter *padapter,
1439 struct packet_irp_hcicmd_data *pHciCmd,
1443 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1444 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1445 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1447 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("StartBeaconAndConnect, CurrentAssocNum =%d, AMPRole =%d\n",
1449 pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole));
1451 if (!pBtMgnt->CheckChnlIsSuit) {
1452 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONNECT_REJ_NOT_SUIT_CHNL_FOUND, CurrentAssocNum, INVALID_PL_HANDLE);
1453 bthci_RemoveEntryByEntryNum(padapter, CurrentAssocNum);
1457 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1458 rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
1459 padapter->eeprompriv.mac_addr[0],
1460 padapter->eeprompriv.mac_addr[1],
1461 padapter->eeprompriv.mac_addr[2],
1462 padapter->eeprompriv.mac_addr[3],
1463 padapter->eeprompriv.mac_addr[4],
1464 padapter->eeprompriv.mac_addr[5]);
1465 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1466 rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
1467 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[0],
1468 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[1],
1469 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[2],
1470 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[3],
1471 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[4],
1472 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[5]);
1475 FillOctetString(pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid, pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 21);
1476 pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid.Length = 21;
1478 /* To avoid set the start ap or connect twice, or the original connection will be disconnected. */
1479 if (!pBtMgnt->bBTConnectInProgress) {
1480 pBtMgnt->bBTConnectInProgress = true;
1481 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress ON!!\n"));
1482 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_STARTING, STATE_CMD_MAC_START_COMPLETE, CurrentAssocNum);
1484 /* 20100325 Joseph: Check RF ON/OFF. */
1485 /* If RF OFF, it reschedule connecting operation after 50ms. */
1486 if (!bthci_CheckRfStateBeforeConnect(padapter))
1489 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1490 /* These macros need braces */
1491 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_COMPLETE, CurrentAssocNum);
1492 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1493 bthci_ResponderStartToScan(padapter);
1496 RT_PRINT_STR(_module_rtl871x_mlme_c_, _drv_notice_,
1497 "StartBeaconAndConnect, SSID:\n",
1498 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Octet,
1499 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Length);
1502 static void bthci_ResetBtMgnt(struct bt_mgnt *pBtMgnt)
1504 pBtMgnt->BtOperationOn = false;
1505 pBtMgnt->bBTConnectInProgress = false;
1506 pBtMgnt->bLogLinkInProgress = false;
1507 pBtMgnt->bPhyLinkInProgress = false;
1508 pBtMgnt->bPhyLinkInProgressStartLL = false;
1509 pBtMgnt->DisconnectEntryNum = 0xff;
1510 pBtMgnt->bStartSendSupervisionPkt = false;
1511 pBtMgnt->JoinerNeedSendAuth = false;
1512 pBtMgnt->CurrentBTConnectionCnt = 0;
1513 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
1514 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
1515 pBtMgnt->BTAuthCount = 0;
1516 pBtMgnt->btLogoTest = 0;
1519 static void bthci_ResetBtHciInfo(struct bt_hci_info *pBtHciInfo)
1521 pBtHciInfo->BTEventMask = 0;
1522 pBtHciInfo->BTEventMaskPage2 = 0;
1523 pBtHciInfo->ConnAcceptTimeout = 10000;
1524 pBtHciInfo->PageTimeout = 0x30;
1525 pBtHciInfo->LocationDomainAware = 0x0;
1526 pBtHciInfo->LocationDomain = 0x5858;
1527 pBtHciInfo->LocationDomainOptions = 0x58;
1528 pBtHciInfo->LocationOptions = 0x0;
1529 pBtHciInfo->FlowControlMode = 0x1; /* 0:Packet based data flow control mode(BR/EDR), 1: Data block based data flow control mode(AMP). */
1531 pBtHciInfo->enFlush_LLH = 0;
1532 pBtHciInfo->FLTO_LLH = 0;
1534 /* Test command only */
1535 pBtHciInfo->bTestIsEnd = true;
1536 pBtHciInfo->bInTestMode = false;
1537 pBtHciInfo->bTestNeedReport = false;
1538 pBtHciInfo->TestScenario = 0xff;
1539 pBtHciInfo->TestReportInterval = 0x01;
1540 pBtHciInfo->TestCtrType = 0x5d;
1541 pBtHciInfo->TestEventType = 0x00;
1542 pBtHciInfo->TestNumOfFrame = 0;
1543 pBtHciInfo->TestNumOfErrFrame = 0;
1544 pBtHciInfo->TestNumOfBits = 0;
1545 pBtHciInfo->TestNumOfErrBits = 0;
1548 static void bthci_ResetBtSec(struct rtw_adapter *padapter, struct bt_security *pBtSec)
1550 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1552 /* Set BT used HW or SW encrypt !! */
1553 if (GET_HAL_DATA(padapter)->bBTMode)
1554 pBtSec->bUsedHwEncrypt = true;
1556 pBtSec->bUsedHwEncrypt = false;
1557 RT_TRACE(_module_rtl871x_security_c_, _drv_info_, ("%s: bUsedHwEncrypt =%d\n", __func__, pBtSec->bUsedHwEncrypt));
1559 pBtSec->RSNIE.Octet = pBtSec->RSNIEBuf;
1562 static void bthci_ResetBtExtInfo(struct bt_mgnt *pBtMgnt)
1566 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
1567 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = 0;
1568 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = 0;
1569 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = 0;
1570 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = BT_PROFILE_NONE;
1571 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = BT_SPEC_2_1_EDR;
1572 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = 0;
1573 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
1574 pBtMgnt->ExtConfig.linkInfo[i].linkRole = BT_LINK_MASTER;
1577 pBtMgnt->ExtConfig.CurrentConnectHandle = 0;
1578 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = 0;
1579 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = 0;
1580 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
1581 pBtMgnt->ExtConfig.NumberOfHandle = 0;
1582 pBtMgnt->ExtConfig.NumberOfSCO = 0;
1583 pBtMgnt->ExtConfig.CurrentBTStatus = 0;
1584 pBtMgnt->ExtConfig.HCIExtensionVer = 0;
1586 pBtMgnt->ExtConfig.bManualControl = false;
1587 pBtMgnt->ExtConfig.bBTBusy = false;
1588 pBtMgnt->ExtConfig.bBTA2DPBusy = false;
1591 static enum hci_status bthci_CmdReset(struct rtw_adapter *_padapter, u8 bNeedSendEvent)
1593 enum hci_status status = HCI_STATUS_SUCCESS;
1594 struct rtw_adapter *padapter;
1595 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1596 struct bt_30info *pBTInfo;
1597 struct bt_mgnt *pBtMgnt;
1598 struct bt_hci_info *pBtHciInfo;
1599 struct bt_security *pBtSec;
1600 struct bt_dgb *pBtDbg;
1603 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_CmdReset()\n"));
1605 padapter = GetDefaultAdapter(_padapter);
1606 pBTInfo = GET_BT_INFO(padapter);
1607 pBtMgnt = &pBTInfo->BtMgnt;
1608 pBtHciInfo = &pBTInfo->BtHciInfo;
1609 pBtSec = &pBTInfo->BtSec;
1610 pBtDbg = &pBTInfo->BtDbg;
1612 pBTInfo->padapter = padapter;
1614 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++)
1615 bthci_ResetEntry(padapter, i);
1617 bthci_ResetBtMgnt(pBtMgnt);
1618 bthci_ResetBtHciInfo(pBtHciInfo);
1619 bthci_ResetBtSec(padapter, pBtSec);
1621 pBtMgnt->BTChannel = BT_Default_Chnl;
1622 pBtMgnt->CheckChnlIsSuit = true;
1624 pBTInfo->BTBeaconTmrOn = false;
1626 pBtMgnt->bCreateSpportQos = true;
1628 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
1629 del_timer_sync(&pBTInfo->BTBeaconTimer);
1631 HALBT_SetRtsCtsNoLenLimit(padapter);
1633 /* Maybe we need to take care Group != AES case !! */
1634 /* now we Pairwise and Group all used AES !! */
1636 bthci_ResetBtExtInfo(pBtMgnt);
1638 /* send command complete event here when all data are received. */
1639 if (bNeedSendEvent) {
1640 u8 localBuf[6] = "";
1643 struct packet_irp_hcievent_data *PPacketIrpEvent;
1645 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1647 len += bthci_CommandCompleteHeader(&localBuf[0],
1648 OGF_SET_EVENT_MASK_COMMAND,
1652 /* Return parameters starts from here */
1653 pRetPar = &PPacketIrpEvent->Data[len];
1654 pRetPar[0] = status; /* status */
1656 PPacketIrpEvent->Length = len;
1658 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1664 static enum hci_status
1665 bthci_CmdWriteRemoteAMPAssoc(
1666 struct rtw_adapter *padapter,
1667 struct packet_irp_hcicmd_data *pHciCmd
1670 enum hci_status status = HCI_STATUS_SUCCESS;
1671 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1672 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1676 pBtDbg->dbgHciInfo.hciCmdCntWriteRemoteAmpAssoc++;
1677 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1678 CurrentAssocNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1680 if (CurrentAssocNum == 0xff) {
1681 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, No such Handle in the Entry\n"));
1682 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1683 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1687 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1688 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, AMP controller is busy\n"));
1689 status = HCI_STATUS_CONTROLLER_BUSY;
1690 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1694 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.BtPhyLinkhandle = PhyLinkHandle;/* u8 *)pHciCmd->Data); */
1695 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
1696 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen = *((u16 *)((u8 *)pHciCmd->Data+3));
1698 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, LenSoFar = 0x%x, AssocRemLen = 0x%x\n",
1699 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar,
1700 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1702 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
1703 ("WriteRemoteAMPAssoc fragment \n"),
1705 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen+5);
1706 if ((pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen) > MAX_AMP_ASSOC_FRAG_LEN) {
1707 memcpy(((u8 *)pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8)))),
1708 (u8 *)pHciCmd->Data+5,
1709 MAX_AMP_ASSOC_FRAG_LEN);
1711 memcpy((u8 *)(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment)+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8))),
1712 ((u8 *)pHciCmd->Data+5),
1713 (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1715 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "WriteRemoteAMPAssoc :\n",
1716 pHciCmd->Data+5, pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen);
1718 if (!bthci_GetAssocInfo(padapter, CurrentAssocNum))
1719 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
1721 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1723 bthci_StartBeaconAndConnect(padapter, pHciCmd, CurrentAssocNum);
1730 static enum hci_status bthci_CmdReadConnectionAcceptTimeout(struct rtw_adapter *padapter)
1732 enum hci_status status = HCI_STATUS_SUCCESS;
1733 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1734 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1735 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1736 u8 localBuf[8] = "";
1739 struct packet_irp_hcievent_data *PPacketIrpEvent;
1742 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1744 len += bthci_CommandCompleteHeader(&localBuf[0],
1745 OGF_SET_EVENT_MASK_COMMAND,
1746 HCI_READ_CONNECTION_ACCEPT_TIMEOUT,
1749 /* Return parameters starts from here */
1750 pRetPar = &PPacketIrpEvent->Data[len];
1751 pRetPar[0] = status; /* status */
1752 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
1753 *pu2Temp = pBtHciInfo->ConnAcceptTimeout;
1755 PPacketIrpEvent->Length = len;
1757 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1763 static enum hci_status
1764 bthci_CmdSetEventFilter(
1765 struct rtw_adapter *padapter,
1766 struct packet_irp_hcicmd_data *pHciCmd
1769 return HCI_STATUS_SUCCESS;
1773 static enum hci_status
1774 bthci_CmdWriteConnectionAcceptTimeout(
1775 struct rtw_adapter *padapter,
1776 struct packet_irp_hcicmd_data *pHciCmd
1779 enum hci_status status = HCI_STATUS_SUCCESS;
1780 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1781 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1783 u8 localBuf[6] = "";
1786 struct packet_irp_hcievent_data *PPacketIrpEvent;
1788 pu2Temp = (u16 *)&pHciCmd->Data[0];
1789 pBtHciInfo->ConnAcceptTimeout = *pu2Temp;
1790 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ConnAcceptTimeout = 0x%x",
1791 pBtHciInfo->ConnAcceptTimeout));
1793 /* send command complete event here when all data are received. */
1794 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1796 len += bthci_CommandCompleteHeader(&localBuf[0],
1797 OGF_SET_EVENT_MASK_COMMAND,
1798 HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT,
1801 /* Return parameters starts from here */
1802 pRetPar = &PPacketIrpEvent->Data[len];
1803 pRetPar[0] = status; /* status */
1805 PPacketIrpEvent->Length = len;
1807 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1812 static enum hci_status
1813 bthci_CmdReadPageTimeout(
1814 struct rtw_adapter *padapter,
1815 struct packet_irp_hcicmd_data *pHciCmd
1818 enum hci_status status = HCI_STATUS_SUCCESS;
1819 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1820 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1821 u8 localBuf[8] = "";
1824 struct packet_irp_hcievent_data *PPacketIrpEvent;
1827 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1829 len += bthci_CommandCompleteHeader(&localBuf[0],
1830 OGF_SET_EVENT_MASK_COMMAND,
1831 HCI_READ_PAGE_TIMEOUT,
1834 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Read PageTimeout = 0x%x\n", pBtHciInfo->PageTimeout));
1835 /* Return parameters starts from here */
1836 pRetPar = &PPacketIrpEvent->Data[len];
1837 pRetPar[0] = status; /* status */
1838 pu2Temp = (u16 *)&pRetPar[1]; /* Page_Timeout */
1839 *pu2Temp = pBtHciInfo->PageTimeout;
1841 PPacketIrpEvent->Length = len;
1843 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1848 static enum hci_status
1849 bthci_CmdWritePageTimeout(
1850 struct rtw_adapter *padapter,
1851 struct packet_irp_hcicmd_data *pHciCmd
1854 enum hci_status status = HCI_STATUS_SUCCESS;
1855 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1856 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1859 pu2Temp = (u16 *)&pHciCmd->Data[0];
1860 pBtHciInfo->PageTimeout = *pu2Temp;
1861 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Write PageTimeout = 0x%x\n",
1862 pBtHciInfo->PageTimeout));
1864 /* send command complete event here when all data are received. */
1866 u8 localBuf[6] = "";
1869 struct packet_irp_hcievent_data *PPacketIrpEvent;
1871 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1873 len += bthci_CommandCompleteHeader(&localBuf[0],
1874 OGF_SET_EVENT_MASK_COMMAND,
1875 HCI_WRITE_PAGE_TIMEOUT,
1878 /* Return parameters starts from here */
1879 pRetPar = &PPacketIrpEvent->Data[len];
1880 pRetPar[0] = status; /* status */
1882 PPacketIrpEvent->Length = len;
1884 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1890 static enum hci_status
1891 bthci_CmdReadLinkSupervisionTimeout(
1892 struct rtw_adapter *padapter,
1893 struct packet_irp_hcicmd_data *pHciCmd
1896 enum hci_status status = HCI_STATUS_SUCCESS;
1897 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1898 u8 physicalLinkHandle, EntryNum;
1900 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1902 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1904 if (EntryNum == 0xff) {
1905 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLinkSupervisionTimeout, No such Handle in the Entry\n"));
1906 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1910 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle)
1911 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1914 u8 localBuf[10] = "";
1917 struct packet_irp_hcievent_data *PPacketIrpEvent;
1920 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1922 len += bthci_CommandCompleteHeader(&localBuf[0],
1923 OGF_SET_EVENT_MASK_COMMAND,
1924 HCI_READ_LINK_SUPERVISION_TIMEOUT,
1927 /* Return parameters starts from here */
1928 pRetPar = &PPacketIrpEvent->Data[len];
1929 pRetPar[0] = status;
1930 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1932 pu2Temp = (u16 *)&pRetPar[3]; /* Conn_Accept_Timeout */
1933 *pu2Temp = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout;
1935 PPacketIrpEvent->Length = len;
1937 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1943 static enum hci_status
1944 bthci_CmdWriteLinkSupervisionTimeout(
1945 struct rtw_adapter *padapter,
1946 struct packet_irp_hcicmd_data *pHciCmd
1949 enum hci_status status = HCI_STATUS_SUCCESS;
1950 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1951 u8 physicalLinkHandle, EntryNum;
1953 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1955 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1957 if (EntryNum == 0xff) {
1958 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("WriteLinkSupervisionTimeout, No such Handle in the Entry\n"));
1959 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1961 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle) {
1962 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1964 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = *((u16 *)(((u8 *)pHciCmd->Data)+2));
1965 RTPRINT(FIOCTL, IOCTL_STATE, ("BT Write LinkSuperversionTimeout[%d] = 0x%x\n",
1966 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout));
1971 u8 localBuf[8] = "";
1974 struct packet_irp_hcievent_data *PPacketIrpEvent;
1976 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1978 len += bthci_CommandCompleteHeader(&localBuf[0],
1979 OGF_SET_EVENT_MASK_COMMAND,
1980 HCI_WRITE_LINK_SUPERVISION_TIMEOUT,
1983 /* Return parameters starts from here */
1984 pRetPar = &PPacketIrpEvent->Data[len];
1985 pRetPar[0] = status;
1986 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1989 PPacketIrpEvent->Length = len;
1991 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1997 static enum hci_status
1998 bthci_CmdEnhancedFlush(
1999 struct rtw_adapter *padapter,
2000 struct packet_irp_hcicmd_data *pHciCmd
2003 enum hci_status status = HCI_STATUS_SUCCESS;
2004 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2005 struct bt_hci_info *pBtHciInfo = &pBTinfo->BtHciInfo;
2009 logicHandle = *((u16 *)&pHciCmd->Data[0]);
2010 Packet_Type = pHciCmd->Data[2];
2012 if (Packet_Type != 0)
2013 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
2015 pBtHciInfo->enFlush_LLH = logicHandle;
2017 if (bthci_DiscardTxPackets(padapter, pBtHciInfo->enFlush_LLH))
2018 bthci_EventFlushOccurred(padapter, pBtHciInfo->enFlush_LLH);
2020 /* should send command status event */
2021 bthci_EventCommandStatus(padapter,
2022 OGF_SET_EVENT_MASK_COMMAND,
2026 if (pBtHciInfo->enFlush_LLH) {
2027 bthci_EventEnhancedFlushComplete(padapter, pBtHciInfo->enFlush_LLH);
2028 pBtHciInfo->enFlush_LLH = 0;
2034 static enum hci_status
2035 bthci_CmdReadLogicalLinkAcceptTimeout(
2036 struct rtw_adapter *padapter,
2037 struct packet_irp_hcicmd_data *pHciCmd
2040 enum hci_status status = HCI_STATUS_SUCCESS;
2041 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2042 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2043 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2044 u8 localBuf[8] = "";
2047 struct packet_irp_hcievent_data *PPacketIrpEvent;
2050 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2052 len += bthci_CommandCompleteHeader(&localBuf[0],
2053 OGF_SET_EVENT_MASK_COMMAND,
2054 HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT,
2057 /* Return parameters starts from here */
2058 pRetPar = &PPacketIrpEvent->Data[len];
2059 pRetPar[0] = status;
2061 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
2062 *pu2Temp = pBtHciInfo->LogicalAcceptTimeout;
2064 PPacketIrpEvent->Length = len;
2066 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2071 static enum hci_status
2072 bthci_CmdWriteLogicalLinkAcceptTimeout(
2073 struct rtw_adapter *padapter,
2074 struct packet_irp_hcicmd_data *pHciCmd
2077 enum hci_status status = HCI_STATUS_SUCCESS;
2078 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2079 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2080 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2081 u8 localBuf[6] = "";
2084 struct packet_irp_hcievent_data *PPacketIrpEvent;
2086 pBtHciInfo->LogicalAcceptTimeout = *((u16 *)pHciCmd->Data);
2088 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2090 len += bthci_CommandCompleteHeader(&localBuf[0],
2091 OGF_SET_EVENT_MASK_COMMAND,
2092 HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT,
2095 /* Return parameters starts from here */
2096 pRetPar = &PPacketIrpEvent->Data[len];
2097 pRetPar[0] = status;
2100 PPacketIrpEvent->Length = len;
2102 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2106 static enum hci_status
2107 bthci_CmdSetEventMask(
2108 struct rtw_adapter *padapter,
2109 struct packet_irp_hcicmd_data *pHciCmd
2112 enum hci_status status = HCI_STATUS_SUCCESS;
2113 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2114 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2115 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2117 u8 localBuf[6] = "";
2120 struct packet_irp_hcievent_data *PPacketIrpEvent;
2122 pu8Temp = (u8 *)&pHciCmd->Data[0];
2123 pBtHciInfo->BTEventMask = *pu8Temp;
2124 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("BTEventMask = 0x%"i64fmt"x\n",
2125 pBtHciInfo->BTEventMask));
2127 /* send command complete event here when all data are received. */
2128 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2130 len += bthci_CommandCompleteHeader(&localBuf[0],
2131 OGF_SET_EVENT_MASK_COMMAND,
2135 /* Return parameters starts from here */
2136 pRetPar = &PPacketIrpEvent->Data[len];
2137 pRetPar[0] = status; /* status */
2139 PPacketIrpEvent->Length = len;
2141 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2147 static enum hci_status
2148 bthci_CmdSetEventMaskPage2(
2149 struct rtw_adapter *padapter,
2150 struct packet_irp_hcicmd_data *pHciCmd
2153 enum hci_status status = HCI_STATUS_SUCCESS;
2154 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2155 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2157 u8 localBuf[6] = "";
2160 struct packet_irp_hcievent_data *PPacketIrpEvent;
2162 pu8Temp = (u8 *)&pHciCmd->Data[0];
2163 pBtHciInfo->BTEventMaskPage2 = *pu8Temp;
2164 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("BTEventMaskPage2 = 0x%"i64fmt"x\n",
2165 pBtHciInfo->BTEventMaskPage2));
2167 /* send command complete event here when all data are received. */
2168 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2170 len += bthci_CommandCompleteHeader(&localBuf[0],
2171 OGF_SET_EVENT_MASK_COMMAND,
2172 HCI_SET_EVENT_MASK_PAGE_2,
2175 /* Return parameters starts from here */
2176 pRetPar = &PPacketIrpEvent->Data[len];
2177 pRetPar[0] = status; /* status */
2179 PPacketIrpEvent->Length = len;
2181 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2186 static enum hci_status
2187 bthci_CmdReadLocationData(
2188 struct rtw_adapter *padapter,
2189 struct packet_irp_hcicmd_data *pHciCmd
2192 enum hci_status status = HCI_STATUS_SUCCESS;
2193 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2194 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2195 u8 localBuf[12] = "";
2198 struct packet_irp_hcievent_data *PPacketIrpEvent;
2201 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2203 len += bthci_CommandCompleteHeader(&localBuf[0],
2204 OGF_SET_EVENT_MASK_COMMAND,
2205 HCI_READ_LOCATION_DATA,
2207 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2208 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2209 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2210 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2212 /* Return parameters starts from here */
2213 pRetPar = &PPacketIrpEvent->Data[len];
2214 pRetPar[0] = status;
2216 pRetPar[1] = pBtHciInfo->LocationDomainAware; /* 0x0; Location_Domain_Aware */
2217 pu2Temp = (u16 *)&pRetPar[2]; /* Location_Domain */
2218 *pu2Temp = pBtHciInfo->LocationDomain; /* 0x5858; */
2219 pRetPar[4] = pBtHciInfo->LocationDomainOptions; /* 0x58; Location_Domain_Options */
2220 pRetPar[5] = pBtHciInfo->LocationOptions; /* 0x0; Location_Options */
2222 PPacketIrpEvent->Length = len;
2224 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2228 static enum hci_status
2229 bthci_CmdWriteLocationData(
2230 struct rtw_adapter *padapter,
2231 struct packet_irp_hcicmd_data *pHciCmd
2234 enum hci_status status = HCI_STATUS_SUCCESS;
2235 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2236 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2238 u8 localBuf[6] = "";
2241 struct packet_irp_hcievent_data *PPacketIrpEvent;
2243 pBtHciInfo->LocationDomainAware = pHciCmd->Data[0];
2244 pu2Temp = (u16 *)&pHciCmd->Data[1];
2245 pBtHciInfo->LocationDomain = *pu2Temp;
2246 pBtHciInfo->LocationDomainOptions = pHciCmd->Data[3];
2247 pBtHciInfo->LocationOptions = pHciCmd->Data[4];
2248 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2249 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2250 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2251 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2253 /* send command complete event here when all data are received. */
2254 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2256 len += bthci_CommandCompleteHeader(&localBuf[0],
2257 OGF_SET_EVENT_MASK_COMMAND,
2258 HCI_WRITE_LOCATION_DATA,
2261 /* Return parameters starts from here */
2262 pRetPar = &PPacketIrpEvent->Data[len];
2263 pRetPar[0] = status; /* status */
2265 PPacketIrpEvent->Length = len;
2267 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2272 static enum hci_status
2273 bthci_CmdReadFlowControlMode(
2274 struct rtw_adapter *padapter,
2275 struct packet_irp_hcicmd_data *pHciCmd
2278 enum hci_status status = HCI_STATUS_SUCCESS;
2279 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2280 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2281 u8 localBuf[7] = "";
2284 struct packet_irp_hcievent_data *PPacketIrpEvent;
2286 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2288 len += bthci_CommandCompleteHeader(&localBuf[0],
2289 OGF_SET_EVENT_MASK_COMMAND,
2290 HCI_READ_FLOW_CONTROL_MODE,
2293 /* Return parameters starts from here */
2294 pRetPar = &PPacketIrpEvent->Data[len];
2295 pRetPar[0] = status;
2296 pRetPar[1] = pBtHciInfo->FlowControlMode; /* Flow Control Mode */
2298 PPacketIrpEvent->Length = len;
2300 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2304 static enum hci_status
2305 bthci_CmdWriteFlowControlMode(
2306 struct rtw_adapter *padapter,
2307 struct packet_irp_hcicmd_data *pHciCmd
2310 enum hci_status status = HCI_STATUS_SUCCESS;
2311 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2312 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2313 u8 localBuf[6] = "";
2316 struct packet_irp_hcievent_data *PPacketIrpEvent;
2318 pBtHciInfo->FlowControlMode = pHciCmd->Data[0];
2320 /* send command complete event here when all data are received. */
2321 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2323 len += bthci_CommandCompleteHeader(&localBuf[0],
2324 OGF_SET_EVENT_MASK_COMMAND,
2325 HCI_WRITE_FLOW_CONTROL_MODE,
2328 /* Return parameters starts from here */
2329 pRetPar = &PPacketIrpEvent->Data[len];
2330 pRetPar[0] = status; /* status */
2332 PPacketIrpEvent->Length = len;
2334 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2339 static enum hci_status
2340 bthci_CmdReadBestEffortFlushTimeout(
2341 struct rtw_adapter *padapter,
2342 struct packet_irp_hcicmd_data *pHciCmd
2345 enum hci_status status = HCI_STATUS_SUCCESS;
2346 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2347 u16 i, j, logicHandle;
2348 u32 BestEffortFlushTimeout = 0xffffffff;
2351 logicHandle = *((u16 *)pHciCmd->Data);
2352 /* find an matched logical link index and copy the data */
2353 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2354 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2355 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2356 BestEffortFlushTimeout = pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout;
2364 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2367 u8 localBuf[10] = "";
2370 struct packet_irp_hcievent_data *PPacketIrpEvent;
2373 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2375 len += bthci_CommandCompleteHeader(&localBuf[0],
2376 OGF_SET_EVENT_MASK_COMMAND,
2377 HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT,
2380 /* Return parameters starts from here */
2381 pRetPar = &PPacketIrpEvent->Data[len];
2382 pRetPar[0] = status;
2383 pu4Temp = (u32 *)&pRetPar[1]; /* Best_Effort_Flush_Timeout */
2384 *pu4Temp = BestEffortFlushTimeout;
2386 PPacketIrpEvent->Length = len;
2388 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2393 static enum hci_status
2394 bthci_CmdWriteBestEffortFlushTimeout(
2395 struct rtw_adapter *padapter,
2396 struct packet_irp_hcicmd_data *pHciCmd
2399 enum hci_status status = HCI_STATUS_SUCCESS;
2400 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2401 u16 i, j, logicHandle;
2402 u32 BestEffortFlushTimeout = 0xffffffff;
2405 logicHandle = *((u16 *)pHciCmd->Data);
2406 BestEffortFlushTimeout = *((u32 *)(pHciCmd->Data+1));
2408 /* find an matched logical link index and copy the data */
2409 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2410 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2411 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2412 pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout = BestEffortFlushTimeout;
2420 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2423 u8 localBuf[6] = "";
2426 struct packet_irp_hcievent_data *PPacketIrpEvent;
2428 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2430 len += bthci_CommandCompleteHeader(&localBuf[0],
2431 OGF_SET_EVENT_MASK_COMMAND,
2432 HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT,
2435 /* Return parameters starts from here */
2436 pRetPar = &PPacketIrpEvent->Data[len];
2437 pRetPar[0] = status;
2439 PPacketIrpEvent->Length = len;
2441 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2446 static enum hci_status
2447 bthci_CmdShortRangeMode(
2448 struct rtw_adapter *padapter,
2449 struct packet_irp_hcicmd_data *pHciCmd
2452 enum hci_status status = HCI_STATUS_SUCCESS;
2453 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2454 u8 PhyLinkHandle, EntryNum, ShortRangeMode;
2456 PhyLinkHandle = pHciCmd->Data[0];
2457 ShortRangeMode = pHciCmd->Data[1];
2458 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x, Short_Range_Mode = 0x%x\n", PhyLinkHandle, ShortRangeMode));
2460 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2461 if (EntryNum != 0xff) {
2462 pBTInfo->BtAsocEntry[EntryNum].ShortRangeMode = ShortRangeMode;
2464 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PhyLinkHandle));
2465 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2468 bthci_EventCommandStatus(padapter,
2469 OGF_SET_EVENT_MASK_COMMAND,
2470 HCI_SHORT_RANGE_MODE,
2473 bthci_EventShortRangeModeChangeComplete(padapter, status, ShortRangeMode, EntryNum);
2478 static enum hci_status bthci_CmdReadLocalSupportedCommands(struct rtw_adapter *padapter)
2480 enum hci_status status = HCI_STATUS_SUCCESS;
2481 u8 localBuf[TmpLocalBufSize] = "";
2482 u8 *pRetPar, *pSupportedCmds;
2484 struct packet_irp_hcievent_data *PPacketIrpEvent;
2486 /* send command complete event here when all data are received. */
2487 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2488 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2490 len += bthci_CommandCompleteHeader(&localBuf[0],
2491 OGF_INFORMATIONAL_PARAMETERS,
2492 HCI_READ_LOCAL_SUPPORTED_COMMANDS,
2495 /* Return parameters starts from here */
2496 pRetPar = &PPacketIrpEvent->Data[len];
2497 pRetPar[0] = status; /* status */
2499 pSupportedCmds = &pRetPar[1];
2500 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[5]= 0xc0\nBit [6]= Set Event Mask, [7]= Reset\n"));
2501 pSupportedCmds[5] = 0xc0;
2502 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[6]= 0x01\nBit [0]= Set Event Filter\n"));
2503 pSupportedCmds[6] = 0x01;
2504 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[7]= 0x0c\nBit [2]= Read Connection Accept Timeout, [3]= Write Connection Accept Timeout\n"));
2505 pSupportedCmds[7] = 0x0c;
2506 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[10]= 0x80\nBit [7]= Host Number Of Completed Packets\n"));
2507 pSupportedCmds[10] = 0x80;
2508 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[11]= 0x03\nBit [0]= Read Link Supervision Timeout, [1]= Write Link Supervision Timeout\n"));
2509 pSupportedCmds[11] = 0x03;
2510 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"));
2511 pSupportedCmds[14] = 0xa8;
2512 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"));
2513 pSupportedCmds[15] = 0x1c;
2514 /* pSupportedCmds[16] = 0x04; */
2515 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[19]= 0x40\nBit [6]= Enhanced Flush\n"));
2516 pSupportedCmds[19] = 0x40;
2517 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"));
2518 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"));
2519 pSupportedCmds[21] = 0xff;
2520 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"));
2521 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"));
2522 pSupportedCmds[22] = 0xff;
2523 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"));
2524 pSupportedCmds[23] = 0x07;
2525 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"));
2526 pSupportedCmds[24] = 0x1c;
2528 PPacketIrpEvent->Length = len;
2530 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2535 static enum hci_status bthci_CmdReadLocalSupportedFeatures(struct rtw_adapter *padapter)
2537 enum hci_status status = HCI_STATUS_SUCCESS;
2538 u8 localBuf[TmpLocalBufSize] = "";
2541 struct packet_irp_hcievent_data *PPacketIrpEvent;
2543 /* send command complete event here when all data are received. */
2544 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2545 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2547 len += bthci_CommandCompleteHeader(&localBuf[0],
2548 OGF_INFORMATIONAL_PARAMETERS,
2549 HCI_READ_LOCAL_SUPPORTED_FEATURES,
2552 /* Return parameters starts from here */
2553 pRetPar = &PPacketIrpEvent->Data[len];
2554 pRetPar[0] = status; /* status */
2556 PPacketIrpEvent->Length = len;
2558 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2562 static enum hci_status bthci_CmdReadLocalAMPAssoc(struct rtw_adapter *padapter,
2563 struct packet_irp_hcicmd_data *pHciCmd)
2565 enum hci_status status = HCI_STATUS_SUCCESS;
2566 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2567 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
2568 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2569 u8 PhyLinkHandle, EntryNum;
2571 pBtDbg->dbgHciInfo.hciCmdCntReadLocalAmpAssoc++;
2572 PhyLinkHandle = *((u8 *)pHciCmd->Data);
2573 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2575 if ((EntryNum == 0xff) && PhyLinkHandle != 0) {
2576 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x\n",
2577 EntryNum, PhyLinkHandle));
2578 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2579 } else if (pBtMgnt->bPhyLinkInProgressStartLL) {
2580 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2581 pBtMgnt->bPhyLinkInProgressStartLL = false;
2583 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
2584 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
2585 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen = *((u16 *)((u8 *)pHciCmd->Data+3));
2586 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ReadLocalAMPAssoc, LenSoFar =%d, MaxRemoteASSOCLen =%d\n",
2587 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar,
2588 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen));
2591 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x, LengthSoFar = %x \n",
2592 EntryNum, PhyLinkHandle, pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar));
2594 /* send command complete event here when all data are received. */
2596 struct packet_irp_hcievent_data *PPacketIrpEvent;
2598 /* PVOID buffer = padapter->IrpHCILocalbuf.Ptr; */
2599 u8 localBuf[TmpLocalBufSize] = "";
2602 u16 typeLen = 0, remainLen = 0, ret_index = 0;
2605 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2606 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2607 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2609 totalLen += bthci_CommandCompleteHeader(&localBuf[0],
2610 OGF_STATUS_PARAMETERS,
2611 HCI_READ_LOCAL_AMP_ASSOC,
2613 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2614 /* Return parameters starts from here */
2615 pRetPar = &PPacketIrpEvent->Data[totalLen];
2616 pRetPar[0] = status; /* status */
2617 pRetPar[1] = *((u8 *)pHciCmd->Data);
2618 pRemainLen = (u16 *)&pRetPar[2]; /* AMP_ASSOC_Remaining_Length */
2619 totalLen += 4; /* 0]~[3] */
2622 typeLen = bthci_AssocMACAddr(padapter, &pRetPar[ret_index]);
2623 totalLen += typeLen;
2624 remainLen += typeLen;
2625 ret_index += typeLen;
2626 typeLen = bthci_AssocPreferredChannelList(padapter, &pRetPar[ret_index], EntryNum);
2627 totalLen += typeLen;
2628 remainLen += typeLen;
2629 ret_index += typeLen;
2630 typeLen = bthci_PALCapabilities(padapter, &pRetPar[ret_index]);
2631 totalLen += typeLen;
2632 remainLen += typeLen;
2633 ret_index += typeLen;
2634 typeLen = bthci_AssocPALVer(padapter, &pRetPar[ret_index]);
2635 totalLen += typeLen;
2636 remainLen += typeLen;
2637 PPacketIrpEvent->Length = (u8)totalLen;
2638 *pRemainLen = remainLen; /* AMP_ASSOC_Remaining_Length */
2639 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2640 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("AMP_ASSOC_fragment : \n"), PPacketIrpEvent->Data, totalLen);
2642 bthci_IndicateEvent(padapter, PPacketIrpEvent, totalLen+2);
2648 static enum hci_status bthci_CmdReadFailedContactCounter(struct rtw_adapter *padapter,
2649 struct packet_irp_hcicmd_data *pHciCmd)
2652 enum hci_status status = HCI_STATUS_SUCCESS;
2653 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2654 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2655 u8 localBuf[TmpLocalBufSize] = "";
2658 struct packet_irp_hcievent_data *PPacketIrpEvent;
2661 handle = *((u16 *)pHciCmd->Data);
2662 /* send command complete event here when all data are received. */
2663 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2664 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2666 len += bthci_CommandCompleteHeader(&localBuf[0],
2667 OGF_STATUS_PARAMETERS,
2668 HCI_READ_FAILED_CONTACT_COUNTER,
2671 /* Return parameters starts from here */
2672 pRetPar = &PPacketIrpEvent->Data[len];
2673 pRetPar[0] = status; /* status */
2674 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2675 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2676 pRetPar[3] = TWOBYTE_LOWBYTE(pBtHciInfo->FailContactCount);
2677 pRetPar[4] = TWOBYTE_HIGHTBYTE(pBtHciInfo->FailContactCount);
2679 PPacketIrpEvent->Length = len;
2681 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2686 static enum hci_status
2687 bthci_CmdResetFailedContactCounter(
2688 struct rtw_adapter *padapter,
2689 struct packet_irp_hcicmd_data *pHciCmd
2692 enum hci_status status = HCI_STATUS_SUCCESS;
2693 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2694 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2695 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2697 u8 localBuf[TmpLocalBufSize] = "";
2700 struct packet_irp_hcievent_data *PPacketIrpEvent;
2702 handle = *((u16 *)pHciCmd->Data);
2703 pBtHciInfo->FailContactCount = 0;
2705 /* send command complete event here when all data are received. */
2706 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2707 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2708 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2710 len += bthci_CommandCompleteHeader(&localBuf[0],
2711 OGF_STATUS_PARAMETERS,
2712 HCI_RESET_FAILED_CONTACT_COUNTER,
2715 /* Return parameters starts from here */
2716 pRetPar = &PPacketIrpEvent->Data[len];
2717 pRetPar[0] = status; /* status */
2718 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2719 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2721 PPacketIrpEvent->Length = len;
2723 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2728 /* BT 3.0+HS [Vol 2] 7.4.1 */
2730 static enum hci_status
2731 bthci_CmdReadLocalVersionInformation(
2732 struct rtw_adapter *padapter
2735 enum hci_status status = HCI_STATUS_SUCCESS;
2736 /* send command complete event here when all data are received. */
2737 u8 localBuf[TmpLocalBufSize] = "";
2740 struct packet_irp_hcievent_data *PPacketIrpEvent;
2743 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2744 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2746 len += bthci_CommandCompleteHeader(&localBuf[0],
2747 OGF_INFORMATIONAL_PARAMETERS,
2748 HCI_READ_LOCAL_VERSION_INFORMATION,
2751 /* Return parameters starts from here */
2752 pRetPar = &PPacketIrpEvent->Data[len];
2753 pRetPar[0] = status; /* status */
2754 pRetPar[1] = 0x05; /* HCI_Version */
2755 pu2Temp = (u16 *)&pRetPar[2]; /* HCI_Revision */
2757 pRetPar[4] = 0x05; /* LMP/PAL_Version */
2758 pu2Temp = (u16 *)&pRetPar[5]; /* Manufacturer_Name */
2760 pu2Temp = (u16 *)&pRetPar[7]; /* LMP/PAL_Subversion */
2763 PPacketIrpEvent->Length = len;
2765 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LOCAL_VERSION_INFORMATION\n"));
2766 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Status %x\n", status));
2767 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Version = 0x05\n"));
2768 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Revision = 0x0001\n"));
2769 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Version = 0x05\n"));
2770 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Manufacturer_Name = 0x0001\n"));
2771 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Subversion = 0x0001\n"));
2773 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2779 static enum hci_status bthci_CmdReadDataBlockSize(struct rtw_adapter *padapter)
2781 enum hci_status status = HCI_STATUS_SUCCESS;
2782 u8 localBuf[TmpLocalBufSize] = "";
2785 struct packet_irp_hcievent_data *PPacketIrpEvent;
2788 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2789 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2791 len += bthci_CommandCompleteHeader(&localBuf[0],
2792 OGF_INFORMATIONAL_PARAMETERS,
2793 HCI_READ_DATA_BLOCK_SIZE,
2796 /* Return parameters starts from here */
2797 pRetPar = &PPacketIrpEvent->Data[len];
2798 pRetPar[0] = HCI_STATUS_SUCCESS; /* status */
2799 pu2Temp = (u16 *)&pRetPar[1]; /* Max_ACL_Data_Packet_Length */
2800 *pu2Temp = Max80211PALPDUSize;
2802 pu2Temp = (u16 *)&pRetPar[3]; /* Data_Block_Length */
2803 *pu2Temp = Max80211PALPDUSize;
2804 pu2Temp = (u16 *)&pRetPar[5]; /* Total_Num_Data_Blocks */
2805 *pu2Temp = BTTotalDataBlockNum;
2807 PPacketIrpEvent->Length = len;
2809 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2815 static enum hci_status bthci_CmdReadBufferSize(struct rtw_adapter *padapter)
2817 enum hci_status status = HCI_STATUS_SUCCESS;
2818 u8 localBuf[TmpLocalBufSize] = "";
2821 struct packet_irp_hcievent_data *PPacketIrpEvent;
2824 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2825 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2826 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2828 len += bthci_CommandCompleteHeader(&localBuf[0],
2829 OGF_INFORMATIONAL_PARAMETERS,
2830 HCI_READ_BUFFER_SIZE,
2832 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Synchronous_Data_Packet_Length = 0x%x\n", BTSynDataPacketLength));
2833 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_ACL_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2834 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_Synchronous_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2835 /* Return parameters starts from here */
2836 pRetPar = &PPacketIrpEvent->Data[len];
2837 pRetPar[0] = status; /* status */
2838 pu2Temp = (u16 *)&pRetPar[1]; /* HC_ACL_Data_Packet_Length */
2839 *pu2Temp = Max80211PALPDUSize;
2841 pRetPar[3] = BTSynDataPacketLength; /* HC_Synchronous_Data_Packet_Length */
2842 pu2Temp = (u16 *)&pRetPar[4]; /* HC_Total_Num_ACL_Data_Packets */
2843 *pu2Temp = BTTotalDataBlockNum;
2844 pu2Temp = (u16 *)&pRetPar[6]; /* HC_Total_Num_Synchronous_Data_Packets */
2845 *pu2Temp = BTTotalDataBlockNum;
2847 PPacketIrpEvent->Length = len;
2849 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2854 static enum hci_status bthci_CmdReadLocalAMPInfo(struct rtw_adapter *padapter)
2856 enum hci_status status = HCI_STATUS_SUCCESS;
2857 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
2858 u8 localBuf[TmpLocalBufSize] = "";
2861 struct packet_irp_hcievent_data *PPacketIrpEvent;
2864 u32 TotalBandwidth = BTTOTALBANDWIDTH, MaxBandGUBandwidth = BTMAXBANDGUBANDWIDTH;
2865 u8 ControlType = 0x01, AmpStatus = 0x01;
2866 u32 MaxFlushTimeout = 10000, BestEffortFlushTimeout = 5000;
2867 u16 MaxPDUSize = Max80211PALPDUSize, PalCap = 0x1, AmpAssocLen = Max80211AMPASSOCLen, MinLatency = 20;
2869 if ((ppwrctrl->rfoff_reason & RF_CHANGE_BY_HW) ||
2870 (ppwrctrl->rfoff_reason & RF_CHANGE_BY_SW)) {
2871 AmpStatus = AMP_STATUS_NO_CAPACITY_FOR_BT;
2874 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2875 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2876 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2878 len += bthci_CommandCompleteHeader(&localBuf[0],
2879 OGF_STATUS_PARAMETERS,
2880 HCI_READ_LOCAL_AMP_INFO,
2883 /* Return parameters starts from here */
2884 pRetPar = &PPacketIrpEvent->Data[len];
2885 pRetPar[0] = status; /* status */
2886 pRetPar[1] = AmpStatus; /* AMP_Status */
2887 pu4Temp = (u32 *)&pRetPar[2]; /* Total_Bandwidth */
2888 *pu4Temp = TotalBandwidth; /* 0x19bfcc00;0x7530; */
2889 pu4Temp = (u32 *)&pRetPar[6]; /* Max_Guaranteed_Bandwidth */
2890 *pu4Temp = MaxBandGUBandwidth; /* 0x19bfcc00;0x4e20; */
2891 pu4Temp = (u32 *)&pRetPar[10]; /* Min_Latency */
2892 *pu4Temp = MinLatency; /* 150; */
2893 pu4Temp = (u32 *)&pRetPar[14]; /* Max_PDU_Size */
2894 *pu4Temp = MaxPDUSize;
2895 pRetPar[18] = ControlType; /* Controller_Type */
2896 pu2Temp = (u16 *)&pRetPar[19]; /* PAL_Capabilities */
2898 pu2Temp = (u16 *)&pRetPar[21]; /* AMP_ASSOC_Length */
2899 *pu2Temp = AmpAssocLen;
2900 pu4Temp = (u32 *)&pRetPar[23]; /* Max_Flush_Timeout */
2901 *pu4Temp = MaxFlushTimeout;
2902 pu4Temp = (u32 *)&pRetPar[27]; /* Best_Effort_Flush_Timeout */
2903 *pu4Temp = BestEffortFlushTimeout;
2905 PPacketIrpEvent->Length = len;
2906 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("AmpStatus = 0x%x\n",
2908 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TotalBandwidth = 0x%x, MaxBandGUBandwidth = 0x%x, MinLatency = 0x%x, \n MaxPDUSize = 0x%x, ControlType = 0x%x\n",
2909 TotalBandwidth, MaxBandGUBandwidth, MinLatency, MaxPDUSize, ControlType));
2910 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PalCap = 0x%x, AmpAssocLen = 0x%x, MaxFlushTimeout = 0x%x, BestEffortFlushTimeout = 0x%x\n",
2911 PalCap, AmpAssocLen, MaxFlushTimeout, BestEffortFlushTimeout));
2912 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2916 static enum hci_status
2917 bthci_CmdCreatePhysicalLink(
2918 struct rtw_adapter *padapter,
2919 struct packet_irp_hcicmd_data *pHciCmd
2922 enum hci_status status;
2923 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2924 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2926 pBtDbg->dbgHciInfo.hciCmdCntCreatePhyLink++;
2928 status = bthci_BuildPhysicalLink(padapter,
2929 pHciCmd, HCI_CREATE_PHYSICAL_LINK);
2934 static enum hci_status
2935 bthci_CmdReadLinkQuality(
2936 struct rtw_adapter *padapter,
2937 struct packet_irp_hcicmd_data *pHciCmd
2940 enum hci_status status = HCI_STATUS_SUCCESS;
2941 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2943 u8 EntryNum, LinkQuality = 0x55;
2945 PLH = *((u16 *)&pHciCmd->Data[0]);
2946 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x\n", PLH));
2948 EntryNum = bthci_GetCurrentEntryNum(padapter, (u8)PLH);
2949 if (EntryNum == 0xff) {
2950 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PLH));
2951 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2955 u8 localBuf[11] = "";
2958 struct packet_irp_hcievent_data *PPacketIrpEvent;
2960 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2962 len += bthci_CommandCompleteHeader(&localBuf[0],
2963 OGF_STATUS_PARAMETERS,
2964 HCI_READ_LINK_QUALITY,
2967 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" PLH = 0x%x\n Link Quality = 0x%x\n", PLH, LinkQuality));
2969 /* Return parameters starts from here */
2970 pRetPar = &PPacketIrpEvent->Data[len];
2971 pRetPar[0] = status; /* status */
2972 *((u16 *)&pRetPar[1]) = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle; /* Handle */
2973 pRetPar[3] = 0x55; /* Link Quailty */
2975 PPacketIrpEvent->Length = len;
2977 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2983 static enum hci_status bthci_CmdReadRSSI(struct rtw_adapter *padapter)
2985 return HCI_STATUS_SUCCESS;
2988 static enum hci_status
2989 bthci_CmdCreateLogicalLink(
2990 struct rtw_adapter *padapter,
2991 struct packet_irp_hcicmd_data *pHciCmd
2994 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2995 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2997 pBtDbg->dbgHciInfo.hciCmdCntCreateLogLink++;
2999 bthci_BuildLogicalLink(padapter, pHciCmd,
3000 HCI_CREATE_LOGICAL_LINK);
3002 return HCI_STATUS_SUCCESS;
3005 static enum hci_status
3006 bthci_CmdAcceptLogicalLink(
3007 struct rtw_adapter *padapter,
3008 struct packet_irp_hcicmd_data *pHciCmd
3011 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3012 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3014 pBtDbg->dbgHciInfo.hciCmdCntAcceptLogLink++;
3016 bthci_BuildLogicalLink(padapter, pHciCmd,
3017 HCI_ACCEPT_LOGICAL_LINK);
3019 return HCI_STATUS_SUCCESS;
3022 static enum hci_status
3023 bthci_CmdDisconnectLogicalLink(
3024 struct rtw_adapter *padapter,
3025 struct packet_irp_hcicmd_data *pHciCmd
3028 enum hci_status status = HCI_STATUS_SUCCESS;
3029 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3030 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3031 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3032 struct bt_dgb *pBtDbg = &pBTinfo->BtDbg;
3034 u8 i, j, find = 0, LogLinkCount = 0;
3036 pBtDbg->dbgHciInfo.hciCmdCntDisconnectLogLink++;
3038 logicHandle = *((u16 *)pHciCmd->Data);
3039 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle = 0x%x\n", logicHandle));
3041 /* find an created logical link index and clear the data */
3042 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3043 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3044 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3045 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle is matched 0x%x\n", logicHandle));
3046 bthci_ResetFlowSpec(padapter, j, i);
3048 pBtMgnt->DisconnectEntryNum = j;
3055 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3058 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3059 if (pBTinfo->BtAsocEntry[pBtMgnt->DisconnectEntryNum].LogLinkCmdData[i].BtLogLinkhandle != 0)
3063 /* When we receive Create logical link command, we should send command status event first. */
3064 bthci_EventCommandStatus(padapter,
3065 LINK_CONTROL_COMMANDS,
3066 HCI_DISCONNECT_LOGICAL_LINK,
3069 /* When we determines the logical link is established, we should send command complete event. */
3071 if (status == HCI_STATUS_SUCCESS) {
3072 bthci_EventDisconnectLogicalLinkComplete(padapter, status,
3073 logicHandle, HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST);
3076 if (LogLinkCount == 0)
3077 mod_timer(&pBTinfo->BTDisconnectPhyLinkTimer,
3078 jiffies + msecs_to_jiffies(100));
3083 static enum hci_status
3084 bthci_CmdLogicalLinkCancel(struct rtw_adapter *padapter,
3085 struct packet_irp_hcicmd_data *pHciCmd)
3087 enum hci_status status = HCI_STATUS_SUCCESS;
3088 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3089 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3090 u8 CurrentEntryNum, CurrentLogEntryNum;
3092 u8 physicalLinkHandle, TxFlowSpecID, i;
3093 u16 CurrentLogicalHandle;
3095 physicalLinkHandle = *((u8 *)pHciCmd->Data);
3096 TxFlowSpecID = *(((u8 *)pHciCmd->Data)+1);
3098 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, physicalLinkHandle = 0x%x, TxFlowSpecID = 0x%x\n",
3099 physicalLinkHandle, TxFlowSpecID));
3101 CurrentEntryNum = pBtMgnt->CurrentConnectEntryNum;
3102 CurrentLogicalHandle = pBtMgnt->BtCurrentLogLinkhandle;
3104 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("CurrentEntryNum = 0x%x, CurrentLogicalHandle = 0x%x\n",
3105 CurrentEntryNum, CurrentLogicalHandle));
3107 CurrentLogEntryNum = 0xff;
3108 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3109 if ((CurrentLogicalHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtLogLinkhandle) &&
3110 (physicalLinkHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtPhyLinkhandle)) {
3111 CurrentLogEntryNum = i;
3116 if (CurrentLogEntryNum == 0xff) {
3117 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, CurrentLogEntryNum == 0xff !!!!\n"));
3118 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3121 if (pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCompleteEventIsSet) {
3122 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, LLCompleteEventIsSet!!!!\n"));
3123 status = HCI_STATUS_ACL_CONNECT_EXISTS;
3128 u8 localBuf[8] = "";
3131 struct packet_irp_hcievent_data *PPacketIrpEvent;
3133 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3135 len += bthci_CommandCompleteHeader(&localBuf[0],
3136 LINK_CONTROL_COMMANDS,
3137 HCI_LOGICAL_LINK_CANCEL,
3140 /* Return parameters starts from here */
3141 pRetPar = &PPacketIrpEvent->Data[len];
3142 pRetPar[0] = status; /* status */
3143 pRetPar[1] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtPhyLinkhandle;
3144 pRetPar[2] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtTxFlowSpecID;
3146 PPacketIrpEvent->Length = len;
3148 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3151 pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCancelCMDIsSetandComplete = true;
3156 static enum hci_status
3157 bthci_CmdFlowSpecModify(struct rtw_adapter *padapter,
3158 struct packet_irp_hcicmd_data *pHciCmd)
3160 enum hci_status status = HCI_STATUS_SUCCESS;
3161 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3162 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3166 logicHandle = *((u16 *)pHciCmd->Data);
3167 /* find an matched logical link index and copy the data */
3168 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3169 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3170 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3171 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec,
3172 &pHciCmd->Data[2], sizeof(struct hci_flow_spec));
3173 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Rx_Flow_Spec,
3174 &pHciCmd->Data[18], sizeof(struct hci_flow_spec));
3176 bthci_CheckLogLinkBehavior(padapter, pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec);
3182 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("FlowSpecModify, LLH = 0x%x, \n", logicHandle));
3184 /* When we receive Flow Spec Modify command, we should send command status event first. */
3185 bthci_EventCommandStatus(padapter,
3186 LINK_CONTROL_COMMANDS,
3187 HCI_FLOW_SPEC_MODIFY,
3188 HCI_STATUS_SUCCESS);
3191 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3193 bthci_EventSendFlowSpecModifyComplete(padapter, status, logicHandle);
3198 static enum hci_status
3199 bthci_CmdAcceptPhysicalLink(struct rtw_adapter *padapter,
3200 struct packet_irp_hcicmd_data *pHciCmd)
3202 enum hci_status status;
3203 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3204 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3206 pBtDbg->dbgHciInfo.hciCmdCntAcceptPhyLink++;
3208 status = bthci_BuildPhysicalLink(padapter,
3209 pHciCmd, HCI_ACCEPT_PHYSICAL_LINK);
3214 static enum hci_status
3215 bthci_CmdDisconnectPhysicalLink(struct rtw_adapter *padapter,
3216 struct packet_irp_hcicmd_data *pHciCmd)
3218 enum hci_status status = HCI_STATUS_SUCCESS;
3219 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3220 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3221 u8 PLH, CurrentEntryNum, PhysLinkDisconnectReason;
3223 pBtDbg->dbgHciInfo.hciCmdCntDisconnectPhyLink++;
3225 PLH = *((u8 *)pHciCmd->Data);
3226 PhysLinkDisconnectReason = (*((u8 *)pHciCmd->Data+1));
3227 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK PhyHandle = 0x%x, Reason = 0x%x\n",
3228 PLH, PhysLinkDisconnectReason));
3230 CurrentEntryNum = bthci_GetCurrentEntryNum(padapter, PLH);
3232 if (CurrentEntryNum == 0xff) {
3233 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
3234 ("DisconnectPhysicalLink, No such Handle in the Entry\n"));
3235 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3237 pBTInfo->BtAsocEntry[CurrentEntryNum].PhyLinkDisconnectReason =
3238 (enum hci_status)PhysLinkDisconnectReason;
3240 /* Send HCI Command status event to AMP. */
3241 bthci_EventCommandStatus(padapter, LINK_CONTROL_COMMANDS,
3242 HCI_DISCONNECT_PHYSICAL_LINK, status);
3244 if (status != HCI_STATUS_SUCCESS)
3247 /* The macros below require { and } in the if statement */
3248 if (pBTInfo->BtAsocEntry[CurrentEntryNum].BtCurrentState == HCI_STATE_DISCONNECTED) {
3249 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3251 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3256 static enum hci_status
3257 bthci_CmdSetACLLinkDataFlowMode(struct rtw_adapter *padapter,
3258 struct packet_irp_hcicmd_data *pHciCmd)
3260 enum hci_status status = HCI_STATUS_SUCCESS;
3261 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3262 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3263 u8 localBuf[8] = "";
3266 struct packet_irp_hcievent_data *PPacketIrpEvent;
3269 pBtMgnt->ExtConfig.CurrentConnectHandle = *((u16 *)pHciCmd->Data);
3270 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = *((u8 *)pHciCmd->Data)+2;
3271 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = *((u8 *)pHciCmd->Data)+3;
3272 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Connection Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic mode = 0x%x",
3273 pBtMgnt->ExtConfig.CurrentConnectHandle,
3274 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode,
3275 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode));
3278 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3280 len += bthci_CommandCompleteHeader(&localBuf[0],
3282 HCI_SET_ACL_LINK_DATA_FLOW_MODE,
3285 /* Return parameters starts from here */
3286 pRetPar = &PPacketIrpEvent->Data[len];
3287 pRetPar[0] = status; /* status */
3289 pu2Temp = (u16 *)&pRetPar[1];
3290 *pu2Temp = pBtMgnt->ExtConfig.CurrentConnectHandle;
3292 PPacketIrpEvent->Length = len;
3294 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3298 static enum hci_status
3299 bthci_CmdSetACLLinkStatus(struct rtw_adapter *padapter,
3300 struct packet_irp_hcicmd_data *pHciCmd)
3302 enum hci_status status = HCI_STATUS_SUCCESS;
3303 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3304 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3305 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3309 pBtDbg->dbgHciInfo.hciCmdCntSetAclLinkStatus++;
3310 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "SetACLLinkStatus, Hex Data :\n",
3311 &pHciCmd->Data[0], pHciCmd->Length);
3313 /* Only Core Stack v251 and later version support this command. */
3314 pBtMgnt->bSupportProfile = true;
3316 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3317 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3319 pTriple = &pHciCmd->Data[1];
3320 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3321 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3322 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = pTriple[2];
3323 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = pTriple[3];
3324 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3325 ("Connection_Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic Mode = 0x%x\n",
3326 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3327 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode,
3328 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode));
3333 u8 localBuf[6] = "";
3336 struct packet_irp_hcievent_data *PPacketIrpEvent;
3338 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3340 len += bthci_CommandCompleteHeader(&localBuf[0],
3342 HCI_SET_ACL_LINK_STATUS,
3345 /* Return parameters starts from here */
3346 pRetPar = &PPacketIrpEvent->Data[len];
3347 pRetPar[0] = status; /* status */
3350 PPacketIrpEvent->Length = len;
3352 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3358 static enum hci_status
3359 bthci_CmdSetSCOLinkStatus(
3360 struct rtw_adapter *padapter,
3361 struct packet_irp_hcicmd_data *pHciCmd
3364 enum hci_status status = HCI_STATUS_SUCCESS;
3365 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3366 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3367 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3369 pBtDbg->dbgHciInfo.hciCmdCntSetScoLinkStatus++;
3370 pBtMgnt->ExtConfig.NumberOfSCO = *((u8 *)pHciCmd->Data);
3371 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfSCO = 0x%x\n",
3372 pBtMgnt->ExtConfig.NumberOfSCO));
3375 u8 localBuf[6] = "";
3378 struct packet_irp_hcievent_data *PPacketIrpEvent;
3380 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3382 len += bthci_CommandCompleteHeader(&localBuf[0],
3384 HCI_SET_SCO_LINK_STATUS,
3387 /* Return parameters starts from here */
3388 pRetPar = &PPacketIrpEvent->Data[len];
3389 pRetPar[0] = status; /* status */
3392 PPacketIrpEvent->Length = len;
3394 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3400 static enum hci_status
3401 bthci_CmdSetRSSIValue(
3402 struct rtw_adapter *padapter,
3403 struct packet_irp_hcicmd_data *pHciCmd
3406 enum hci_status status = HCI_STATUS_SUCCESS;
3407 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3408 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3411 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3412 if (pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle == *((u16 *)&pHciCmd->Data[0])) {
3413 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = (s8)(pHciCmd->Data[2]);
3414 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL,
3415 ("Connection_Handle = 0x%x, RSSI = %d \n",
3416 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3417 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI));
3419 /* get the minimum bt rssi value */
3420 if (pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI <= min_bt_rssi)
3421 min_bt_rssi = pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI;
3424 pBtMgnt->ExtConfig.MIN_BT_RSSI = min_bt_rssi;
3425 RTPRINT(FBT, BT_TRACE, ("[bt rssi], the min rssi is %d\n", min_bt_rssi));
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],
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_CmdSetCurrentBluetoothStatus(
3455 struct rtw_adapter *padapter,
3456 struct packet_irp_hcicmd_data *pHciCmd
3459 enum hci_status status = HCI_STATUS_SUCCESS;
3460 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3461 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3462 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3464 pBtMgnt->ExtConfig.CurrentBTStatus = *((u8 *)&pHciCmd->Data[0]);
3465 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("SetCurrentBluetoothStatus, CurrentBTStatus = 0x%x\n",
3466 pBtMgnt->ExtConfig.CurrentBTStatus));
3469 u8 localBuf[6] = "";
3472 struct packet_irp_hcievent_data *PPacketIrpEvent;
3474 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3476 len += bthci_CommandCompleteHeader(&localBuf[0],
3478 HCI_SET_CURRENT_BLUETOOTH_STATUS,
3481 /* Return parameters starts from here */
3482 pRetPar = &PPacketIrpEvent->Data[len];
3483 pRetPar[0] = status; /* status */
3486 PPacketIrpEvent->Length = len;
3488 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3494 static enum hci_status
3495 bthci_CmdExtensionVersionNotify(
3496 struct rtw_adapter *padapter,
3497 struct packet_irp_hcicmd_data *pHciCmd
3500 enum hci_status status = HCI_STATUS_SUCCESS;
3501 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3502 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3503 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3505 pBtDbg->dbgHciInfo.hciCmdCntExtensionVersionNotify++;
3506 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "ExtensionVersionNotify, Hex Data :\n",
3507 &pHciCmd->Data[0], pHciCmd->Length);
3509 pBtMgnt->ExtConfig.HCIExtensionVer = *((u16 *)&pHciCmd->Data[0]);
3510 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = 0x%x\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3513 u8 localBuf[6] = "";
3516 struct packet_irp_hcievent_data *PPacketIrpEvent;
3518 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3520 len += bthci_CommandCompleteHeader(&localBuf[0],
3522 HCI_EXTENSION_VERSION_NOTIFY,
3525 /* Return parameters starts from here */
3526 pRetPar = &PPacketIrpEvent->Data[len];
3527 pRetPar[0] = status; /* status */
3530 PPacketIrpEvent->Length = len;
3532 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3538 static enum hci_status
3539 bthci_CmdLinkStatusNotify(
3540 struct rtw_adapter *padapter,
3541 struct packet_irp_hcicmd_data *pHciCmd
3544 enum hci_status status = HCI_STATUS_SUCCESS;
3545 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3546 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3547 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3551 pBtDbg->dbgHciInfo.hciCmdCntLinkStatusNotify++;
3552 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "LinkStatusNotify, Hex Data :\n",
3553 &pHciCmd->Data[0], pHciCmd->Length);
3555 /* Current only RTL8723 support this command. */
3556 pBtMgnt->bSupportProfile = true;
3558 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3559 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3560 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = %d\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3562 pTriple = &pHciCmd->Data[1];
3563 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3564 if (pBtMgnt->ExtConfig.HCIExtensionVer < 1) {
3565 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3566 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3567 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3568 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3569 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d\n",
3570 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3571 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3572 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec));
3574 } else if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
3575 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3576 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3577 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3578 pBtMgnt->ExtConfig.linkInfo[i].linkRole = pTriple[4];
3579 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3580 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d, LinkRole =%d\n",
3581 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3582 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3583 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec,
3584 pBtMgnt->ExtConfig.linkInfo[i].linkRole));
3589 BTHCI_UpdateBTProfileRTKToMoto(padapter);
3591 u8 localBuf[6] = "";
3594 struct packet_irp_hcievent_data *PPacketIrpEvent;
3596 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3598 len += bthci_CommandCompleteHeader(&localBuf[0],
3600 HCI_LINK_STATUS_NOTIFY,
3603 /* Return parameters starts from here */
3604 pRetPar = &PPacketIrpEvent->Data[len];
3605 pRetPar[0] = status; /* status */
3608 PPacketIrpEvent->Length = len;
3610 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3616 static enum hci_status
3617 bthci_CmdBtOperationNotify(
3618 struct rtw_adapter *padapter,
3619 struct packet_irp_hcicmd_data *pHciCmd
3622 enum hci_status status = HCI_STATUS_SUCCESS;
3623 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3624 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3626 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Bt Operation notify, Hex Data :\n",
3627 &pHciCmd->Data[0], pHciCmd->Length);
3629 pBtMgnt->ExtConfig.btOperationCode = *((u8 *)pHciCmd->Data);
3630 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("btOperationCode = 0x%x\n", pBtMgnt->ExtConfig.btOperationCode));
3631 switch (pBtMgnt->ExtConfig.btOperationCode) {
3632 case HCI_BT_OP_NONE:
3633 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Operation None!!\n"));
3635 case HCI_BT_OP_INQUIRY_START:
3636 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire start!!\n"));
3638 case HCI_BT_OP_INQUIRY_FINISH:
3639 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire finished!!\n"));
3641 case HCI_BT_OP_PAGING_START:
3642 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging is started!!\n"));
3644 case HCI_BT_OP_PAGING_SUCCESS:
3645 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete successfully!!\n"));
3647 case HCI_BT_OP_PAGING_UNSUCCESS:
3648 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete unsuccessfully!!\n"));
3650 case HCI_BT_OP_PAIRING_START:
3651 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing start!!\n"));
3653 case HCI_BT_OP_PAIRING_FINISH:
3654 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing finished!!\n"));
3656 case HCI_BT_OP_BT_DEV_ENABLE:
3657 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is enabled!!\n"));
3659 case HCI_BT_OP_BT_DEV_DISABLE:
3660 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is disabled!!\n"));
3663 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Unknown, error!!\n"));
3666 BTDM_AdjustForBtOperation(padapter);
3668 u8 localBuf[6] = "";
3671 struct packet_irp_hcievent_data *PPacketIrpEvent;
3673 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3675 len += bthci_CommandCompleteHeader(&localBuf[0],
3677 HCI_BT_OPERATION_NOTIFY,
3680 /* Return parameters starts from here */
3681 pRetPar = &PPacketIrpEvent->Data[len];
3682 pRetPar[0] = status; /* status */
3685 PPacketIrpEvent->Length = len;
3687 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3693 static enum hci_status
3694 bthci_CmdEnableWifiScanNotify(struct rtw_adapter *padapter,
3695 struct packet_irp_hcicmd_data *pHciCmd)
3697 enum hci_status status = HCI_STATUS_SUCCESS;
3698 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3699 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3701 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Enable Wifi scan notify, Hex Data :\n",
3702 &pHciCmd->Data[0], pHciCmd->Length);
3704 pBtMgnt->ExtConfig.bEnableWifiScanNotify = *((u8 *)pHciCmd->Data);
3705 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("bEnableWifiScanNotify = %d\n", pBtMgnt->ExtConfig.bEnableWifiScanNotify));
3708 u8 localBuf[6] = "";
3711 struct packet_irp_hcievent_data *PPacketIrpEvent;
3713 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3715 len += bthci_CommandCompleteHeader(&localBuf[0],
3717 HCI_ENABLE_WIFI_SCAN_NOTIFY,
3720 /* Return parameters starts from here */
3721 pRetPar = &PPacketIrpEvent->Data[len];
3722 pRetPar[0] = status; /* status */
3725 PPacketIrpEvent->Length = len;
3727 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3733 static enum hci_status
3734 bthci_CmdWIFICurrentChannel(struct rtw_adapter *padapter,
3735 struct packet_irp_hcicmd_data *pHciCmd)
3737 enum hci_status status = HCI_STATUS_SUCCESS;
3738 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3739 u8 chnl = pmlmeext->cur_channel;
3741 if (pmlmeext->cur_bwmode == HT_CHANNEL_WIDTH_40) {
3742 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
3744 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
3748 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current Channel = 0x%x\n", chnl));
3751 u8 localBuf[8] = "";
3754 struct packet_irp_hcievent_data *PPacketIrpEvent;
3756 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3758 len += bthci_CommandCompleteHeader(&localBuf[0],
3760 HCI_WIFI_CURRENT_CHANNEL,
3763 /* Return parameters starts from here */
3764 pRetPar = &PPacketIrpEvent->Data[len];
3765 pRetPar[0] = status; /* status */
3766 pRetPar[1] = chnl; /* current channel */
3768 PPacketIrpEvent->Length = len;
3770 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3776 static enum hci_status
3777 bthci_CmdWIFICurrentBandwidth(struct rtw_adapter *padapter,
3778 struct packet_irp_hcicmd_data *pHciCmd)
3780 enum hci_status status = HCI_STATUS_SUCCESS;
3781 enum ht_channel_width bw;
3784 bw = padapter->mlmeextpriv.cur_bwmode;
3786 if (bw == HT_CHANNEL_WIDTH_20)
3788 else if (bw == HT_CHANNEL_WIDTH_40)
3791 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current BW = 0x%x\n",
3795 u8 localBuf[8] = "";
3798 struct packet_irp_hcievent_data *PPacketIrpEvent;
3800 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3802 len += bthci_CommandCompleteHeader(&localBuf[0],
3804 HCI_WIFI_CURRENT_BANDWIDTH,
3807 /* Return parameters starts from here */
3808 pRetPar = &PPacketIrpEvent->Data[len];
3809 pRetPar[0] = status; /* status */
3810 pRetPar[1] = CurrentBW; /* current BW */
3812 PPacketIrpEvent->Length = len;
3814 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3820 static enum hci_status
3821 bthci_CmdWIFIConnectionStatus(
3822 struct rtw_adapter *padapter,
3823 struct packet_irp_hcicmd_data *pHciCmd
3826 enum hci_status status = HCI_STATUS_SUCCESS;
3827 u8 connectStatus = HCI_WIFI_NOT_CONNECTED;
3829 if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) {
3830 if (padapter->stapriv.asoc_sta_count >= 3)
3831 connectStatus = HCI_WIFI_CONNECTED;
3833 connectStatus = HCI_WIFI_NOT_CONNECTED;
3834 } else if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE|WIFI_ASOC_STATE)) {
3835 connectStatus = HCI_WIFI_CONNECTED;
3836 } else if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING)) {
3837 connectStatus = HCI_WIFI_CONNECT_IN_PROGRESS;
3839 connectStatus = HCI_WIFI_NOT_CONNECTED;
3843 u8 localBuf[8] = "";
3846 struct packet_irp_hcievent_data *PPacketIrpEvent;
3848 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3850 len += bthci_CommandCompleteHeader(&localBuf[0],
3852 HCI_WIFI_CONNECTION_STATUS,
3855 /* Return parameters starts from here */
3856 pRetPar = &PPacketIrpEvent->Data[len];
3857 pRetPar[0] = status; /* status */
3858 pRetPar[1] = connectStatus; /* connect status */
3860 PPacketIrpEvent->Length = len;
3862 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3868 static enum hci_status
3869 bthci_CmdEnableDeviceUnderTestMode(
3870 struct rtw_adapter *padapter,
3871 struct packet_irp_hcicmd_data *pHciCmd
3874 enum hci_status status = HCI_STATUS_SUCCESS;
3875 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3876 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3878 pBtHciInfo->bInTestMode = true;
3879 pBtHciInfo->bTestIsEnd = false;
3881 /* send command complete event here when all data are received. */
3883 u8 localBuf[6] = "";
3886 struct packet_irp_hcievent_data *PPacketIrpEvent;
3888 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3890 len += bthci_CommandCompleteHeader(&localBuf[0],
3891 OGF_TESTING_COMMANDS,
3892 HCI_ENABLE_DEVICE_UNDER_TEST_MODE,
3895 /* Return parameters starts from here */
3896 pRetPar = &PPacketIrpEvent->Data[len];
3897 pRetPar[0] = status; /* status */
3899 PPacketIrpEvent->Length = len;
3901 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3907 static enum hci_status
3908 bthci_CmdAMPTestEnd(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->bTestIsEnd = true;
3923 del_timer_sync(&pBTInfo->BTTestSendPacketTimer);
3925 rtl8723a_check_bssid(padapter, true);
3927 /* send command complete event here when all data are received. */
3929 u8 localBuf[4] = "";
3930 struct packet_irp_hcievent_data *PPacketIrpEvent;
3932 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3933 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3934 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3935 PPacketIrpEvent->Length = 2;
3937 PPacketIrpEvent->Data[0] = status;
3938 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario;
3940 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3943 bthci_EventAMPReceiverReport(padapter, 0x01);
3948 static enum hci_status
3949 bthci_CmdAMPTestCommand(struct rtw_adapter *padapter,
3950 struct packet_irp_hcicmd_data *pHciCmd)
3952 enum hci_status status = HCI_STATUS_SUCCESS;
3953 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3954 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3956 if (!pBtHciInfo->bInTestMode) {
3957 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3958 status = HCI_STATUS_CMD_DISALLOW;
3962 pBtHciInfo->TestScenario = *((u8 *)pHciCmd->Data);
3964 if (pBtHciInfo->TestScenario == 0x01)
3965 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
3966 else if (pBtHciInfo->TestScenario == 0x02)
3967 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
3969 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("No Such Test !!!!!!!!!!!!!!!!!! \n"));
3971 if (pBtHciInfo->bTestIsEnd) {
3972 u8 localBuf[5] = "";
3973 struct packet_irp_hcievent_data *PPacketIrpEvent;
3975 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3976 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3977 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3978 PPacketIrpEvent->Length = 2;
3980 PPacketIrpEvent->Data[0] = status;
3981 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
3983 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3985 /* Return to Idel state with RX and TX off. */
3990 /* should send command status event */
3991 bthci_EventCommandStatus(padapter,
3992 OGF_TESTING_COMMANDS,
3993 HCI_AMP_TEST_COMMAND,
3996 /* The HCI_AMP_Start Test Event shall be generated when the */
3997 /* HCI_AMP_Test_Command has completed and the first data is ready to be sent */
4001 u8 localBuf[5] = "";
4002 struct packet_irp_hcievent_data *PPacketIrpEvent;
4004 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_AMP_Start Test Event \n"));
4005 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4006 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_START_TEST;
4007 PPacketIrpEvent->Length = 2;
4009 PPacketIrpEvent->Data[0] = status;
4010 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
4012 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
4014 /* Return to Idel state with RX and TX off. */
4017 if (pBtHciInfo->TestScenario == 0x01) {
4019 When in a transmitter test scenario and the frames/bursts count have been
4020 transmitted the HCI_AMP_Test_End event shall be sent.
4022 mod_timer(&pBTInfo->BTTestSendPacketTimer,
4023 jiffies + msecs_to_jiffies(50));
4024 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
4025 } else if (pBtHciInfo->TestScenario == 0x02) {
4026 rtl8723a_check_bssid(padapter, false);
4027 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
4033 static enum hci_status
4034 bthci_CmdEnableAMPReceiverReports(struct rtw_adapter *padapter,
4035 struct packet_irp_hcicmd_data *pHciCmd)
4037 enum hci_status status = HCI_STATUS_SUCCESS;
4038 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4039 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4041 if (!pBtHciInfo->bInTestMode) {
4042 status = HCI_STATUS_CMD_DISALLOW;
4043 /* send command complete event here when all data are received. */
4045 u8 localBuf[6] = "";
4048 struct packet_irp_hcievent_data *PPacketIrpEvent;
4050 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4052 len += bthci_CommandCompleteHeader(&localBuf[0],
4053 OGF_TESTING_COMMANDS,
4054 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4057 /* Return parameters starts from here */
4058 pRetPar = &PPacketIrpEvent->Data[len];
4059 pRetPar[0] = status; /* status */
4061 PPacketIrpEvent->Length = len;
4063 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4068 pBtHciInfo->bTestNeedReport = *((u8 *)pHciCmd->Data);
4069 pBtHciInfo->TestReportInterval = (*((u8 *)pHciCmd->Data+2));
4071 bthci_EventAMPReceiverReport(padapter, 0x00);
4073 /* send command complete event here when all data are received. */
4075 u8 localBuf[6] = "";
4078 struct packet_irp_hcievent_data *PPacketIrpEvent;
4080 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4082 len += bthci_CommandCompleteHeader(&localBuf[0],
4083 OGF_TESTING_COMMANDS,
4084 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4087 /* Return parameters starts from here */
4088 pRetPar = &PPacketIrpEvent->Data[len];
4089 pRetPar[0] = status; /* status */
4091 PPacketIrpEvent->Length = len;
4093 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4099 static enum hci_status
4100 bthci_CmdHostBufferSize(struct rtw_adapter *padapter,
4101 struct packet_irp_hcicmd_data *pHciCmd)
4103 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4104 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4105 struct packet_irp_hcievent_data *PPacketIrpEvent;
4106 enum hci_status status = HCI_STATUS_SUCCESS;
4107 u8 localBuf[6] = "";
4111 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].ACLPacketsData.ACLDataPacketLen = *((u16 *)pHciCmd->Data);
4112 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].SyncDataPacketLen = *((u8 *)(pHciCmd->Data+2));
4113 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalNumACLDataPackets = *((u16 *)(pHciCmd->Data+3));
4114 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalSyncNumDataPackets = *((u16 *)(pHciCmd->Data+5));
4116 /* send command complete event here when all data are received. */
4117 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4119 len += bthci_CommandCompleteHeader(&localBuf[0],
4120 OGF_SET_EVENT_MASK_COMMAND,
4121 HCI_HOST_BUFFER_SIZE,
4124 /* Return parameters starts from here */
4125 pRetPar = &PPacketIrpEvent->Data[len];
4126 pRetPar[0] = status; /* status */
4128 PPacketIrpEvent->Length = len;
4130 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4135 static enum hci_status
4136 bthci_CmdHostNumberOfCompletedPackets(struct rtw_adapter *padapter,
4137 struct packet_irp_hcicmd_data *pHciCmd)
4139 return HCI_STATUS_SUCCESS;
4142 static enum hci_status
4143 bthci_UnknownCMD(struct rtw_adapter *padapter, struct packet_irp_hcicmd_data *pHciCmd)
4145 enum hci_status status = HCI_STATUS_UNKNOW_HCI_CMD;
4146 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4147 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
4149 pBtDbg->dbgHciInfo.hciCmdCntUnknown++;
4150 bthci_EventCommandStatus(padapter,
4158 static enum hci_status
4159 bthci_HandleOGFInformationalParameters(struct rtw_adapter *padapter,
4160 struct packet_irp_hcicmd_data *pHciCmd)
4162 enum hci_status status = HCI_STATUS_SUCCESS;
4164 switch (pHciCmd->OCF) {
4165 case HCI_READ_LOCAL_VERSION_INFORMATION:
4166 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_VERSION_INFORMATION\n"));
4167 status = bthci_CmdReadLocalVersionInformation(padapter);
4169 case HCI_READ_LOCAL_SUPPORTED_COMMANDS:
4170 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_COMMANDS\n"));
4171 status = bthci_CmdReadLocalSupportedCommands(padapter);
4173 case HCI_READ_LOCAL_SUPPORTED_FEATURES:
4174 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_FEATURES\n"));
4175 status = bthci_CmdReadLocalSupportedFeatures(padapter);
4177 case HCI_READ_BUFFER_SIZE:
4178 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BUFFER_SIZE\n"));
4179 status = bthci_CmdReadBufferSize(padapter);
4181 case HCI_READ_DATA_BLOCK_SIZE:
4182 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_DATA_BLOCK_SIZE\n"));
4183 status = bthci_CmdReadDataBlockSize(padapter);
4186 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFInformationalParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4187 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4188 status = bthci_UnknownCMD(padapter, pHciCmd);
4194 static enum hci_status
4195 bthci_HandleOGFSetEventMaskCMD(struct rtw_adapter *padapter,
4196 struct packet_irp_hcicmd_data *pHciCmd)
4198 enum hci_status status = HCI_STATUS_SUCCESS;
4200 switch (pHciCmd->OCF) {
4201 case HCI_SET_EVENT_MASK:
4202 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK\n"));
4203 status = bthci_CmdSetEventMask(padapter, pHciCmd);
4206 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET\n"));
4207 status = bthci_CmdReset(padapter, true);
4209 case HCI_READ_CONNECTION_ACCEPT_TIMEOUT:
4210 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_CONNECTION_ACCEPT_TIMEOUT\n"));
4211 status = bthci_CmdReadConnectionAcceptTimeout(padapter);
4213 case HCI_SET_EVENT_FILTER:
4214 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_FILTER\n"));
4215 status = bthci_CmdSetEventFilter(padapter, pHciCmd);
4217 case HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT:
4218 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT\n"));
4219 status = bthci_CmdWriteConnectionAcceptTimeout(padapter, pHciCmd);
4221 case HCI_READ_PAGE_TIMEOUT:
4222 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_PAGE_TIMEOUT\n"));
4223 status = bthci_CmdReadPageTimeout(padapter, pHciCmd);
4225 case HCI_WRITE_PAGE_TIMEOUT:
4226 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_PAGE_TIMEOUT\n"));
4227 status = bthci_CmdWritePageTimeout(padapter, pHciCmd);
4229 case HCI_HOST_NUMBER_OF_COMPLETED_PACKETS:
4230 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_NUMBER_OF_COMPLETED_PACKETS\n"));
4231 status = bthci_CmdHostNumberOfCompletedPackets(padapter, pHciCmd);
4233 case HCI_READ_LINK_SUPERVISION_TIMEOUT:
4234 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_SUPERVISION_TIMEOUT\n"));
4235 status = bthci_CmdReadLinkSupervisionTimeout(padapter, pHciCmd);
4237 case HCI_WRITE_LINK_SUPERVISION_TIMEOUT:
4238 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LINK_SUPERVISION_TIMEOUT\n"));
4239 status = bthci_CmdWriteLinkSupervisionTimeout(padapter, pHciCmd);
4241 case HCI_ENHANCED_FLUSH:
4242 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENHANCED_FLUSH\n"));
4243 status = bthci_CmdEnhancedFlush(padapter, pHciCmd);
4245 case HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT:
4246 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4247 status = bthci_CmdReadLogicalLinkAcceptTimeout(padapter, pHciCmd);
4249 case HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT:
4250 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4251 status = bthci_CmdWriteLogicalLinkAcceptTimeout(padapter, pHciCmd);
4253 case HCI_SET_EVENT_MASK_PAGE_2:
4254 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK_PAGE_2\n"));
4255 status = bthci_CmdSetEventMaskPage2(padapter, pHciCmd);
4257 case HCI_READ_LOCATION_DATA:
4258 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCATION_DATA\n"));
4259 status = bthci_CmdReadLocationData(padapter, pHciCmd);
4261 case HCI_WRITE_LOCATION_DATA:
4262 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOCATION_DATA\n"));
4263 status = bthci_CmdWriteLocationData(padapter, pHciCmd);
4265 case HCI_READ_FLOW_CONTROL_MODE:
4266 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FLOW_CONTROL_MODE\n"));
4267 status = bthci_CmdReadFlowControlMode(padapter, pHciCmd);
4269 case HCI_WRITE_FLOW_CONTROL_MODE:
4270 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_FLOW_CONTROL_MODE\n"));
4271 status = bthci_CmdWriteFlowControlMode(padapter, pHciCmd);
4273 case HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT:
4274 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4275 status = bthci_CmdReadBestEffortFlushTimeout(padapter, pHciCmd);
4277 case HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT:
4278 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4279 status = bthci_CmdWriteBestEffortFlushTimeout(padapter, pHciCmd);
4281 case HCI_SHORT_RANGE_MODE:
4282 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SHORT_RANGE_MODE\n"));
4283 status = bthci_CmdShortRangeMode(padapter, pHciCmd);
4285 case HCI_HOST_BUFFER_SIZE:
4286 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_BUFFER_SIZE\n"));
4287 status = bthci_CmdHostBufferSize(padapter, pHciCmd);
4290 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFSetEventMaskCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4291 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4292 status = bthci_UnknownCMD(padapter, pHciCmd);
4298 static enum hci_status
4299 bthci_HandleOGFStatusParameters(struct rtw_adapter *padapter,
4300 struct packet_irp_hcicmd_data *pHciCmd)
4302 enum hci_status status = HCI_STATUS_SUCCESS;
4304 switch (pHciCmd->OCF) {
4305 case HCI_READ_FAILED_CONTACT_COUNTER:
4306 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FAILED_CONTACT_COUNTER\n"));
4307 status = bthci_CmdReadFailedContactCounter(padapter, pHciCmd);
4309 case HCI_RESET_FAILED_CONTACT_COUNTER:
4310 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET_FAILED_CONTACT_COUNTER\n"));
4311 status = bthci_CmdResetFailedContactCounter(padapter, pHciCmd);
4313 case HCI_READ_LINK_QUALITY:
4314 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_QUALITY\n"));
4315 status = bthci_CmdReadLinkQuality(padapter, pHciCmd);
4318 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_RSSI\n"));
4319 status = bthci_CmdReadRSSI(padapter);
4321 case HCI_READ_LOCAL_AMP_INFO:
4322 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_INFO\n"));
4323 status = bthci_CmdReadLocalAMPInfo(padapter);
4325 case HCI_READ_LOCAL_AMP_ASSOC:
4326 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_ASSOC\n"));
4327 status = bthci_CmdReadLocalAMPAssoc(padapter, pHciCmd);
4329 case HCI_WRITE_REMOTE_AMP_ASSOC:
4330 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_REMOTE_AMP_ASSOC\n"));
4331 status = bthci_CmdWriteRemoteAMPAssoc(padapter, pHciCmd);
4334 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFStatusParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4335 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4336 status = bthci_UnknownCMD(padapter, pHciCmd);
4342 static enum hci_status
4343 bthci_HandleOGFLinkControlCMD(struct rtw_adapter *padapter,
4344 struct packet_irp_hcicmd_data *pHciCmd)
4346 enum hci_status status = HCI_STATUS_SUCCESS;
4348 switch (pHciCmd->OCF) {
4349 case HCI_CREATE_PHYSICAL_LINK:
4350 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_PHYSICAL_LINK\n"));
4351 status = bthci_CmdCreatePhysicalLink(padapter, pHciCmd);
4353 case HCI_ACCEPT_PHYSICAL_LINK:
4354 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_PHYSICAL_LINK\n"));
4355 status = bthci_CmdAcceptPhysicalLink(padapter, pHciCmd);
4357 case HCI_DISCONNECT_PHYSICAL_LINK:
4358 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK\n"));
4359 status = bthci_CmdDisconnectPhysicalLink(padapter, pHciCmd);
4361 case HCI_CREATE_LOGICAL_LINK:
4362 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_LOGICAL_LINK\n"));
4363 status = bthci_CmdCreateLogicalLink(padapter, pHciCmd);
4365 case HCI_ACCEPT_LOGICAL_LINK:
4366 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_LOGICAL_LINK\n"));
4367 status = bthci_CmdAcceptLogicalLink(padapter, pHciCmd);
4369 case HCI_DISCONNECT_LOGICAL_LINK:
4370 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_LOGICAL_LINK\n"));
4371 status = bthci_CmdDisconnectLogicalLink(padapter, pHciCmd);
4373 case HCI_LOGICAL_LINK_CANCEL:
4374 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_LOGICAL_LINK_CANCEL\n"));
4375 status = bthci_CmdLogicalLinkCancel(padapter, pHciCmd);
4377 case HCI_FLOW_SPEC_MODIFY:
4378 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_FLOW_SPEC_MODIFY\n"));
4379 status = bthci_CmdFlowSpecModify(padapter, pHciCmd);
4382 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFLinkControlCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4383 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4384 status = bthci_UnknownCMD(padapter, pHciCmd);
4390 static enum hci_status
4391 bthci_HandleOGFTestingCMD(struct rtw_adapter *padapter,
4392 struct packet_irp_hcicmd_data *pHciCmd)
4394 enum hci_status status = HCI_STATUS_SUCCESS;
4395 switch (pHciCmd->OCF) {
4396 case HCI_ENABLE_DEVICE_UNDER_TEST_MODE:
4397 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_DEVICE_UNDER_TEST_MODE\n"));
4398 bthci_CmdEnableDeviceUnderTestMode(padapter, pHciCmd);
4400 case HCI_AMP_TEST_END:
4401 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_END\n"));
4402 bthci_CmdAMPTestEnd(padapter, pHciCmd);
4404 case HCI_AMP_TEST_COMMAND:
4405 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_COMMAND\n"));
4406 bthci_CmdAMPTestCommand(padapter, pHciCmd);
4408 case HCI_ENABLE_AMP_RECEIVER_REPORTS:
4409 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_AMP_RECEIVER_REPORTS\n"));
4410 bthci_CmdEnableAMPReceiverReports(padapter, pHciCmd);
4413 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4414 status = bthci_UnknownCMD(padapter, pHciCmd);
4420 static enum hci_status
4421 bthci_HandleOGFExtension(struct rtw_adapter *padapter,
4422 struct packet_irp_hcicmd_data *pHciCmd)
4424 enum hci_status status = HCI_STATUS_SUCCESS;
4425 switch (pHciCmd->OCF) {
4426 case HCI_SET_ACL_LINK_DATA_FLOW_MODE:
4427 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_DATA_FLOW_MODE\n"));
4428 status = bthci_CmdSetACLLinkDataFlowMode(padapter, pHciCmd);
4430 case HCI_SET_ACL_LINK_STATUS:
4431 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_STATUS\n"));
4432 status = bthci_CmdSetACLLinkStatus(padapter, pHciCmd);
4434 case HCI_SET_SCO_LINK_STATUS:
4435 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_SCO_LINK_STATUS\n"));
4436 status = bthci_CmdSetSCOLinkStatus(padapter, pHciCmd);
4438 case HCI_SET_RSSI_VALUE:
4439 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("HCI_SET_RSSI_VALUE\n"));
4440 status = bthci_CmdSetRSSIValue(padapter, pHciCmd);
4442 case HCI_SET_CURRENT_BLUETOOTH_STATUS:
4443 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_CURRENT_BLUETOOTH_STATUS\n"));
4444 status = bthci_CmdSetCurrentBluetoothStatus(padapter, pHciCmd);
4446 /* The following is for RTK8723 */
4448 case HCI_EXTENSION_VERSION_NOTIFY:
4449 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_EXTENSION_VERSION_NOTIFY\n"));
4450 status = bthci_CmdExtensionVersionNotify(padapter, pHciCmd);
4452 case HCI_LINK_STATUS_NOTIFY:
4453 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_LINK_STATUS_NOTIFY\n"));
4454 status = bthci_CmdLinkStatusNotify(padapter, pHciCmd);
4456 case HCI_BT_OPERATION_NOTIFY:
4457 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_BT_OPERATION_NOTIFY\n"));
4458 status = bthci_CmdBtOperationNotify(padapter, pHciCmd);
4460 case HCI_ENABLE_WIFI_SCAN_NOTIFY:
4461 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_ENABLE_WIFI_SCAN_NOTIFY\n"));
4462 status = bthci_CmdEnableWifiScanNotify(padapter, pHciCmd);
4465 /* The following is for IVT */
4466 case HCI_WIFI_CURRENT_CHANNEL:
4467 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_CHANNEL\n"));
4468 status = bthci_CmdWIFICurrentChannel(padapter, pHciCmd);
4470 case HCI_WIFI_CURRENT_BANDWIDTH:
4471 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_BANDWIDTH\n"));
4472 status = bthci_CmdWIFICurrentBandwidth(padapter, pHciCmd);
4474 case HCI_WIFI_CONNECTION_STATUS:
4475 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CONNECTION_STATUS\n"));
4476 status = bthci_CmdWIFIConnectionStatus(padapter, pHciCmd);
4480 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_UNKNOWN_COMMAND\n"));
4481 status = bthci_UnknownCMD(padapter, pHciCmd);
4488 bthci_StateStarting(struct rtw_adapter *padapter,
4489 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4491 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4492 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4494 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Starting], "));
4496 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4497 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4498 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4499 pBtMgnt->bNeedNotifyAMPNoCap = true;
4500 BTHCI_DisconnectPeer(padapter, EntryNum);
4502 case STATE_CMD_DISCONNECT_PHY_LINK:
4503 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4505 bthci_EventDisconnectPhyLinkComplete(padapter,
4507 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4510 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4512 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4514 BTHCI_DisconnectPeer(padapter, EntryNum);
4516 case STATE_CMD_MAC_START_COMPLETE:
4517 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_START_COMPLETE\n"));
4518 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR)
4519 bthci_EventChannelSelected(padapter, EntryNum);
4522 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4528 bthci_StateConnecting(struct rtw_adapter *padapter,
4529 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4531 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4532 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4534 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connecting], "));
4536 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4537 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4538 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4539 pBtMgnt->bNeedNotifyAMPNoCap = true;
4540 BTHCI_DisconnectPeer(padapter, EntryNum);
4542 case STATE_CMD_MAC_CONNECT_COMPLETE:
4543 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_COMPLETE\n"));
4545 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_JOINER) {
4546 RT_TRACE(_module_rtl871x_security_c_,
4547 _drv_info_, ("StateConnecting \n"));
4550 case STATE_CMD_DISCONNECT_PHY_LINK:
4551 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4553 bthci_EventDisconnectPhyLinkComplete(padapter,
4555 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4558 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4560 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4562 BTHCI_DisconnectPeer(padapter, EntryNum);
4565 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4566 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4567 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONTROLLER_BUSY;
4568 /* Because this state cmd is caused by the BTHCI_EventAMPStatusChange(), */
4569 /* we don't need to send event in the following BTHCI_DisconnectPeer() again. */
4570 pBtMgnt->bNeedNotifyAMPNoCap = false;
4571 BTHCI_DisconnectPeer(padapter, EntryNum);
4574 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4580 bthci_StateConnected(struct rtw_adapter *padapter,
4581 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4583 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4584 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4585 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4587 u16 logicHandle = 0;
4589 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connected], "));
4591 case STATE_CMD_DISCONNECT_PHY_LINK:
4592 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4594 /* When we are trying to disconnect the phy link, we should disconnect log link first, */
4595 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
4596 if (pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle != 0) {
4597 logicHandle = pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle;
4599 bthci_EventDisconnectLogicalLinkComplete(padapter, HCI_STATUS_SUCCESS,
4600 logicHandle, pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason);
4602 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle = 0;
4606 bthci_EventDisconnectPhyLinkComplete(padapter,
4608 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4611 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4613 BTHCI_DisconnectPeer(padapter, EntryNum);
4616 case STATE_CMD_MAC_DISCONNECT_INDICATE:
4617 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_DISCONNECT_INDICATE\n"));
4619 bthci_EventDisconnectPhyLinkComplete(padapter,
4621 /* TODO: Remote Host not local host */
4622 HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST,
4624 BTHCI_DisconnectPeer(padapter, EntryNum);
4627 case STATE_CMD_ENTER_STATE:
4628 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4630 if (pBtMgnt->bBTConnectInProgress) {
4631 pBtMgnt->bBTConnectInProgress = false;
4632 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4634 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_CONNECTED;
4635 pBTInfo->BtAsocEntry[EntryNum].b4waySuccess = true;
4636 pBtMgnt->bStartSendSupervisionPkt = true;
4638 /* for rate adaptive */
4640 rtl8723a_update_ramask(padapter,
4641 MAX_FW_SUPPORT_MACID_NUM-1-EntryNum, 0);
4643 HalSetBrateCfg23a(padapter, padapter->mlmepriv.cur_network.network.SupportedRates);
4644 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
4647 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4653 bthci_StateAuth(struct rtw_adapter *padapter, enum hci_state_with_cmd StateCmd,
4656 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4657 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4659 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Authenticating], "));
4661 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4662 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4663 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4664 pBtMgnt->bNeedNotifyAMPNoCap = true;
4665 BTHCI_DisconnectPeer(padapter, EntryNum);
4667 case STATE_CMD_DISCONNECT_PHY_LINK:
4668 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4669 bthci_EventDisconnectPhyLinkComplete(padapter,
4671 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4674 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4676 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4678 BTHCI_DisconnectPeer(padapter, EntryNum);
4680 case STATE_CMD_4WAY_FAILED:
4681 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_FAILED\n"));
4683 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_AUTH_FAIL;
4684 pBtMgnt->bNeedNotifyAMPNoCap = true;
4686 BTHCI_DisconnectPeer(padapter, EntryNum);
4688 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4690 case STATE_CMD_4WAY_SUCCESSED:
4691 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_SUCCESSED\n"));
4693 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_SUCCESS, EntryNum, INVALID_PL_HANDLE);
4695 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4697 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4700 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4706 bthci_StateDisconnecting(struct rtw_adapter *padapter,
4707 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4709 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4710 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4712 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnecting], "));
4714 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4715 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4716 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4717 bthci_EventPhysicalLinkComplete(padapter,
4718 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus,
4719 EntryNum, INVALID_PL_HANDLE);
4722 if (pBtMgnt->bBTConnectInProgress) {
4723 pBtMgnt->bBTConnectInProgress = false;
4724 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4727 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4729 case STATE_CMD_DISCONNECT_PHY_LINK:
4730 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4732 bthci_EventDisconnectPhyLinkComplete(padapter,
4734 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4737 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4739 BTHCI_DisconnectPeer(padapter, EntryNum);
4742 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4748 bthci_StateDisconnected(struct rtw_adapter *padapter,
4749 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4751 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4752 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4753 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4754 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4756 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnected], "));
4758 case STATE_CMD_CREATE_PHY_LINK:
4759 case STATE_CMD_ACCEPT_PHY_LINK:
4760 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4761 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CREATE_PHY_LINK\n"));
4763 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ACCEPT_PHY_LINK\n"));
4765 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], Disable IPS and LPS\n"));
4766 ips_leave23a(padapter);
4767 LPS_Leave23a(padapter);
4769 pBtMgnt->bPhyLinkInProgress = true;
4770 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
4771 pBtMgnt->CurrentBTConnectionCnt++;
4772 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d\n",
4773 pBtMgnt->CurrentBTConnectionCnt));
4774 pBtMgnt->BtOperationOn = true;
4775 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation ON!! CurrentConnectEntryNum = %d\n",
4776 pBtMgnt->CurrentConnectEntryNum));
4778 if (pBtMgnt->bBTConnectInProgress) {
4779 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONTROLLER_BUSY, INVALID_ENTRY_NUM, pBtMgnt->BtCurrentPhyLinkhandle);
4780 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4784 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4785 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_CREATOR;
4787 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_JOINER;
4789 /* 1. MAC not yet in selected channel */
4790 while (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)) {
4791 RTPRINT(FIOCTL, IOCTL_STATE, ("Scan/Roaming/Wifi Link is in Progress, wait 200 ms\n"));
4794 /* 2. MAC already in selected channel */
4795 RTPRINT(FIOCTL, IOCTL_STATE, ("Channel is Ready\n"));
4796 mod_timer(&pBTInfo->BTHCIJoinTimeoutTimer,
4797 jiffies + msecs_to_jiffies(pBtHciInfo->ConnAcceptTimeout));
4799 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = true;
4801 case STATE_CMD_DISCONNECT_PHY_LINK:
4802 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4804 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4806 bthci_EventDisconnectPhyLinkComplete(padapter,
4808 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4811 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4812 bthci_EventPhysicalLinkComplete(padapter,
4813 HCI_STATUS_UNKNOW_CONNECT_ID,
4814 EntryNum, INVALID_PL_HANDLE);
4817 if (pBtMgnt->bBTConnectInProgress) {
4818 pBtMgnt->bBTConnectInProgress = false;
4819 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4821 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4822 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4824 case STATE_CMD_ENTER_STATE:
4825 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4828 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4833 void BTHCI_EventParse(struct rtw_adapter *padapter, void *pEvntData, u32 dataLen)
4837 u8 BTHCI_HsConnectionEstablished(struct rtw_adapter *padapter)
4839 u8 bBtConnectionExist = false;
4840 struct bt_30info *pBtinfo = GET_BT_INFO(padapter);
4843 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
4844 if (pBtinfo->BtAsocEntry[i].b4waySuccess) {
4845 bBtConnectionExist = true;
4850 /*RTPRINT(FIOCTL, IOCTL_STATE, (" BTHCI_HsConnectionEstablished(), connection exist = %d\n", bBtConnectionExist)); */
4852 return bBtConnectionExist;
4856 BTHCI_CheckProfileExist(struct rtw_adapter *padapter,
4857 enum bt_traffic_mode_profile Profile)
4859 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4860 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4861 u8 IsPRofile = false;
4864 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4865 if (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile == Profile) {
4874 void BTHCI_UpdateBTProfileRTKToMoto(struct rtw_adapter *padapter)
4876 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4877 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4880 pBtMgnt->ExtConfig.NumberOfSCO = 0;
4882 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4883 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
4885 if (pBtMgnt->ExtConfig.linkInfo[i].BTProfile == BT_PROFILE_SCO)
4886 pBtMgnt->ExtConfig.NumberOfSCO++;
4888 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = pBtMgnt->ExtConfig.linkInfo[i].BTProfile;
4889 switch (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile) {
4890 case BT_PROFILE_SCO:
4892 case BT_PROFILE_PAN:
4893 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_BE;
4894 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4896 case BT_PROFILE_A2DP:
4897 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GULB;
4898 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_GULB;
4900 case BT_PROFILE_HID:
4901 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GUL;
4902 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4909 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RTK, NumberOfHandle = %d, NumberOfSCO = %d\n",
4910 pBtMgnt->ExtConfig.NumberOfHandle, pBtMgnt->ExtConfig.NumberOfSCO));
4913 void BTHCI_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
4915 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4916 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4918 if (pBtMgnt->ExtConfig.bEnableWifiScanNotify)
4919 bthci_EventExtWifiScanNotify(padapter, scanType);
4924 struct rtw_adapter *padapter,
4926 enum hci_state_with_cmd StateCmd,
4930 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4931 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4933 if (EntryNum == 0xff) {
4934 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, error EntryNum = 0x%x \n", EntryNum));
4937 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, EntryNum = 0x%x, CurrentState = 0x%x, BtNextState = 0x%x, StateCmd = 0x%x , StateToEnter = 0x%x\n",
4938 EntryNum, pBTInfo->BtAsocEntry[EntryNum].BtCurrentState, pBTInfo->BtAsocEntry[EntryNum].BtNextState, StateCmd, StateToEnter));
4940 if (pBTInfo->BtAsocEntry[EntryNum].BtNextState & StateToEnter) {
4941 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = StateToEnter;
4943 switch (StateToEnter) {
4944 case HCI_STATE_STARTING:
4945 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTING;
4946 bthci_StateStarting(padapter, StateCmd, EntryNum);
4948 case HCI_STATE_CONNECTING:
4949 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTING | HCI_STATE_DISCONNECTING | HCI_STATE_AUTHENTICATING;
4950 bthci_StateConnecting(padapter, StateCmd, EntryNum);
4952 case HCI_STATE_AUTHENTICATING:
4953 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTED;
4954 bthci_StateAuth(padapter, StateCmd, EntryNum);
4956 case HCI_STATE_CONNECTED:
4957 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTED | HCI_STATE_DISCONNECTING;
4958 bthci_StateConnected(padapter, StateCmd, EntryNum);
4960 case HCI_STATE_DISCONNECTING:
4961 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_DISCONNECTING;
4962 bthci_StateDisconnecting(padapter, StateCmd, EntryNum);
4964 case HCI_STATE_DISCONNECTED:
4965 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_STARTING | HCI_STATE_CONNECTING;
4966 bthci_StateDisconnected(padapter, StateCmd, EntryNum);
4969 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Unknown state to enter!!!\n"));
4973 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Wrong state to enter\n"));
4976 /* 20100325 Joseph: Disable/Enable IPS/LPS according to BT status. */
4977 if (!pBtMgnt->bBTConnectInProgress && !pBtMgnt->BtOperationOn) {
4978 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], ips_enter23a()\n"));
4979 ips_enter23a(padapter);
4983 void BTHCI_DisconnectPeer(struct rtw_adapter *padapter, u8 EntryNum)
4985 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4986 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4988 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" BTHCI_DisconnectPeer()\n"));
4990 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, EntryNum);
4992 if (pBTInfo->BtAsocEntry[EntryNum].bUsed) {
4993 /*BTPKT_SendDeauthentication(padapter, pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, unspec_reason); not porting yet */
4996 if (pBtMgnt->bBTConnectInProgress) {
4997 pBtMgnt->bBTConnectInProgress = false;
4998 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
5001 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
5003 if (pBtMgnt->bNeedNotifyAMPNoCap) {
5004 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT AMPStatus], set to invalid in BTHCI_DisconnectPeer()\n"));
5005 BTHCI_EventAMPStatusChange(padapter, AMP_STATUS_NO_CAPACITY_FOR_BT);
5009 void BTHCI_EventNumOfCompletedDataBlocks(struct rtw_adapter *padapter)
5011 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
5012 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5013 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
5014 u8 localBuf[TmpLocalBufSize] = "";
5015 u8 *pRetPar, *pTriple;
5016 u8 len = 0, i, j, handleNum = 0;
5017 struct packet_irp_hcievent_data *PPacketIrpEvent;
5018 u16 *pu2Temp, *pPackets, *pHandle, *pDblocks;
5021 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5023 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS)) {
5024 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Num Of Completed DataBlocks, Ignore to send NumOfCompletedDataBlocksEvent due to event mask page 2\n"));
5028 /* Return parameters starts from here */
5029 pRetPar = &PPacketIrpEvent->Data[0];
5030 pTriple = &pRetPar[3];
5031 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
5033 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
5034 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle) {
5036 pHandle = (u16 *)&pTriple[0]; /* Handle[i] */
5037 pPackets = (u16 *)&pTriple[2]; /* Num_Of_Completed_Packets[i] */
5038 pDblocks = (u16 *)&pTriple[4]; /* Num_Of_Completed_Blocks[i] */
5039 *pHandle = pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle;
5040 *pPackets = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5041 *pDblocks = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5042 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount) {
5044 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL,
5045 ("[BT event], Num Of Completed DataBlocks, Handle = 0x%x, Num_Of_Completed_Packets = 0x%x, Num_Of_Completed_Blocks = 0x%x\n",
5046 *pHandle, *pPackets, *pDblocks));
5048 pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount = 0;
5055 pRetPar[2] = handleNum; /* Number_of_Handles */
5057 pu2Temp = (u16 *)&pRetPar[0];
5058 *pu2Temp = BTTotalDataBlockNum;
5061 PPacketIrpEvent->EventCode = HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS;
5062 PPacketIrpEvent->Length = len;
5063 if (handleNum && sent)
5064 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
5067 void BTHCI_EventAMPStatusChange(struct rtw_adapter *padapter, u8 AMP_Status)
5069 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5070 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
5071 struct packet_irp_hcievent_data *PPacketIrpEvent;
5073 u8 localBuf[7] = "";
5076 if (AMP_Status == AMP_STATUS_NO_CAPACITY_FOR_BT) {
5077 pBtMgnt->BTNeedAMPStatusChg = true;
5078 pBtMgnt->bNeedNotifyAMPNoCap = false;
5080 BTHCI_DisconnectAll(padapter);
5081 } else if (AMP_Status == AMP_STATUS_FULL_CAPACITY_FOR_BT) {
5082 pBtMgnt->BTNeedAMPStatusChg = false;
5085 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5086 /* Return parameters starts from here */
5087 pRetPar = &PPacketIrpEvent->Data[0];
5089 pRetPar[0] = 0; /* Status */
5091 pRetPar[1] = AMP_Status; /* AMP_Status */
5094 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_STATUS_CHANGE;
5095 PPacketIrpEvent->Length = len;
5096 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS)
5097 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_STATE), ("[BT event], AMP Status Change, AMP_Status = %d\n", AMP_Status));
5100 void BTHCI_DisconnectAll(struct rtw_adapter *padapter)
5102 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5105 RTPRINT(FIOCTL, IOCTL_STATE, (" DisconnectALL()\n"));
5107 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
5108 if (pBTInfo->BtAsocEntry[i].b4waySuccess) {
5109 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, i);
5110 } else if (pBTInfo->BtAsocEntry[i].bUsed) {
5111 if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_CONNECTING) {
5112 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5113 } else if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_DISCONNECTING) {
5114 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5122 struct rtw_adapter *padapter,
5123 struct packet_irp_hcicmd_data *pHciCmd
5126 enum hci_status status = HCI_STATUS_SUCCESS;
5127 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5128 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
5130 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("\n"));
5131 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI Command start, OGF = 0x%x, OCF = 0x%x, Length = 0x%x\n",
5132 pHciCmd->OGF, pHciCmd->OCF, pHciCmd->Length));
5133 if (pHciCmd->Length) {
5134 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "HCI Command, Hex Data :\n",
5135 &pHciCmd->Data[0], pHciCmd->Length);
5137 if (pHciCmd->OGF == OGF_EXTENSION) {
5138 if (pHciCmd->OCF == HCI_SET_RSSI_VALUE)
5139 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("[BT cmd], "));
5141 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[BT cmd], "));
5143 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("[BT cmd], "));
5146 pBtDbg->dbgHciInfo.hciCmdCnt++;
5148 switch (pHciCmd->OGF) {
5149 case LINK_CONTROL_COMMANDS:
5150 status = bthci_HandleOGFLinkControlCMD(padapter, pHciCmd);
5152 case HOLD_MODE_COMMAND:
5154 case OGF_SET_EVENT_MASK_COMMAND:
5155 status = bthci_HandleOGFSetEventMaskCMD(padapter, pHciCmd);
5157 case OGF_INFORMATIONAL_PARAMETERS:
5158 status = bthci_HandleOGFInformationalParameters(padapter, pHciCmd);
5160 case OGF_STATUS_PARAMETERS:
5161 status = bthci_HandleOGFStatusParameters(padapter, pHciCmd);
5163 case OGF_TESTING_COMMANDS:
5164 status = bthci_HandleOGFTestingCMD(padapter, pHciCmd);
5167 status = bthci_HandleOGFExtension(padapter, pHciCmd);
5170 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI Command(), Unknown OGF = 0x%x\n", pHciCmd->OGF));
5171 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
5172 status = bthci_UnknownCMD(padapter, pHciCmd);
5175 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("HCI Command execution end!!\n"));
5180 /* ===== End of sync from SD7 driver COMMOM/bt_hci.c ===== */
5182 static const char *const BtStateString[] = {
5190 "BT_ACL_INQ_OR_PAG",
5191 "BT_STATE_NOT_DEFINED"
5194 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
5196 static void btdm_SetFwIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
5198 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5199 u8 H2C_Parameter[1] = {0};
5202 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Ignore Wlan_Act !!\n"));
5203 H2C_Parameter[0] |= BIT(0); /* function enable */
5204 pHalData->bt_coexist.bFWCoexistAllOff = false;
5206 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT don't ignore Wlan_Act !!\n"));
5209 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, write 0x25 = 0x%02x\n",
5212 FillH2CCmd(padapter, BT_IGNORE_WLAN_ACT_EID, 1, H2C_Parameter);
5215 static void btdm_NotifyFwScan(struct rtw_adapter *padapter, u8 scanType)
5217 u8 H2C_Parameter[1] = {0};
5219 if (scanType == true)
5220 H2C_Parameter[0] = 0x1;
5222 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Notify FW for wifi scan, write 0x3b = 0x%02x\n",
5225 FillH2CCmd(padapter, 0x3b, 1, H2C_Parameter);
5228 static void btdm_1AntSetPSMode(struct rtw_adapter *padapter,
5229 u8 enable, u8 smartps, u8 mode)
5231 struct pwrctrl_priv *pwrctrl;
5233 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current LPS(%s, %d), smartps =%d\n", enable == true?"ON":"OFF", mode, smartps));
5235 pwrctrl = &padapter->pwrctrlpriv;
5237 if (enable == true) {
5238 rtw_set_ps_mode23a(padapter, PS_MODE_MIN, smartps, mode);
5240 rtw_set_ps_mode23a(padapter, PS_MODE_ACTIVE, 0, 0);
5241 LPS_RF_ON_check23a(padapter, 100);
5245 static void btdm_1AntTSFSwitch(struct rtw_adapter *padapter, u8 enable)
5249 oldVal = rtl8723au_read8(padapter, 0x550);
5252 newVal = oldVal | EN_BCN_FUNCTION;
5254 newVal = oldVal & ~EN_BCN_FUNCTION;
5256 if (oldVal != newVal)
5257 rtl8723au_write8(padapter, 0x550, newVal);
5260 static u8 btdm_Is1AntPsTdmaStateChange(struct rtw_adapter *padapter)
5262 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5263 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5265 if ((pBtdm8723->bPrePsTdmaOn != pBtdm8723->bCurPsTdmaOn) ||
5266 (pBtdm8723->prePsTdma != pBtdm8723->curPsTdma))
5272 /* Before enter TDMA, make sure Power Saving is enable! */
5275 struct rtw_adapter *padapter,
5280 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5281 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5283 pBtdm8723->bCurPsTdmaOn = bTurnOn;
5284 pBtdm8723->curPsTdma = type;
5287 case 1: /* A2DP Level-1 or FTP/OPP */
5289 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5290 /* wide duration for WiFi */
5291 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x0, 0x58);
5294 case 2: /* A2DP Level-2 */
5295 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5296 /* normal duration for WiFi */
5297 BTDM_SetFw3a(padapter, 0xd3, 0x12, 0x12, 0x0, 0x58);
5300 case 3: /* BT FTP/OPP */
5301 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5302 /* normal duration for WiFi */
5303 BTDM_SetFw3a(padapter, 0xd3, 0x30, 0x03, 0x10, 0x58);
5307 case 4: /* for wifi scan & BT is connected */
5308 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5309 /* protect 3 beacons in 3-beacon period & no Tx pause at BT slot */
5310 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x0);
5313 case 5: /* for WiFi connected-busy & BT is Non-Connected-Idle */
5314 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5315 /* SCO mode, Ant fixed at WiFi, WLAN_Act toggle */
5316 BTDM_SetFw3a(padapter, 0x61, 0x15, 0x03, 0x31, 0x00);
5319 case 9: /* ACL high-retry type - 2 */
5320 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5321 /* narrow duration for WiFi */
5322 BTDM_SetFw3a(padapter, 0xd3, 0xa, 0xa, 0x0, 0x58); /* narrow duration for WiFi */
5325 case 10: /* for WiFi connect idle & BT ACL busy or WiFi Connected-Busy & BT is Inquiry */
5326 if (btdm_Is1AntPsTdmaStateChange(padapter))
5327 BTDM_SetFw3a(padapter, 0x13, 0xa, 0xa, 0x0, 0x40);
5329 case 11: /* ACL high-retry type - 3 */
5330 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5331 /* narrow duration for WiFi */
5332 BTDM_SetFw3a(padapter, 0xd3, 0x05, 0x05, 0x00, 0x58);
5335 case 12: /* for WiFi Connected-Busy & BT is Connected-Idle */
5336 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5337 /* Allow High-Pri BT */
5338 BTDM_SetFw3a(padapter, 0xeb, 0x0a, 0x03, 0x31, 0x18);
5341 case 20: /* WiFi only busy , TDMA mode for power saving */
5342 if (btdm_Is1AntPsTdmaStateChange(padapter))
5343 BTDM_SetFw3a(padapter, 0x13, 0x25, 0x25, 0x00, 0x00);
5345 case 27: /* WiFi DHCP/Site Survey & BT SCO busy */
5346 if (btdm_Is1AntPsTdmaStateChange(padapter))
5347 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x31, 0x98);
5349 case 28: /* WiFi DHCP/Site Survey & BT idle */
5350 if (btdm_Is1AntPsTdmaStateChange(padapter))
5351 BTDM_SetFw3a(padapter, 0x69, 0x25, 0x03, 0x31, 0x00);
5353 case 29: /* WiFi DHCP/Site Survey & BT ACL busy */
5354 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5355 BTDM_SetFw3a(padapter, 0xeb, 0x1a, 0x1a, 0x01, 0x18);
5356 rtl8723au_write32(padapter, 0x6c0, 0x5afa5afa);
5357 rtl8723au_write32(padapter, 0x6c4, 0x5afa5afa);
5360 case 30: /* WiFi idle & BT Inquiry */
5361 if (btdm_Is1AntPsTdmaStateChange(padapter))
5362 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x00);
5364 case 31: /* BT HID */
5365 if (btdm_Is1AntPsTdmaStateChange(padapter))
5366 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x58);
5368 case 32: /* BT SCO & Inquiry */
5369 if (btdm_Is1AntPsTdmaStateChange(padapter))
5370 BTDM_SetFw3a(padapter, 0xab, 0x0a, 0x03, 0x11, 0x98);
5372 case 33: /* BT SCO & WiFi site survey */
5373 if (btdm_Is1AntPsTdmaStateChange(padapter))
5374 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x30, 0x98);
5376 case 34: /* BT HID & WiFi site survey */
5377 if (btdm_Is1AntPsTdmaStateChange(padapter))
5378 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x18);
5380 case 35: /* BT HID & WiFi Connecting */
5381 if (btdm_Is1AntPsTdmaStateChange(padapter))
5382 BTDM_SetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x00, 0x18);
5386 /* disable PS-TDMA */
5389 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5390 /* Antenna control by PTA, 0x870 = 0x310 */
5391 BTDM_SetFw3a(padapter, 0x8, 0x0, 0x0, 0x0, 0x0);
5396 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5397 /* Antenna control by PTA, 0x870 = 0x310 */
5398 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5400 /* Switch Antenna to BT */
5401 rtl8723au_write16(padapter, 0x860, 0x210);
5402 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x210, Switch Antenna to BT\n"));
5405 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5406 /* Antenna control by PTA, 0x870 = 0x310 */
5407 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5409 /* Switch Antenna to WiFi */
5410 rtl8723au_write16(padapter, 0x860, 0x110);
5411 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x110, Switch Antenna to WiFi\n"));
5416 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current TDMA(%s, %d)\n",
5417 pBtdm8723->bCurPsTdmaOn?"ON":"OFF", pBtdm8723->curPsTdma));
5419 /* update pre state */
5420 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
5421 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
5425 _btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn, u8 smartps,
5426 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5428 struct pwrctrl_priv *pwrctrl;
5429 struct hal_data_8723a *pHalData;
5430 struct btdm_8723a_1ant *pBtdm8723;
5434 if (!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) &&
5435 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
5436 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5439 psOption &= ~BIT(0);
5441 RTPRINT(FBT, BT_TRACE,
5442 ("[BTCoex], Set LPS(%s, %d) TDMA(%s, %d)\n",
5443 bPSEn == true?"ON":"OFF", psOption,
5444 bTDMAOn == true?"ON":"OFF", tdmaType));
5446 pwrctrl = &padapter->pwrctrlpriv;
5447 pHalData = GET_HAL_DATA(padapter);
5448 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5451 if (pBtdm8723->bWiFiHalt) {
5452 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Halt!!\n"));
5456 if (pwrctrl->bInSuspend) {
5457 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Suspend!!\n"));
5461 if (padapter->bDriverStopped) {
5462 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi driver stopped!!\n"));
5466 if (padapter->bSurpriseRemoved) {
5467 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi Surprise Removed!!\n"));
5471 psMode = PS_MODE_MIN;
5473 psMode = PS_MODE_ACTIVE;
5477 if (psMode != pwrctrl->pwr_mode) {
5479 } else if (psMode != PS_MODE_ACTIVE) {
5480 if (psOption != pwrctrl->bcn_ant_mode)
5482 else if (smartps != pwrctrl->smart_ps)
5492 if (pBtdm8723->bCurPsTdmaOn) {
5494 btdm_1AntPsTdma(padapter, false, tdmaType);
5496 if (!rtl8723a_BT_enabled(padapter) ||
5497 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_NO_CONNECTION) ||
5498 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_CONNECT_IDLE) ||
5500 btdm_1AntPsTdma(padapter, false, 9);
5502 btdm_1AntPsTdma(padapter, false, 0);
5506 /* change Power Save State */
5507 btdm_1AntSetPSMode(padapter, bPSEn, smartps, psOption);
5510 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5514 btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn,
5515 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5517 _btdm_1AntSetPSTDMA(padapter, bPSEn, 0, psOption, bTDMAOn, tdmaType);
5520 static void btdm_1AntWifiParaAdjust(struct rtw_adapter *padapter, u8 bEnable)
5522 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5523 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5526 pBtdm8723->curWifiPara = 1;
5527 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5528 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_LOW_PENALTY);
5530 pBtdm8723->curWifiPara = 2;
5531 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5532 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_NORMAL);
5537 static void btdm_1AntPtaParaReload(struct rtw_adapter *padapter)
5540 rtl8723au_write8(padapter, 0x6cc, 0x0); /* 1-Ant coex */
5541 rtl8723au_write32(padapter, 0x6c8, 0xffff); /* wifi break table */
5542 rtl8723au_write32(padapter, 0x6c4, 0x55555555); /* coex table */
5544 /* Antenna switch control parameter */
5545 rtl8723au_write32(padapter, 0x858, 0xaaaaaaaa);
5546 if (IS_8723A_A_CUT(GET_HAL_DATA(padapter)->VersionID)) {
5547 /* SPDT(connected with TRSW) control by hardware PTA */
5548 rtl8723au_write32(padapter, 0x870, 0x0);
5549 rtl8723au_write8(padapter, 0x40, 0x24);
5551 rtl8723au_write8(padapter, 0x40, 0x20);
5552 /* set antenna at bt side if ANTSW is software control */
5553 rtl8723au_write16(padapter, 0x860, 0x210);
5554 /* SPDT(connected with TRSW) control by hardware PTA */
5555 rtl8723au_write32(padapter, 0x870, 0x300);
5556 /* ANTSW keep by GNT_BT */
5557 rtl8723au_write32(padapter, 0x874, 0x22804000);
5560 /* coexistence parameters */
5561 rtl8723au_write8(padapter, 0x778, 0x1); /* enable RTK mode PTA */
5563 /* BT don't ignore WLAN_Act */
5564 btdm_SetFwIgnoreWlanAct(padapter, false);
5569 *1: upgrade (add WiFi duration time)
5571 *-1: downgrade (add BT duration time)
5573 static s8 btdm_1AntTdmaJudgement(struct rtw_adapter *padapter, u8 retry)
5575 struct hal_data_8723a *pHalData;
5576 struct btdm_8723a_1ant *pBtdm8723;
5577 static s8 up, dn, m = 1, n = 3, WaitCount;
5580 pHalData = GET_HAL_DATA(padapter);
5581 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5584 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5595 /* no retry in the last 2-second duration */
5601 /* retry = 0 in consecutive 3m*(2s), add WiFi duration */
5609 } else if (retry <= 3) {
5610 /* retry<= 3 in the last 2-second duration */
5617 /* retry<= 3 in consecutive 2*(2s), minus WiFi duration (add BT duration) */
5620 /* record how many time downgrad WiFi duration */
5625 /* the max number of m is 20 */
5626 /* the longest time of upgrade WiFi duration is 20*3*2s = 120s */
5634 /* retry count > 3 */
5635 /* retry>3, minus WiFi duration (add BT duration) */
5638 /* record how many time downgrad WiFi duration */
5653 static void btdm_1AntTdmaDurationAdjustForACL(struct rtw_adapter *padapter)
5655 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5656 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5658 if (pBtdm8723->psTdmaGlobalCnt != pBtdm8723->psTdmaMonitorCnt) {
5659 pBtdm8723->psTdmaMonitorCnt = 0;
5660 pBtdm8723->psTdmaGlobalCnt = 0;
5662 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5663 btdm_1AntSetPSTDMA(padapter, true, 0, true, 2);
5664 pBtdm8723->psTdmaDuAdjType = 2;
5666 /* Now we only have 4 level Ps Tdma, */
5667 /* if that's not the following 4 level(will changed by wifi scan, dhcp...), */
5668 /* then we have to adjust it back to the previous record one. */
5669 if ((pBtdm8723->curPsTdma != 1) &&
5670 (pBtdm8723->curPsTdma != 2) &&
5671 (pBtdm8723->curPsTdma != 9) &&
5672 (pBtdm8723->curPsTdma != 11)) {
5673 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5677 judge = btdm_1AntTdmaJudgement(padapter, pHalData->bt_coexist.halCoex8723.btRetryCnt);
5679 if (pBtdm8723->curPsTdma == 1) {
5680 /* Decrease WiFi duration for high BT retry */
5681 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5682 pBtdm8723->psTdmaDuAdjType = 9;
5684 pBtdm8723->psTdmaDuAdjType = 2;
5685 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5686 } else if (pBtdm8723->curPsTdma == 2) {
5687 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5688 pBtdm8723->psTdmaDuAdjType = 9;
5689 } else if (pBtdm8723->curPsTdma == 9) {
5690 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5691 pBtdm8723->psTdmaDuAdjType = 11;
5693 } else if (judge == 1) {
5694 if (pBtdm8723->curPsTdma == 11) {
5695 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5696 pBtdm8723->psTdmaDuAdjType = 9;
5697 } else if (pBtdm8723->curPsTdma == 9) {
5698 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5699 pBtdm8723->psTdmaDuAdjType = 9;
5701 pBtdm8723->psTdmaDuAdjType = 2;
5702 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5703 } else if (pBtdm8723->curPsTdma == 2) {
5704 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5705 pBtdm8723->psTdmaDuAdjType = 9;
5707 pBtdm8723->psTdmaDuAdjType = 1;
5708 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5712 RTPRINT(FBT, BT_TRACE,
5713 ("[BTCoex], ACL current TDMA(%s, %d)\n",
5714 (pBtdm8723->bCurPsTdmaOn ? "ON" : "OFF"), pBtdm8723->curPsTdma));
5716 pBtdm8723->psTdmaMonitorCnt++;
5719 static void btdm_1AntCoexProcessForWifiConnect(struct rtw_adapter *padapter)
5721 struct mlme_priv *pmlmepriv;
5722 struct hal_data_8723a *pHalData;
5723 struct bt_coexist_8723a *pBtCoex;
5724 struct btdm_8723a_1ant *pBtdm8723;
5727 pmlmepriv = &padapter->mlmepriv;
5728 pHalData = GET_HAL_DATA(padapter);
5729 pBtCoex = &pHalData->bt_coexist.halCoex8723;
5730 pBtdm8723 = &pBtCoex->btdm1Ant;
5731 BtState = pBtCoex->c2hBtInfo;
5733 RTPRINT(FBT, BT_TRACE, ("[BTCoex], WiFi is %s\n",
5734 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
5735 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is %s\n",
5736 BtStateString[BtState]));
5738 padapter->pwrctrlpriv.btcoex_rfon = false;
5740 if (!BTDM_IsWifiBusy(padapter) &&
5741 !check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) &&
5742 (BtState == BT_INFO_STATE_NO_CONNECTION ||
5743 BtState == BT_INFO_STATE_CONNECT_IDLE)) {
5745 case BT_INFO_STATE_NO_CONNECTION:
5746 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 9);
5748 case BT_INFO_STATE_CONNECT_IDLE:
5749 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 0);
5754 case BT_INFO_STATE_NO_CONNECTION:
5755 case BT_INFO_STATE_CONNECT_IDLE:
5757 btdm_1AntSetPSTDMA(padapter, false, 0, true, 5);
5758 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5759 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5761 case BT_INFO_STATE_ACL_INQ_OR_PAG:
5762 RTPRINT(FBT, BT_TRACE,
5763 ("[BTCoex], BT PROFILE is "
5764 "BT_INFO_STATE_ACL_INQ_OR_PAG\n"));
5765 case BT_INFO_STATE_INQ_OR_PAG:
5766 padapter->pwrctrlpriv.btcoex_rfon = true;
5767 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
5769 case BT_INFO_STATE_SCO_ONLY_BUSY:
5770 case BT_INFO_STATE_ACL_SCO_BUSY:
5771 if (true == pBtCoex->bC2hBtInquiryPage)
5772 btdm_1AntSetPSTDMA(padapter, false, 0,
5775 #ifdef BTCOEX_CMCC_TEST
5776 btdm_1AntSetPSTDMA(padapter, false, 0,
5778 #else /* !BTCOEX_CMCC_TEST */
5779 btdm_1AntSetPSTDMA(padapter, false, 0,
5781 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5782 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5783 #endif /* !BTCOEX_CMCC_TEST */
5786 case BT_INFO_STATE_ACL_ONLY_BUSY:
5787 padapter->pwrctrlpriv.btcoex_rfon = true;
5788 if (pBtCoex->c2hBtProfile == BT_INFO_HID) {
5789 RTPRINT(FBT, BT_TRACE,
5790 ("[BTCoex], BT PROFILE is HID\n"));
5791 btdm_1AntSetPSTDMA(padapter, true, 0, true, 31);
5792 } else if (pBtCoex->c2hBtProfile == BT_INFO_FTP) {
5793 RTPRINT(FBT, BT_TRACE,
5794 ("[BTCoex], BT PROFILE is FTP/OPP\n"));
5795 btdm_1AntSetPSTDMA(padapter, true, 0, true, 3);
5796 } else if (pBtCoex->c2hBtProfile == (BT_INFO_A2DP|BT_INFO_FTP)) {
5797 RTPRINT(FBT, BT_TRACE,
5798 ("[BTCoex], BT PROFILE is A2DP_FTP\n"));
5799 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5801 if (pBtCoex->c2hBtProfile == BT_INFO_A2DP)
5802 RTPRINT(FBT, BT_TRACE,
5803 ("[BTCoex], BT PROFILE is "
5806 RTPRINT(FBT, BT_TRACE,
5807 ("[BTCoex], BT PROFILE is "
5808 "UNKNOWN(0x%02X)! Use A2DP "
5810 pBtCoex->c2hBtProfile));
5811 btdm_1AntTdmaDurationAdjustForACL(padapter);
5817 pBtdm8723->psTdmaGlobalCnt++;
5821 btdm_1AntUpdateHalRAMask(struct rtw_adapter *padapter, u32 mac_id, u32 filter)
5826 u8 shortGIrate = false;
5827 int supportRateNum = 0;
5828 struct sta_info *psta;
5829 struct hal_data_8723a *pHalData;
5830 struct dm_priv *pdmpriv;
5831 struct mlme_ext_priv *pmlmeext;
5832 struct mlme_ext_info *pmlmeinfo;
5833 struct wlan_bssid_ex *cur_network;
5835 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d, filter = 0x%08x!!\n",
5836 __func__, mac_id, filter));
5838 pHalData = GET_HAL_DATA(padapter);
5839 pdmpriv = &pHalData->dmpriv;
5840 pmlmeext = &padapter->mlmeextpriv;
5841 pmlmeinfo = &pmlmeext->mlmext_info;
5842 cur_network = &pmlmeinfo->network;
5844 if (mac_id >= NUM_STA) { /* CAM_SIZE */
5845 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d illegal!!\n",
5850 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
5852 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, Can't find station!!\n",
5860 case 0:/* for infra mode */
5862 rtw_get_rateset_len23a(cur_network->SupportedRates);
5863 mask = update_supported_rate23a(cur_network->SupportedRates,
5865 mask |= (pmlmeinfo->HT_enable) ?
5866 update_MSC_rate23a(&pmlmeinfo->ht_cap):0;
5867 if (support_short_GI23a(padapter, &pmlmeinfo->ht_cap))
5870 case 1:/* for broadcast/multicast */
5871 supportRateNum = rtw_get_rateset_len23a(
5872 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5873 mask = update_basic_rate23a(cur_network->SupportedRates,
5876 default: /* for each sta in IBSS */
5877 supportRateNum = rtw_get_rateset_len23a(
5878 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5879 mask = update_supported_rate23a(cur_network->SupportedRates,
5883 mask |= ((raid<<28)&0xf0000000);
5886 init_rate = get_highest_rate_idx23a(mask)&0x3f;
5888 if (pHalData->fw_ractrl) {
5891 arg = mac_id&0x1f;/* MACID */
5893 if (true == shortGIrate)
5896 RTPRINT(FBT, BT_TRACE,
5897 ("[BTCoex], Update FW RAID entry, MASK = 0x%08x, "
5898 "arg = 0x%02x\n", mask, arg));
5900 rtl8723a_set_raid_cmd(padapter, mask, arg);
5903 init_rate |= BIT(6);
5905 rtl8723au_write8(padapter, REG_INIDATA_RATE_SEL + mac_id,
5909 psta->init_rate = init_rate;
5910 pdmpriv->INIDATA_RATE[mac_id] = init_rate;
5914 btdm_1AntUpdateHalRAMaskForSCO(struct rtw_adapter *padapter, u8 forceUpdate)
5916 struct btdm_8723a_1ant *pBtdm8723;
5917 struct sta_priv *pstapriv;
5918 struct wlan_bssid_ex *cur_network;
5919 struct sta_info *psta;
5923 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5925 if (pBtdm8723->bRAChanged == true && forceUpdate == false)
5928 pstapriv = &padapter->stapriv;
5929 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5930 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5931 macid = psta->mac_id;
5933 filter |= BIT(_1M_RATE_);
5934 filter |= BIT(_2M_RATE_);
5935 filter |= BIT(_5M_RATE_);
5936 filter |= BIT(_11M_RATE_);
5937 filter |= BIT(_6M_RATE_);
5938 filter |= BIT(_9M_RATE_);
5940 btdm_1AntUpdateHalRAMask(padapter, macid, filter);
5942 pBtdm8723->bRAChanged = true;
5945 static void btdm_1AntRecoverHalRAMask(struct rtw_adapter *padapter)
5947 struct btdm_8723a_1ant *pBtdm8723;
5948 struct sta_priv *pstapriv;
5949 struct wlan_bssid_ex *cur_network;
5950 struct sta_info *psta;
5952 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5954 if (pBtdm8723->bRAChanged == false)
5957 pstapriv = &padapter->stapriv;
5958 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5959 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5961 Update_RA_Entry23a(padapter, psta);
5963 pBtdm8723->bRAChanged = false;
5967 btdm_1AntBTStateChangeHandler(struct rtw_adapter *padapter,
5968 enum bt_state_1ant oldState,
5969 enum bt_state_1ant newState)
5971 struct hal_data_8723a *phaldata;
5972 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT state change, %s => %s\n",
5973 BtStateString[oldState],
5974 BtStateString[newState]));
5976 /* BT default ignore wlan active, */
5977 /* WiFi MUST disable this when BT is enable */
5978 if (newState > BT_INFO_STATE_DISABLED)
5979 btdm_SetFwIgnoreWlanAct(padapter, false);
5981 if ((check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
5982 (BTDM_IsWifiConnectionExist(padapter))) {
5983 if ((newState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
5984 (newState == BT_INFO_STATE_ACL_SCO_BUSY)) {
5985 btdm_1AntUpdateHalRAMaskForSCO(padapter, false);
5987 /* Recover original RA setting */
5988 btdm_1AntRecoverHalRAMask(padapter);
5991 phaldata = GET_HAL_DATA(padapter);
5992 phaldata->bt_coexist.halCoex8723.btdm1Ant.bRAChanged = false;
5995 if (oldState == newState)
5998 if (oldState == BT_INFO_STATE_ACL_ONLY_BUSY) {
5999 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
6000 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCnt = 0;
6001 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
6004 if ((oldState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6005 (oldState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6006 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
6007 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
6010 /* Active 2Ant mechanism when BT Connected */
6011 if ((oldState == BT_INFO_STATE_DISABLED) ||
6012 (oldState == BT_INFO_STATE_NO_CONNECTION)) {
6013 if ((newState != BT_INFO_STATE_DISABLED) &&
6014 (newState != BT_INFO_STATE_NO_CONNECTION)) {
6015 BTDM_SetSwRfRxLpfCorner(padapter,
6016 BT_RF_RX_LPF_CORNER_SHRINK);
6017 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6018 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6021 if ((newState == BT_INFO_STATE_DISABLED) ||
6022 (newState == BT_INFO_STATE_NO_CONNECTION)) {
6023 BTDM_SetSwRfRxLpfCorner(padapter,
6024 BT_RF_RX_LPF_CORNER_RESUME);
6025 BTDM_AGCTable(padapter, BT_AGCTABLE_OFF);
6026 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_OFF);
6031 static void btdm_1AntBtCoexistHandler(struct rtw_adapter *padapter)
6033 struct hal_data_8723a *pHalData;
6034 struct bt_coexist_8723a *pBtCoex8723;
6035 struct btdm_8723a_1ant *pBtdm8723;
6037 pHalData = GET_HAL_DATA(padapter);
6038 pBtCoex8723 = &pHalData->bt_coexist.halCoex8723;
6039 pBtdm8723 = &pBtCoex8723->btdm1Ant;
6040 padapter->pwrctrlpriv.btcoex_rfon = false;
6041 if (!rtl8723a_BT_enabled(padapter)) {
6042 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is disabled\n"));
6044 if (BTDM_IsWifiConnectionExist(padapter)) {
6045 RTPRINT(FBT, BT_TRACE,
6046 ("[BTCoex], wifi is connected\n"));
6048 if (BTDM_IsWifiBusy(padapter)) {
6049 RTPRINT(FBT, BT_TRACE,
6050 ("[BTCoex], Wifi is busy\n"));
6051 btdm_1AntSetPSTDMA(padapter, false, 0,
6054 RTPRINT(FBT, BT_TRACE,
6055 ("[BTCoex], Wifi is idle\n"));
6056 _btdm_1AntSetPSTDMA(padapter, true, 2, 1,
6060 RTPRINT(FBT, BT_TRACE,
6061 ("[BTCoex], wifi is disconnected\n"));
6063 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6066 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is enabled\n"));
6068 if (BTDM_IsWifiConnectionExist(padapter)) {
6069 RTPRINT(FBT, BT_TRACE,
6070 ("[BTCoex], wifi is connected\n"));
6072 btdm_1AntWifiParaAdjust(padapter, true);
6073 btdm_1AntCoexProcessForWifiConnect(padapter);
6075 RTPRINT(FBT, BT_TRACE,
6076 ("[BTCoex], wifi is disconnected\n"));
6078 /* Antenna switch at BT side(0x870 = 0x300,
6079 0x860 = 0x210) after PSTDMA off */
6080 btdm_1AntWifiParaAdjust(padapter, false);
6081 btdm_1AntSetPSTDMA(padapter, false, 0, false, 0);
6085 btdm_1AntBTStateChangeHandler(padapter, pBtCoex8723->prec2hBtInfo,
6086 pBtCoex8723->c2hBtInfo);
6087 pBtCoex8723->prec2hBtInfo = pBtCoex8723->c2hBtInfo;
6090 void BTDM_1AntSignalCompensation(struct rtw_adapter *padapter,
6091 u8 *rssi_wifi, u8 *rssi_bt)
6093 struct hal_data_8723a *pHalData;
6094 struct btdm_8723a_1ant *pBtdm8723;
6095 u8 RSSI_WiFi_Cmpnstn, RSSI_BT_Cmpnstn;
6097 pHalData = GET_HAL_DATA(padapter);
6098 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
6099 RSSI_WiFi_Cmpnstn = 0;
6100 RSSI_BT_Cmpnstn = 0;
6102 switch (pBtdm8723->curPsTdma) {
6103 case 1: /* WiFi 52ms */
6104 RSSI_WiFi_Cmpnstn = 11; /* 22*0.48 */
6106 case 2: /* WiFi 36ms */
6107 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6109 case 9: /* WiFi 20ms */
6110 RSSI_WiFi_Cmpnstn = 18; /* 22*0.80 */
6112 case 11: /* WiFi 10ms */
6113 RSSI_WiFi_Cmpnstn = 20; /* 22*0.90 */
6115 case 4: /* WiFi 21ms */
6116 RSSI_WiFi_Cmpnstn = 17; /* 22*0.79 */
6118 case 16: /* WiFi 24ms */
6119 RSSI_WiFi_Cmpnstn = 18; /* 22*0.76 */
6121 case 18: /* WiFi 37ms */
6122 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6124 case 23: /* Level-1, Antenna switch to BT at all time */
6125 case 24: /* Level-2, Antenna switch to BT at all time */
6126 case 25: /* Level-3a, Antenna switch to BT at all time */
6127 case 26: /* Level-3b, Antenna switch to BT at all time */
6128 case 27: /* Level-3b, Antenna switch to BT at all time */
6129 case 33: /* BT SCO & WiFi site survey */
6130 RSSI_WiFi_Cmpnstn = 22;
6136 if (rssi_wifi && RSSI_WiFi_Cmpnstn) {
6137 RTPRINT(FBT, BT_TRACE,
6138 ("[BTCoex], 1AntSgnlCmpnstn, case %d, WiFiCmpnstn "
6139 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6140 RSSI_WiFi_Cmpnstn, *rssi_wifi,
6141 *rssi_wifi+RSSI_WiFi_Cmpnstn));
6142 *rssi_wifi += RSSI_WiFi_Cmpnstn;
6145 if (rssi_bt && RSSI_BT_Cmpnstn) {
6146 RTPRINT(FBT, BT_TRACE,
6147 ("[BTCoex], 1AntSgnlCmpnstn, case %d, BTCmpnstn "
6148 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6149 RSSI_BT_Cmpnstn, *rssi_bt, *rssi_bt+RSSI_BT_Cmpnstn));
6150 *rssi_bt += RSSI_BT_Cmpnstn;
6154 static void BTDM_1AntParaInit(struct rtw_adapter *padapter)
6156 struct hal_data_8723a *pHalData;
6157 struct bt_coexist_8723a *pBtCoex;
6158 struct btdm_8723a_1ant *pBtdm8723;
6160 pHalData = GET_HAL_DATA(padapter);
6161 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6162 pBtdm8723 = &pBtCoex->btdm1Ant;
6164 /* Enable counter statistics */
6165 rtl8723au_write8(padapter, 0x76e, 0x4);
6166 btdm_1AntPtaParaReload(padapter);
6168 pBtdm8723->wifiRssiThresh = 48;
6170 pBtdm8723->bWiFiHalt = false;
6171 pBtdm8723->bRAChanged = false;
6173 if ((pBtCoex->c2hBtInfo != BT_INFO_STATE_DISABLED) &&
6174 (pBtCoex->c2hBtInfo != BT_INFO_STATE_NO_CONNECTION)) {
6175 BTDM_SetSwRfRxLpfCorner(padapter, BT_RF_RX_LPF_CORNER_SHRINK);
6176 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6177 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6181 static void BTDM_1AntForHalt(struct rtw_adapter *padapter)
6183 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for halt\n"));
6185 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6188 btdm_1AntWifiParaAdjust(padapter, false);
6190 /* don't use btdm_1AntSetPSTDMA() here */
6191 /* it will call rtw_set_ps_mode23a() and request pwrpriv->lock. */
6192 /* This will lead to deadlock, if this function is called in IPS */
6193 /* Lucas@20130205 */
6194 btdm_1AntPsTdma(padapter, false, 0);
6196 btdm_SetFwIgnoreWlanAct(padapter, true);
6199 static void BTDM_1AntLpsLeave(struct rtw_adapter *padapter)
6201 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for LPS Leave\n"));
6203 /* Prevent from entering LPS again */
6204 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6207 btdm_1AntSetPSTDMA(padapter, false, 0, false, 8);
6208 /*btdm_1AntPsTdma(padapter, false, 8); */
6211 static void BTDM_1AntWifiAssociateNotify(struct rtw_adapter *padapter, u8 type)
6213 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6215 RTPRINT(FBT, BT_TRACE,
6216 ("\n[BTCoex], 1Ant for associate, type =%d\n", type));
6219 rtl8723a_CheckAntenna_Selection(padapter);
6220 if (!rtl8723a_BT_enabled(padapter))
6221 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6223 struct bt_coexist_8723a *pBtCoex;
6226 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6227 BtState = pBtCoex->c2hBtInfo;
6229 btdm_1AntTSFSwitch(padapter, true);
6231 if (BtState == BT_INFO_STATE_NO_CONNECTION ||
6232 BtState == BT_INFO_STATE_CONNECT_IDLE) {
6233 btdm_1AntSetPSTDMA(padapter, false, 0,
6235 } else if (BtState == BT_INFO_STATE_SCO_ONLY_BUSY ||
6236 BtState == BT_INFO_STATE_ACL_SCO_BUSY) {
6237 btdm_1AntSetPSTDMA(padapter, false, 0,
6239 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
6240 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
6241 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY ||
6242 BtState == BT_INFO_STATE_ACL_INQ_OR_PAG) {
6243 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6244 btdm_1AntSetPSTDMA(padapter, false, 0,
6247 btdm_1AntSetPSTDMA(padapter, false, 0,
6252 if (!rtl8723a_BT_enabled(padapter)) {
6253 if (!BTDM_IsWifiConnectionExist(padapter)) {
6254 btdm_1AntPsTdma(padapter, false, 0);
6255 btdm_1AntTSFSwitch(padapter, false);
6259 btdm_1AntBtCoexistHandler(padapter);
6264 BTDM_1AntMediaStatusNotify(struct rtw_adapter *padapter,
6265 enum rt_media_status mstatus)
6267 struct bt_coexist_8723a *pBtCoex;
6269 pBtCoex = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723;
6271 RTPRINT(FBT, BT_TRACE,
6272 ("\n\n[BTCoex]******************************\n"));
6273 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatus, WiFi %s !!\n",
6274 mstatus == RT_MEDIA_CONNECT?"CONNECT":"DISCONNECT"));
6275 RTPRINT(FBT, BT_TRACE, ("[BTCoex]******************************\n"));
6277 if (RT_MEDIA_CONNECT == mstatus) {
6278 if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) {
6279 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_SCO_ONLY_BUSY ||
6280 pBtCoex->c2hBtInfo == BT_INFO_STATE_ACL_SCO_BUSY)
6281 btdm_1AntUpdateHalRAMaskForSCO(padapter, true);
6284 padapter->pwrctrlpriv.DelayLPSLastTimeStamp = jiffies;
6285 BTDM_1AntForDhcp(padapter);
6287 /* DBG_8723A("%s rtl8723a_DeinitAntenna_Selection\n",
6289 rtl8723a_DeinitAntenna_Selection(padapter);
6290 btdm_1AntBtCoexistHandler(padapter);
6291 pBtCoex->btdm1Ant.bRAChanged = false;
6295 void BTDM_1AntForDhcp(struct rtw_adapter *padapter)
6297 struct hal_data_8723a *pHalData;
6299 struct bt_coexist_8723a *pBtCoex;
6300 struct btdm_8723a_1ant *pBtdm8723;
6302 pHalData = GET_HAL_DATA(padapter);
6303 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6304 BtState = pBtCoex->c2hBtInfo;
6305 pBtdm8723 = &pBtCoex->btdm1Ant;
6307 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for DHCP\n"));
6308 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, WiFi is %s\n",
6309 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6310 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, %s\n",
6311 BtStateString[BtState]));
6313 BTDM_1AntWifiAssociateNotify(padapter, true);
6316 static void BTDM_1AntWifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
6318 struct hal_data_8723a *pHalData;
6320 struct bt_coexist_8723a *pBtCoex;
6321 struct btdm_8723a_1ant *pBtdm8723;
6323 pHalData = GET_HAL_DATA(padapter);
6324 BtState = pHalData->bt_coexist.halCoex8723.c2hBtInfo;
6325 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6326 pBtdm8723 = &pBtCoex->btdm1Ant;
6328 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for wifi scan =%d!!\n",
6330 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, WiFi is %s\n",
6331 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6332 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, %s\n",
6333 BtStateString[BtState]));
6336 rtl8723a_CheckAntenna_Selection(padapter);
6337 if (!rtl8723a_BT_enabled(padapter)) {
6338 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6339 } else if (BTDM_IsWifiConnectionExist(padapter) == false) {
6340 BTDM_1AntWifiAssociateNotify(padapter, true);
6342 if ((BtState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6343 (BtState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6344 if (pBtCoex->bC2hBtInquiryPage) {
6345 btdm_1AntSetPSTDMA(padapter, false, 0,
6348 padapter->pwrctrlpriv.btcoex_rfon =
6350 btdm_1AntSetPSTDMA(padapter, true, 0,
6353 } else if (true == pBtCoex->bC2hBtInquiryPage) {
6354 padapter->pwrctrlpriv.btcoex_rfon = true;
6355 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
6356 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY) {
6357 padapter->pwrctrlpriv.btcoex_rfon = true;
6358 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6359 btdm_1AntSetPSTDMA(padapter, true, 0,
6362 btdm_1AntSetPSTDMA(padapter, true, 0,
6365 padapter->pwrctrlpriv.btcoex_rfon = true;
6366 btdm_1AntSetPSTDMA(padapter, true, 0, true, 5);
6370 btdm_NotifyFwScan(padapter, 1);
6372 /* WiFi_Finish_Scan */
6373 btdm_NotifyFwScan(padapter, 0);
6374 btdm_1AntBtCoexistHandler(padapter);
6378 static void BTDM_1AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
6380 struct hal_data_8723a *pHalData;
6381 struct bt_30info *pBTInfo;
6382 struct bt_mgnt *pBtMgnt;
6383 struct bt_coexist_8723a *pBtCoex;
6386 pHalData = GET_HAL_DATA(padapter);
6387 pBTInfo = GET_BT_INFO(padapter);
6388 pBtMgnt = &pBTInfo->BtMgnt;
6389 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6391 u1tmp = pBtCoex->c2hBtInfoOriginal;
6392 /* sco BUSY bit is not used on voice over PCM platform */
6393 btState = u1tmp & 0xF;
6394 pBtCoex->c2hBtProfile = u1tmp & 0xE0;
6396 /* default set bt to idle state. */
6397 pBtMgnt->ExtConfig.bBTBusy = false;
6398 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
6400 /* check BIT2 first ==> check if bt is under inquiry or page scan */
6401 if (btState & BIT(2))
6402 pBtCoex->bC2hBtInquiryPage = true;
6404 pBtCoex->bC2hBtInquiryPage = false;
6407 if (!(btState & BIT(0)))
6408 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
6411 pBtCoex->c2hBtInfo = BT_INFO_STATE_CONNECT_IDLE;
6412 else if (btState == 0x9) {
6413 if (pBtCoex->bC2hBtInquiryPage == true)
6414 pBtCoex->c2hBtInfo =
6415 BT_INFO_STATE_ACL_INQ_OR_PAG;
6417 pBtCoex->c2hBtInfo =
6418 BT_INFO_STATE_ACL_ONLY_BUSY;
6419 pBtMgnt->ExtConfig.bBTBusy = true;
6420 } else if (btState == 0x3) {
6421 pBtCoex->c2hBtInfo = BT_INFO_STATE_SCO_ONLY_BUSY;
6422 pBtMgnt->ExtConfig.bBTBusy = true;
6423 } else if (btState == 0xb) {
6424 pBtCoex->c2hBtInfo = BT_INFO_STATE_ACL_SCO_BUSY;
6425 pBtMgnt->ExtConfig.bBTBusy = true;
6427 pBtCoex->c2hBtInfo = BT_INFO_STATE_MAX;
6428 if (pBtMgnt->ExtConfig.bBTBusy)
6429 pHalData->bt_coexist.CurrentState &=
6430 ~BT_COEX_STATE_BT_IDLE;
6433 if (BT_INFO_STATE_NO_CONNECTION == pBtCoex->c2hBtInfo ||
6434 BT_INFO_STATE_CONNECT_IDLE == pBtCoex->c2hBtInfo) {
6435 if (pBtCoex->bC2hBtInquiryPage)
6436 pBtCoex->c2hBtInfo = BT_INFO_STATE_INQ_OR_PAG;
6439 RTPRINT(FBT, BT_TRACE, ("[BTC2H], %s(%d)\n",
6440 BtStateString[pBtCoex->c2hBtInfo], pBtCoex->c2hBtInfo));
6442 if (pBtCoex->c2hBtProfile != BT_INFO_HID)
6443 pBtCoex->c2hBtProfile &= ~BT_INFO_HID;
6446 void BTDM_1AntBtCoexist8723A(struct rtw_adapter *padapter)
6448 struct mlme_priv *pmlmepriv;
6449 struct hal_data_8723a *pHalData;
6450 unsigned long delta_time;
6452 pmlmepriv = &padapter->mlmepriv;
6453 pHalData = GET_HAL_DATA(padapter);
6455 if (check_fwstate(pmlmepriv, WIFI_SITE_MONITOR)) {
6456 /* already done in BTDM_1AntForScan() */
6457 RTPRINT(FBT, BT_TRACE,
6458 ("[BTCoex], wifi is under scan progress!!\n"));
6462 if (check_fwstate(pmlmepriv, WIFI_UNDER_LINKING)) {
6463 RTPRINT(FBT, BT_TRACE,
6464 ("[BTCoex], wifi is under link progress!!\n"));
6468 /* under DHCP(Special packet) */
6469 delta_time = jiffies - padapter->pwrctrlpriv.DelayLPSLastTimeStamp;
6470 delta_time = jiffies_to_msecs(delta_time);
6471 if (delta_time < 500) {
6472 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is under DHCP "
6473 "progress(%li ms)!!\n", delta_time));
6477 BTDM_CheckWiFiState(padapter);
6479 btdm_1AntBtCoexistHandler(padapter);
6482 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
6484 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
6486 /* local function start with btdm_ */
6487 static u8 btdm_ActionAlgorithm(struct rtw_adapter *padapter)
6489 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
6490 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
6491 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6492 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6493 u8 bScoExist = false, bBtLinkExist = false, bBtHsModeExist = false;
6494 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
6496 if (pBtMgnt->ExtConfig.NumberOfHandle)
6497 bBtLinkExist = true;
6498 if (pBtMgnt->ExtConfig.NumberOfSCO)
6500 if (BT_HsConnectionEstablished(padapter))
6501 bBtHsModeExist = true;
6503 /* here we get BT status first */
6505 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
6507 if ((bScoExist) || (bBtHsModeExist) ||
6508 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID))) {
6509 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO or HID or HS exists, set BT non-idle !!!\n"));
6510 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6513 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6514 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP))) {
6515 if (BTDM_BtTxRxCounterL(padapter) < 100) {
6516 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx < 100, set BT connected-idle!!!\n"));
6517 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6519 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx >= 100, set BT non-idle!!!\n"));
6520 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6524 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6525 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6526 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6527 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6528 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6530 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6531 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6532 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6533 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6534 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6538 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6539 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, set BT non-idle!!!\n"));
6540 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6543 /* Pan+A2dp profile */
6544 if ((pBtMgnt->ExtConfig.NumberOfHandle == 2) &&
6545 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) &&
6546 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6547 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6548 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6549 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6551 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6552 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6553 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6554 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6555 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6559 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6560 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, set BT non-idle!!!\n"));
6561 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6565 if (BT_2ANT_BT_STATUS_IDLE != pBtdm8723->btStatus)
6566 pBtMgnt->ExtConfig.bBTBusy = true;
6568 pBtMgnt->ExtConfig.bBTBusy = false;
6570 if (!bBtLinkExist) {
6571 RTPRINT(FBT, BT_TRACE, ("[BTCoex], No profile exists!!!\n"));
6575 if (pBtMgnt->ExtConfig.NumberOfHandle == 1) {
6577 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
6578 algorithm = BT_2ANT_COEX_ALGO_SCO;
6580 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6581 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID only\n"));
6582 algorithm = BT_2ANT_COEX_ALGO_HID;
6583 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6584 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP only\n"));
6585 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6586 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6587 if (bBtHsModeExist) {
6588 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(HS) only\n"));
6589 algorithm = BT_2ANT_COEX_ALGO_PANHS;
6591 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR) only\n"));
6592 algorithm = BT_2ANT_COEX_ALGO_PANEDR;
6595 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d \n",
6596 pBtMgnt->ExtConfig.NumberOfHandle));
6599 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 2) {
6601 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6602 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
6603 algorithm = BT_2ANT_COEX_ALGO_HID;
6604 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6605 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
6606 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6607 if (bBtHsModeExist) {
6608 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
6609 algorithm = BT_2ANT_COEX_ALGO_SCO;
6611 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
6612 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6615 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched ACL profile for NumberOfHandle =%d\n",
6616 pBtMgnt->ExtConfig.NumberOfHandle));
6619 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6620 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6621 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
6622 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6623 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6624 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6625 if (bBtHsModeExist) {
6626 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
6627 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6629 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
6630 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6632 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6633 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6634 if (bBtHsModeExist) {
6635 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
6636 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6638 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
6639 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
6642 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6643 pBtMgnt->ExtConfig.NumberOfHandle));
6646 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 3) {
6648 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6649 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6650 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP\n"));
6651 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6652 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6653 if (bBtHsModeExist) {
6654 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));
6655 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6657 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));
6658 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6660 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6661 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6662 if (bBtHsModeExist) {
6663 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(HS)\n"));
6664 algorithm = BT_2ANT_COEX_ALGO_SCO;
6666 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(EDR)\n"));
6669 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6670 pBtMgnt->ExtConfig.NumberOfHandle));
6673 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6674 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6675 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6676 if (bBtHsModeExist) {
6677 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
6678 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANHS;
6680 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
6681 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
6684 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6685 pBtMgnt->ExtConfig.NumberOfHandle));
6688 } else if (pBtMgnt->ExtConfig.NumberOfHandle >= 3) {
6690 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6691 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6692 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6694 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
6696 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(EDR)\n"));
6698 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6699 pBtMgnt->ExtConfig.NumberOfHandle));
6702 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6703 pBtMgnt->ExtConfig.NumberOfHandle));
6709 static u8 btdm_NeedToDecBtPwr(struct rtw_adapter *padapter)
6711 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6714 if (BT_Operation(padapter)) {
6715 if (pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB > 47) {
6716 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for HS mode!!\n"));
6719 RTPRINT(FBT, BT_TRACE, ("NO Need to decrease bt power for HS mode!!\n"));
6722 if (BTDM_IsWifiConnectionExist(padapter)) {
6723 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for Wifi is connected!!\n"));
6731 btdm_SetCoexTable(struct rtw_adapter *padapter, u32 val0x6c0,
6732 u32 val0x6c8, u8 val0x6cc)
6734 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c0 = 0x%x\n", val0x6c0));
6735 rtl8723au_write32(padapter, 0x6c0, val0x6c0);
6737 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c8 = 0x%x\n", val0x6c8));
6738 rtl8723au_write32(padapter, 0x6c8, val0x6c8);
6740 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6cc = 0x%x\n", val0x6cc));
6741 rtl8723au_write8(padapter, 0x6cc, val0x6cc);
6745 btdm_SetSwFullTimeDacSwing(struct rtw_adapter *padapter, u8 bSwDacSwingOn,
6748 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6750 if (bSwDacSwingOn) {
6751 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing = 0x%x\n", swDacSwingLvl));
6752 PHY_SetBBReg(padapter, 0x880, 0xff000000, swDacSwingLvl);
6753 pHalData->bt_coexist.bSWCoexistAllOff = false;
6755 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing Off!\n"));
6756 PHY_SetBBReg(padapter, 0x880, 0xff000000, 0xc0);
6761 btdm_SetFwDacSwingLevel(struct rtw_adapter *padapter, u8 dacSwingLvl)
6763 u8 H2C_Parameter[1] = {0};
6765 H2C_Parameter[0] = dacSwingLvl;
6767 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Set Dac Swing Level = 0x%x\n", dacSwingLvl));
6768 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write 0x29 = 0x%x\n", H2C_Parameter[0]));
6770 FillH2CCmd(padapter, 0x29, 1, H2C_Parameter);
6773 static void btdm_2AntDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
6775 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6776 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6778 RTPRINT(FBT, BT_TRACE,
6779 ("[BTCoex], Dec BT power = %s\n",
6780 ((bDecBtPwr) ? "ON" : "OFF")));
6781 pBtdm8723->bCurDecBtPwr = bDecBtPwr;
6783 if (pBtdm8723->bPreDecBtPwr == pBtdm8723->bCurDecBtPwr)
6786 BTDM_SetFwDecBtPwr(padapter, pBtdm8723->bCurDecBtPwr);
6788 pBtdm8723->bPreDecBtPwr = pBtdm8723->bCurDecBtPwr;
6792 btdm_2AntFwDacSwingLvl(struct rtw_adapter *padapter, u8 fwDacSwingLvl)
6794 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6795 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6797 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW Dac Swing level = %d\n", fwDacSwingLvl));
6798 pBtdm8723->curFwDacSwingLvl = fwDacSwingLvl;
6800 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preFwDacSwingLvl =%d, curFwDacSwingLvl =%d\n", */
6801 /*pBtdm8723->preFwDacSwingLvl, pBtdm8723->curFwDacSwingLvl)); */
6803 if (pBtdm8723->preFwDacSwingLvl == pBtdm8723->curFwDacSwingLvl)
6806 btdm_SetFwDacSwingLevel(padapter, pBtdm8723->curFwDacSwingLvl);
6808 pBtdm8723->preFwDacSwingLvl = pBtdm8723->curFwDacSwingLvl;
6812 btdm_2AntRfShrink(struct rtw_adapter *padapter, u8 bRxRfShrinkOn)
6814 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6815 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6817 RTPRINT(FBT, BT_TRACE,
6818 ("[BTCoex], turn Rx RF Shrink = %s\n",
6819 ((bRxRfShrinkOn) ? "ON" : "OFF")));
6820 pBtdm8723->bCurRfRxLpfShrink = bRxRfShrinkOn;
6822 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreRfRxLpfShrink =%d, bCurRfRxLpfShrink =%d\n", */
6823 /*pBtdm8723->bPreRfRxLpfShrink, pBtdm8723->bCurRfRxLpfShrink)); */
6825 if (pBtdm8723->bPreRfRxLpfShrink == pBtdm8723->bCurRfRxLpfShrink)
6828 BTDM_SetSwRfRxLpfCorner(padapter, (u8)pBtdm8723->bCurRfRxLpfShrink);
6830 pBtdm8723->bPreRfRxLpfShrink = pBtdm8723->bCurRfRxLpfShrink;
6834 btdm_2AntLowPenaltyRa(struct rtw_adapter *padapter, u8 bLowPenaltyRa)
6836 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6837 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6839 RTPRINT(FBT, BT_TRACE,
6840 ("[BTCoex], turn LowPenaltyRA = %s\n",
6841 ((bLowPenaltyRa) ? "ON" : "OFF")));
6842 pBtdm8723->bCurLowPenaltyRa = bLowPenaltyRa;
6844 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreLowPenaltyRa =%d, bCurLowPenaltyRa =%d\n", */
6845 /*pBtdm8723->bPreLowPenaltyRa, pBtdm8723->bCurLowPenaltyRa)); */
6847 if (pBtdm8723->bPreLowPenaltyRa == pBtdm8723->bCurLowPenaltyRa)
6850 BTDM_SetSwPenaltyTxRateAdaptive(padapter, (u8)pBtdm8723->bCurLowPenaltyRa);
6852 pBtdm8723->bPreLowPenaltyRa = pBtdm8723->bCurLowPenaltyRa;
6856 btdm_2AntDacSwing(struct rtw_adapter *padapter,
6857 u8 bDacSwingOn, u32 dacSwingLvl)
6859 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6860 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6862 RTPRINT(FBT, BT_TRACE,
6863 ("[BTCoex], turn DacSwing =%s, dacSwingLvl = 0x%x\n",
6864 (bDacSwingOn ? "ON" : "OFF"), dacSwingLvl));
6865 pBtdm8723->bCurDacSwingOn = bDacSwingOn;
6866 pBtdm8723->curDacSwingLvl = dacSwingLvl;
6868 if ((pBtdm8723->bPreDacSwingOn == pBtdm8723->bCurDacSwingOn) &&
6869 (pBtdm8723->preDacSwingLvl == pBtdm8723->curDacSwingLvl))
6873 btdm_SetSwFullTimeDacSwing(padapter, bDacSwingOn, dacSwingLvl);
6875 pBtdm8723->bPreDacSwingOn = pBtdm8723->bCurDacSwingOn;
6876 pBtdm8723->preDacSwingLvl = pBtdm8723->curDacSwingLvl;
6879 static void btdm_2AntAdcBackOff(struct rtw_adapter *padapter, u8 bAdcBackOff)
6881 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6882 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6884 RTPRINT(FBT, BT_TRACE,
6885 ("[BTCoex], turn AdcBackOff = %s\n",
6886 ((bAdcBackOff) ? "ON" : "OFF")));
6887 pBtdm8723->bCurAdcBackOff = bAdcBackOff;
6889 if (pBtdm8723->bPreAdcBackOff == pBtdm8723->bCurAdcBackOff)
6892 BTDM_BBBackOffLevel(padapter, (u8)pBtdm8723->bCurAdcBackOff);
6894 pBtdm8723->bPreAdcBackOff = pBtdm8723->bCurAdcBackOff;
6897 static void btdm_2AntAgcTable(struct rtw_adapter *padapter, u8 bAgcTableEn)
6899 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6900 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6902 RTPRINT(FBT, BT_TRACE,
6903 ("[BTCoex], %s Agc Table\n", ((bAgcTableEn) ? "Enable" : "Disable")));
6904 pBtdm8723->bCurAgcTableEn = bAgcTableEn;
6906 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreAgcTableEn =%d, bCurAgcTableEn =%d\n", */
6907 /*pBtdm8723->bPreAgcTableEn, pBtdm8723->bCurAgcTableEn)); */
6909 if (pBtdm8723->bPreAgcTableEn == pBtdm8723->bCurAgcTableEn)
6912 BTDM_AGCTable(padapter, (u8)bAgcTableEn);
6914 pBtdm8723->bPreAgcTableEn = pBtdm8723->bCurAgcTableEn;
6918 btdm_2AntCoexTable(struct rtw_adapter *padapter,
6919 u32 val0x6c0, u32 val0x6c8, u8 val0x6cc)
6921 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6922 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6924 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write Coex Table 0x6c0 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
6925 val0x6c0, val0x6c8, val0x6cc));
6926 pBtdm8723->curVal0x6c0 = val0x6c0;
6927 pBtdm8723->curVal0x6c8 = val0x6c8;
6928 pBtdm8723->curVal0x6cc = val0x6cc;
6930 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n", */
6931 /*pBtdm8723->preVal0x6c0, pBtdm8723->preVal0x6c8, pBtdm8723->preVal0x6cc)); */
6932 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n", */
6933 /*pBtdm8723->curVal0x6c0, pBtdm8723->curVal0x6c8, pBtdm8723->curVal0x6cc)); */
6935 if ((pBtdm8723->preVal0x6c0 == pBtdm8723->curVal0x6c0) &&
6936 (pBtdm8723->preVal0x6c8 == pBtdm8723->curVal0x6c8) &&
6937 (pBtdm8723->preVal0x6cc == pBtdm8723->curVal0x6cc))
6940 btdm_SetCoexTable(padapter, val0x6c0, val0x6c8, val0x6cc);
6942 pBtdm8723->preVal0x6c0 = pBtdm8723->curVal0x6c0;
6943 pBtdm8723->preVal0x6c8 = pBtdm8723->curVal0x6c8;
6944 pBtdm8723->preVal0x6cc = pBtdm8723->curVal0x6cc;
6947 static void btdm_2AntIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
6949 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6950 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6952 RTPRINT(FBT, BT_TRACE,
6953 ("[BTCoex], turn Ignore WlanAct %s\n", (bEnable ? "ON" : "OFF")));
6954 pBtdm8723->bCurIgnoreWlanAct = bEnable;
6957 if (pBtdm8723->bPreIgnoreWlanAct == pBtdm8723->bCurIgnoreWlanAct)
6960 btdm_SetFwIgnoreWlanAct(padapter, bEnable);
6961 pBtdm8723->bPreIgnoreWlanAct = pBtdm8723->bCurIgnoreWlanAct;
6965 btdm_2AntSetFw3a(struct rtw_adapter *padapter, u8 byte1, u8 byte2,
6966 u8 byte3, u8 byte4, u8 byte5)
6968 u8 H2C_Parameter[5] = {0};
6970 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6972 /* byte1[1:0] != 0 means enable pstdma */
6973 /* for 2Ant bt coexist, if byte1 != 0 means enable pstdma */
6975 pHalData->bt_coexist.bFWCoexistAllOff = false;
6976 H2C_Parameter[0] = byte1;
6977 H2C_Parameter[1] = byte2;
6978 H2C_Parameter[2] = byte3;
6979 H2C_Parameter[3] = byte4;
6980 H2C_Parameter[4] = byte5;
6982 pHalData->bt_coexist.fw3aVal[0] = byte1;
6983 pHalData->bt_coexist.fw3aVal[1] = byte2;
6984 pHalData->bt_coexist.fw3aVal[2] = byte3;
6985 pHalData->bt_coexist.fw3aVal[3] = byte4;
6986 pHalData->bt_coexist.fw3aVal[4] = byte5;
6988 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%x%08x\n",
6990 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
6992 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
6995 static void btdm_2AntPsTdma(struct rtw_adapter *padapter, u8 bTurnOn, u8 type)
6997 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6998 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7000 u8 bTurnOnByCnt = false;
7001 u8 psTdmaTypeByCnt = 0;
7003 btTxRxCnt = BTDM_BtTxRxCounterH(padapter)+BTDM_BtTxRxCounterL(padapter);
7004 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT TxRx Counters = %d\n", btTxRxCnt));
7005 if (btTxRxCnt > 3000) {
7006 bTurnOnByCnt = true;
7007 psTdmaTypeByCnt = 8;
7009 RTPRINT(FBT, BT_TRACE,
7010 ("[BTCoex], For BTTxRxCounters, turn %s PS TDMA, type =%d\n",
7011 (bTurnOnByCnt ? "ON" : "OFF"), psTdmaTypeByCnt));
7012 pBtdm8723->bCurPsTdmaOn = bTurnOnByCnt;
7013 pBtdm8723->curPsTdma = psTdmaTypeByCnt;
7015 RTPRINT(FBT, BT_TRACE,
7016 ("[BTCoex], turn %s PS TDMA, type =%d\n",
7017 (bTurnOn ? "ON" : "OFF"), type));
7018 pBtdm8723->bCurPsTdmaOn = bTurnOn;
7019 pBtdm8723->curPsTdma = type;
7022 if ((pBtdm8723->bPrePsTdmaOn == pBtdm8723->bCurPsTdmaOn) &&
7023 (pBtdm8723->prePsTdma == pBtdm8723->curPsTdma))
7030 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
7033 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
7036 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
7039 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0xa1, 0x80);
7042 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7045 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7048 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7051 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0x20, 0x80);
7054 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
7057 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
7060 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
7063 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7066 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7069 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7072 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7075 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0x20, 0x98);
7078 btdm_2AntSetFw3a(padapter, 0xa3, 0x2f, 0x2f, 0x20, 0x80);
7081 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7084 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0xa1, 0x98);
7087 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0x20, 0x98);
7091 /* disable PS tdma */
7094 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7097 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x0, 0x0);
7100 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7105 /* update pre state */
7106 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
7107 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
7110 static void btdm_2AntBtInquiryPage(struct rtw_adapter *padapter)
7112 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7113 btdm_2AntIgnoreWlanAct(padapter, false);
7114 btdm_2AntPsTdma(padapter, true, 8);
7117 static u8 btdm_HoldForBtInqPage(struct rtw_adapter *padapter)
7119 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7120 u32 curTime = jiffies;
7122 if (pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
7123 /* bt inquiry or page is started. */
7124 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime == 0) {
7125 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = curTime;
7126 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page is started at time : 0x%lx \n",
7127 pHalData->bt_coexist.halCoex8723.btInqPageStartTime));
7130 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page started time : 0x%lx, curTime : 0x%x \n",
7131 pHalData->bt_coexist.halCoex8723.btInqPageStartTime, curTime));
7133 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7134 if (((curTime - pHalData->bt_coexist.halCoex8723.btInqPageStartTime)/1000000) >= 10) {
7135 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page >= 10sec!!!"));
7136 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = 0;
7140 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7141 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7142 btdm_2AntIgnoreWlanAct(padapter, false);
7143 btdm_2AntPsTdma(padapter, true, 8);
7150 static u8 btdm_Is2Ant8723ACommonAction(struct rtw_adapter *padapter)
7152 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7153 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7156 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));
7158 if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7159 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7160 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7161 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt idle!!\n"));
7163 btdm_2AntLowPenaltyRa(padapter, false);
7164 btdm_2AntRfShrink(padapter, false);
7165 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7167 btdm_2AntIgnoreWlanAct(padapter, false);
7168 btdm_2AntPsTdma(padapter, false, 0);
7169 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7170 btdm_2AntDecBtPwr(padapter, false);
7172 btdm_2AntAgcTable(padapter, false);
7173 btdm_2AntAdcBackOff(padapter, false);
7174 btdm_2AntDacSwing(padapter, false, 0xc0);
7177 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7178 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7179 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7180 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT idle!!\n"));
7182 btdm_2AntLowPenaltyRa(padapter, true);
7183 btdm_2AntRfShrink(padapter, false);
7184 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7186 btdm_2AntIgnoreWlanAct(padapter, false);
7187 btdm_2AntPsTdma(padapter, false, 0);
7188 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7189 btdm_2AntDecBtPwr(padapter, true);
7191 btdm_2AntAgcTable(padapter, false);
7192 btdm_2AntAdcBackOff(padapter, false);
7193 btdm_2AntDacSwing(padapter, false, 0xc0);
7196 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7197 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7198 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7199 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt connected idle!!\n"));
7201 btdm_2AntLowPenaltyRa(padapter, true);
7202 btdm_2AntRfShrink(padapter, true);
7203 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7205 btdm_2AntIgnoreWlanAct(padapter, false);
7206 btdm_2AntPsTdma(padapter, false, 0);
7207 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7208 btdm_2AntDecBtPwr(padapter, false);
7210 btdm_2AntAgcTable(padapter, false);
7211 btdm_2AntAdcBackOff(padapter, false);
7212 btdm_2AntDacSwing(padapter, false, 0xc0);
7215 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7216 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7217 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7218 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + Bt connected idle!!\n"));
7220 btdm_2AntLowPenaltyRa(padapter, true);
7221 btdm_2AntRfShrink(padapter, true);
7222 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7224 btdm_2AntIgnoreWlanAct(padapter, false);
7225 btdm_2AntPsTdma(padapter, false, 0);
7226 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7227 btdm_2AntDecBtPwr(padapter, true);
7229 btdm_2AntAgcTable(padapter, false);
7230 btdm_2AntAdcBackOff(padapter, false);
7231 btdm_2AntDacSwing(padapter, false, 0xc0);
7234 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7235 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7236 (BT_2ANT_BT_STATUS_NON_IDLE == pBtdm8723->btStatus)) {
7237 RTPRINT(FBT, BT_TRACE, ("Wifi idle + BT non-idle!!\n"));
7239 btdm_2AntLowPenaltyRa(padapter, true);
7240 btdm_2AntRfShrink(padapter, true);
7241 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7243 btdm_2AntIgnoreWlanAct(padapter, false);
7244 btdm_2AntPsTdma(padapter, false, 0);
7245 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7246 btdm_2AntDecBtPwr(padapter, false);
7248 btdm_2AntAgcTable(padapter, false);
7249 btdm_2AntAdcBackOff(padapter, false);
7250 btdm_2AntDacSwing(padapter, false, 0xc0);
7254 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT non-idle!!\n"));
7255 btdm_2AntLowPenaltyRa(padapter, true);
7256 btdm_2AntRfShrink(padapter, true);
7257 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7258 btdm_2AntIgnoreWlanAct(padapter, false);
7259 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7267 btdm_2AntTdmaDurationAdjust(struct rtw_adapter *padapter, u8 bScoHid,
7268 u8 bTxPause, u8 maxInterval)
7270 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7271 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7272 static s32 up, dn, m, n, WaitCount;
7273 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
7276 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));
7278 if (pBtdm8723->bResetTdmaAdjust) {
7279 pBtdm8723->bResetTdmaAdjust = false;
7280 RTPRINT(FBT, BT_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
7283 if (maxInterval == 1) {
7284 btdm_2AntPsTdma(padapter, true, 15);
7285 pBtdm8723->psTdmaDuAdjType = 15;
7286 } else if (maxInterval == 2) {
7287 btdm_2AntPsTdma(padapter, true, 15);
7288 pBtdm8723->psTdmaDuAdjType = 15;
7289 } else if (maxInterval == 3) {
7290 btdm_2AntPsTdma(padapter, true, 15);
7291 pBtdm8723->psTdmaDuAdjType = 15;
7293 btdm_2AntPsTdma(padapter, true, 15);
7294 pBtdm8723->psTdmaDuAdjType = 15;
7297 if (maxInterval == 1) {
7298 btdm_2AntPsTdma(padapter, true, 11);
7299 pBtdm8723->psTdmaDuAdjType = 11;
7300 } else if (maxInterval == 2) {
7301 btdm_2AntPsTdma(padapter, true, 11);
7302 pBtdm8723->psTdmaDuAdjType = 11;
7303 } else if (maxInterval == 3) {
7304 btdm_2AntPsTdma(padapter, true, 11);
7305 pBtdm8723->psTdmaDuAdjType = 11;
7307 btdm_2AntPsTdma(padapter, true, 11);
7308 pBtdm8723->psTdmaDuAdjType = 11;
7313 if (maxInterval == 1) {
7314 btdm_2AntPsTdma(padapter, true, 7);
7315 pBtdm8723->psTdmaDuAdjType = 7;
7316 } else if (maxInterval == 2) {
7317 btdm_2AntPsTdma(padapter, true, 7);
7318 pBtdm8723->psTdmaDuAdjType = 7;
7319 } else if (maxInterval == 3) {
7320 btdm_2AntPsTdma(padapter, true, 7);
7321 pBtdm8723->psTdmaDuAdjType = 7;
7323 btdm_2AntPsTdma(padapter, true, 7);
7324 pBtdm8723->psTdmaDuAdjType = 7;
7327 if (maxInterval == 1) {
7328 btdm_2AntPsTdma(padapter, true, 3);
7329 pBtdm8723->psTdmaDuAdjType = 3;
7330 } else if (maxInterval == 2) {
7331 btdm_2AntPsTdma(padapter, true, 3);
7332 pBtdm8723->psTdmaDuAdjType = 3;
7333 } else if (maxInterval == 3) {
7334 btdm_2AntPsTdma(padapter, true, 3);
7335 pBtdm8723->psTdmaDuAdjType = 3;
7337 btdm_2AntPsTdma(padapter, true, 3);
7338 pBtdm8723->psTdmaDuAdjType = 3;
7349 /* accquire the BT TRx retry count from BT_Info byte2 */
7350 retryCount = pHalData->bt_coexist.halCoex8723.btRetryCnt;
7351 RTPRINT(FBT, BT_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));
7355 if (retryCount == 0) { /* no retry in the last 2-second duration */
7362 if (up >= n) { /* if ³sÄò n Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */
7368 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
7370 } else if (retryCount <= 3) { /* <= 3 retry in the last 2-second duration */
7377 if (dn == 2) { /* if ³sÄò 2 Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */
7379 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7383 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7391 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
7393 } else { /* retry count > 3, ¥un1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */
7395 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7399 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7406 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
7409 RTPRINT(FBT, BT_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));
7410 if (maxInterval == 1) {
7412 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7413 if (pBtdm8723->curPsTdma == 1) {
7414 btdm_2AntPsTdma(padapter, true, 5);
7415 pBtdm8723->psTdmaDuAdjType = 5;
7416 } else if (pBtdm8723->curPsTdma == 2) {
7417 btdm_2AntPsTdma(padapter, true, 6);
7418 pBtdm8723->psTdmaDuAdjType = 6;
7419 } else if (pBtdm8723->curPsTdma == 3) {
7420 btdm_2AntPsTdma(padapter, true, 7);
7421 pBtdm8723->psTdmaDuAdjType = 7;
7422 } else if (pBtdm8723->curPsTdma == 4) {
7423 btdm_2AntPsTdma(padapter, true, 8);
7424 pBtdm8723->psTdmaDuAdjType = 8;
7426 if (pBtdm8723->curPsTdma == 9) {
7427 btdm_2AntPsTdma(padapter, true, 13);
7428 pBtdm8723->psTdmaDuAdjType = 13;
7429 } else if (pBtdm8723->curPsTdma == 10) {
7430 btdm_2AntPsTdma(padapter, true, 14);
7431 pBtdm8723->psTdmaDuAdjType = 14;
7432 } else if (pBtdm8723->curPsTdma == 11) {
7433 btdm_2AntPsTdma(padapter, true, 15);
7434 pBtdm8723->psTdmaDuAdjType = 15;
7435 } else if (pBtdm8723->curPsTdma == 12) {
7436 btdm_2AntPsTdma(padapter, true, 16);
7437 pBtdm8723->psTdmaDuAdjType = 16;
7441 if (pBtdm8723->curPsTdma == 5) {
7442 btdm_2AntPsTdma(padapter, true, 6);
7443 pBtdm8723->psTdmaDuAdjType = 6;
7444 } else if (pBtdm8723->curPsTdma == 6) {
7445 btdm_2AntPsTdma(padapter, true, 7);
7446 pBtdm8723->psTdmaDuAdjType = 7;
7447 } else if (pBtdm8723->curPsTdma == 7) {
7448 btdm_2AntPsTdma(padapter, true, 8);
7449 pBtdm8723->psTdmaDuAdjType = 8;
7450 } else if (pBtdm8723->curPsTdma == 13) {
7451 btdm_2AntPsTdma(padapter, true, 14);
7452 pBtdm8723->psTdmaDuAdjType = 14;
7453 } else if (pBtdm8723->curPsTdma == 14) {
7454 btdm_2AntPsTdma(padapter, true, 15);
7455 pBtdm8723->psTdmaDuAdjType = 15;
7456 } else if (pBtdm8723->curPsTdma == 15) {
7457 btdm_2AntPsTdma(padapter, true, 16);
7458 pBtdm8723->psTdmaDuAdjType = 16;
7460 } else if (result == 1) {
7461 if (pBtdm8723->curPsTdma == 8) {
7462 btdm_2AntPsTdma(padapter, true, 7);
7463 pBtdm8723->psTdmaDuAdjType = 7;
7464 } else if (pBtdm8723->curPsTdma == 7) {
7465 btdm_2AntPsTdma(padapter, true, 6);
7466 pBtdm8723->psTdmaDuAdjType = 6;
7467 } else if (pBtdm8723->curPsTdma == 6) {
7468 btdm_2AntPsTdma(padapter, true, 5);
7469 pBtdm8723->psTdmaDuAdjType = 5;
7470 } else if (pBtdm8723->curPsTdma == 16) {
7471 btdm_2AntPsTdma(padapter, true, 15);
7472 pBtdm8723->psTdmaDuAdjType = 15;
7473 } else if (pBtdm8723->curPsTdma == 15) {
7474 btdm_2AntPsTdma(padapter, true, 14);
7475 pBtdm8723->psTdmaDuAdjType = 14;
7476 } else if (pBtdm8723->curPsTdma == 14) {
7477 btdm_2AntPsTdma(padapter, true, 13);
7478 pBtdm8723->psTdmaDuAdjType = 13;
7482 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7483 if (pBtdm8723->curPsTdma == 5) {
7484 btdm_2AntPsTdma(padapter, true, 1);
7485 pBtdm8723->psTdmaDuAdjType = 1;
7486 } else if (pBtdm8723->curPsTdma == 6) {
7487 btdm_2AntPsTdma(padapter, true, 2);
7488 pBtdm8723->psTdmaDuAdjType = 2;
7489 } else if (pBtdm8723->curPsTdma == 7) {
7490 btdm_2AntPsTdma(padapter, true, 3);
7491 pBtdm8723->psTdmaDuAdjType = 3;
7492 } else if (pBtdm8723->curPsTdma == 8) {
7493 btdm_2AntPsTdma(padapter, true, 4);
7494 pBtdm8723->psTdmaDuAdjType = 4;
7496 if (pBtdm8723->curPsTdma == 13) {
7497 btdm_2AntPsTdma(padapter, true, 9);
7498 pBtdm8723->psTdmaDuAdjType = 9;
7499 } else if (pBtdm8723->curPsTdma == 14) {
7500 btdm_2AntPsTdma(padapter, true, 10);
7501 pBtdm8723->psTdmaDuAdjType = 10;
7502 } else if (pBtdm8723->curPsTdma == 15) {
7503 btdm_2AntPsTdma(padapter, true, 11);
7504 pBtdm8723->psTdmaDuAdjType = 11;
7505 } else if (pBtdm8723->curPsTdma == 16) {
7506 btdm_2AntPsTdma(padapter, true, 12);
7507 pBtdm8723->psTdmaDuAdjType = 12;
7511 if (pBtdm8723->curPsTdma == 1) {
7512 btdm_2AntPsTdma(padapter, true, 2);
7513 pBtdm8723->psTdmaDuAdjType = 2;
7514 } else if (pBtdm8723->curPsTdma == 2) {
7515 btdm_2AntPsTdma(padapter, true, 3);
7516 pBtdm8723->psTdmaDuAdjType = 3;
7517 } else if (pBtdm8723->curPsTdma == 3) {
7518 btdm_2AntPsTdma(padapter, true, 4);
7519 pBtdm8723->psTdmaDuAdjType = 4;
7520 } else if (pBtdm8723->curPsTdma == 9) {
7521 btdm_2AntPsTdma(padapter, true, 10);
7522 pBtdm8723->psTdmaDuAdjType = 10;
7523 } else if (pBtdm8723->curPsTdma == 10) {
7524 btdm_2AntPsTdma(padapter, true, 11);
7525 pBtdm8723->psTdmaDuAdjType = 11;
7526 } else if (pBtdm8723->curPsTdma == 11) {
7527 btdm_2AntPsTdma(padapter, true, 12);
7528 pBtdm8723->psTdmaDuAdjType = 12;
7530 } else if (result == 1) {
7531 if (pBtdm8723->curPsTdma == 4) {
7532 btdm_2AntPsTdma(padapter, true, 3);
7533 pBtdm8723->psTdmaDuAdjType = 3;
7534 } else if (pBtdm8723->curPsTdma == 3) {
7535 btdm_2AntPsTdma(padapter, true, 2);
7536 pBtdm8723->psTdmaDuAdjType = 2;
7537 } else if (pBtdm8723->curPsTdma == 2) {
7538 btdm_2AntPsTdma(padapter, true, 1);
7539 pBtdm8723->psTdmaDuAdjType = 1;
7540 } else if (pBtdm8723->curPsTdma == 12) {
7541 btdm_2AntPsTdma(padapter, true, 11);
7542 pBtdm8723->psTdmaDuAdjType = 11;
7543 } else if (pBtdm8723->curPsTdma == 11) {
7544 btdm_2AntPsTdma(padapter, true, 10);
7545 pBtdm8723->psTdmaDuAdjType = 10;
7546 } else if (pBtdm8723->curPsTdma == 10) {
7547 btdm_2AntPsTdma(padapter, true, 9);
7548 pBtdm8723->psTdmaDuAdjType = 9;
7552 } else if (maxInterval == 2) {
7554 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7555 if (pBtdm8723->curPsTdma == 1) {
7556 btdm_2AntPsTdma(padapter, true, 6);
7557 pBtdm8723->psTdmaDuAdjType = 6;
7558 } else if (pBtdm8723->curPsTdma == 2) {
7559 btdm_2AntPsTdma(padapter, true, 6);
7560 pBtdm8723->psTdmaDuAdjType = 6;
7561 } else if (pBtdm8723->curPsTdma == 3) {
7562 btdm_2AntPsTdma(padapter, true, 7);
7563 pBtdm8723->psTdmaDuAdjType = 7;
7564 } else if (pBtdm8723->curPsTdma == 4) {
7565 btdm_2AntPsTdma(padapter, true, 8);
7566 pBtdm8723->psTdmaDuAdjType = 8;
7568 if (pBtdm8723->curPsTdma == 9) {
7569 btdm_2AntPsTdma(padapter, true, 14);
7570 pBtdm8723->psTdmaDuAdjType = 14;
7571 } else if (pBtdm8723->curPsTdma == 10) {
7572 btdm_2AntPsTdma(padapter, true, 14);
7573 pBtdm8723->psTdmaDuAdjType = 14;
7574 } else if (pBtdm8723->curPsTdma == 11) {
7575 btdm_2AntPsTdma(padapter, true, 15);
7576 pBtdm8723->psTdmaDuAdjType = 15;
7577 } else if (pBtdm8723->curPsTdma == 12) {
7578 btdm_2AntPsTdma(padapter, true, 16);
7579 pBtdm8723->psTdmaDuAdjType = 16;
7582 if (pBtdm8723->curPsTdma == 5) {
7583 btdm_2AntPsTdma(padapter, true, 6);
7584 pBtdm8723->psTdmaDuAdjType = 6;
7585 } else if (pBtdm8723->curPsTdma == 6) {
7586 btdm_2AntPsTdma(padapter, true, 7);
7587 pBtdm8723->psTdmaDuAdjType = 7;
7588 } else if (pBtdm8723->curPsTdma == 7) {
7589 btdm_2AntPsTdma(padapter, true, 8);
7590 pBtdm8723->psTdmaDuAdjType = 8;
7591 } else if (pBtdm8723->curPsTdma == 13) {
7592 btdm_2AntPsTdma(padapter, true, 14);
7593 pBtdm8723->psTdmaDuAdjType = 14;
7594 } else if (pBtdm8723->curPsTdma == 14) {
7595 btdm_2AntPsTdma(padapter, true, 15);
7596 pBtdm8723->psTdmaDuAdjType = 15;
7597 } else if (pBtdm8723->curPsTdma == 15) {
7598 btdm_2AntPsTdma(padapter, true, 16);
7599 pBtdm8723->psTdmaDuAdjType = 16;
7601 } else if (result == 1) {
7602 if (pBtdm8723->curPsTdma == 8) {
7603 btdm_2AntPsTdma(padapter, true, 7);
7604 pBtdm8723->psTdmaDuAdjType = 7;
7605 } else if (pBtdm8723->curPsTdma == 7) {
7606 btdm_2AntPsTdma(padapter, true, 6);
7607 pBtdm8723->psTdmaDuAdjType = 6;
7608 } else if (pBtdm8723->curPsTdma == 6) {
7609 btdm_2AntPsTdma(padapter, true, 6);
7610 pBtdm8723->psTdmaDuAdjType = 6;
7611 } else if (pBtdm8723->curPsTdma == 16) {
7612 btdm_2AntPsTdma(padapter, true, 15);
7613 pBtdm8723->psTdmaDuAdjType = 15;
7614 } else if (pBtdm8723->curPsTdma == 15) {
7615 btdm_2AntPsTdma(padapter, true, 14);
7616 pBtdm8723->psTdmaDuAdjType = 14;
7617 } else if (pBtdm8723->curPsTdma == 14) {
7618 btdm_2AntPsTdma(padapter, true, 14);
7619 pBtdm8723->psTdmaDuAdjType = 14;
7623 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7624 if (pBtdm8723->curPsTdma == 5) {
7625 btdm_2AntPsTdma(padapter, true, 2);
7626 pBtdm8723->psTdmaDuAdjType = 2;
7627 } else if (pBtdm8723->curPsTdma == 6) {
7628 btdm_2AntPsTdma(padapter, true, 2);
7629 pBtdm8723->psTdmaDuAdjType = 2;
7630 } else if (pBtdm8723->curPsTdma == 7) {
7631 btdm_2AntPsTdma(padapter, true, 3);
7632 pBtdm8723->psTdmaDuAdjType = 3;
7633 } else if (pBtdm8723->curPsTdma == 8) {
7634 btdm_2AntPsTdma(padapter, true, 4);
7635 pBtdm8723->psTdmaDuAdjType = 4;
7637 if (pBtdm8723->curPsTdma == 13) {
7638 btdm_2AntPsTdma(padapter, true, 10);
7639 pBtdm8723->psTdmaDuAdjType = 10;
7640 } else if (pBtdm8723->curPsTdma == 14) {
7641 btdm_2AntPsTdma(padapter, true, 10);
7642 pBtdm8723->psTdmaDuAdjType = 10;
7643 } else if (pBtdm8723->curPsTdma == 15) {
7644 btdm_2AntPsTdma(padapter, true, 11);
7645 pBtdm8723->psTdmaDuAdjType = 11;
7646 } else if (pBtdm8723->curPsTdma == 16) {
7647 btdm_2AntPsTdma(padapter, true, 12);
7648 pBtdm8723->psTdmaDuAdjType = 12;
7651 if (pBtdm8723->curPsTdma == 1) {
7652 btdm_2AntPsTdma(padapter, true, 2);
7653 pBtdm8723->psTdmaDuAdjType = 2;
7654 } else if (pBtdm8723->curPsTdma == 2) {
7655 btdm_2AntPsTdma(padapter, true, 3);
7656 pBtdm8723->psTdmaDuAdjType = 3;
7657 } else if (pBtdm8723->curPsTdma == 3) {
7658 btdm_2AntPsTdma(padapter, true, 4);
7659 pBtdm8723->psTdmaDuAdjType = 4;
7660 } else if (pBtdm8723->curPsTdma == 9) {
7661 btdm_2AntPsTdma(padapter, true, 10);
7662 pBtdm8723->psTdmaDuAdjType = 10;
7663 } else if (pBtdm8723->curPsTdma == 10) {
7664 btdm_2AntPsTdma(padapter, true, 11);
7665 pBtdm8723->psTdmaDuAdjType = 11;
7666 } else if (pBtdm8723->curPsTdma == 11) {
7667 btdm_2AntPsTdma(padapter, true, 12);
7668 pBtdm8723->psTdmaDuAdjType = 12;
7670 } else if (result == 1) {
7671 if (pBtdm8723->curPsTdma == 4) {
7672 btdm_2AntPsTdma(padapter, true, 3);
7673 pBtdm8723->psTdmaDuAdjType = 3;
7674 } else if (pBtdm8723->curPsTdma == 3) {
7675 btdm_2AntPsTdma(padapter, true, 2);
7676 pBtdm8723->psTdmaDuAdjType = 2;
7677 } else if (pBtdm8723->curPsTdma == 2) {
7678 btdm_2AntPsTdma(padapter, true, 2);
7679 pBtdm8723->psTdmaDuAdjType = 2;
7680 } else if (pBtdm8723->curPsTdma == 12) {
7681 btdm_2AntPsTdma(padapter, true, 11);
7682 pBtdm8723->psTdmaDuAdjType = 11;
7683 } else if (pBtdm8723->curPsTdma == 11) {
7684 btdm_2AntPsTdma(padapter, true, 10);
7685 pBtdm8723->psTdmaDuAdjType = 10;
7686 } else if (pBtdm8723->curPsTdma == 10) {
7687 btdm_2AntPsTdma(padapter, true, 10);
7688 pBtdm8723->psTdmaDuAdjType = 10;
7692 } else if (maxInterval == 3) {
7694 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7695 if (pBtdm8723->curPsTdma == 1) {
7696 btdm_2AntPsTdma(padapter, true, 7);
7697 pBtdm8723->psTdmaDuAdjType = 7;
7698 } else if (pBtdm8723->curPsTdma == 2) {
7699 btdm_2AntPsTdma(padapter, true, 7);
7700 pBtdm8723->psTdmaDuAdjType = 7;
7701 } else if (pBtdm8723->curPsTdma == 3) {
7702 btdm_2AntPsTdma(padapter, true, 7);
7703 pBtdm8723->psTdmaDuAdjType = 7;
7704 } else if (pBtdm8723->curPsTdma == 4) {
7705 btdm_2AntPsTdma(padapter, true, 8);
7706 pBtdm8723->psTdmaDuAdjType = 8;
7708 if (pBtdm8723->curPsTdma == 9) {
7709 btdm_2AntPsTdma(padapter, true, 15);
7710 pBtdm8723->psTdmaDuAdjType = 15;
7711 } else if (pBtdm8723->curPsTdma == 10) {
7712 btdm_2AntPsTdma(padapter, true, 15);
7713 pBtdm8723->psTdmaDuAdjType = 15;
7714 } else if (pBtdm8723->curPsTdma == 11) {
7715 btdm_2AntPsTdma(padapter, true, 15);
7716 pBtdm8723->psTdmaDuAdjType = 15;
7717 } else if (pBtdm8723->curPsTdma == 12) {
7718 btdm_2AntPsTdma(padapter, true, 16);
7719 pBtdm8723->psTdmaDuAdjType = 16;
7722 if (pBtdm8723->curPsTdma == 5) {
7723 btdm_2AntPsTdma(padapter, true, 7);
7724 pBtdm8723->psTdmaDuAdjType = 7;
7725 } else if (pBtdm8723->curPsTdma == 6) {
7726 btdm_2AntPsTdma(padapter, true, 7);
7727 pBtdm8723->psTdmaDuAdjType = 7;
7728 } else if (pBtdm8723->curPsTdma == 7) {
7729 btdm_2AntPsTdma(padapter, true, 8);
7730 pBtdm8723->psTdmaDuAdjType = 8;
7731 } else if (pBtdm8723->curPsTdma == 13) {
7732 btdm_2AntPsTdma(padapter, true, 15);
7733 pBtdm8723->psTdmaDuAdjType = 15;
7734 } else if (pBtdm8723->curPsTdma == 14) {
7735 btdm_2AntPsTdma(padapter, true, 15);
7736 pBtdm8723->psTdmaDuAdjType = 15;
7737 } else if (pBtdm8723->curPsTdma == 15) {
7738 btdm_2AntPsTdma(padapter, true, 16);
7739 pBtdm8723->psTdmaDuAdjType = 16;
7741 } else if (result == 1) {
7742 if (pBtdm8723->curPsTdma == 8) {
7743 btdm_2AntPsTdma(padapter, true, 7);
7744 pBtdm8723->psTdmaDuAdjType = 7;
7745 } else if (pBtdm8723->curPsTdma == 7) {
7746 btdm_2AntPsTdma(padapter, true, 7);
7747 pBtdm8723->psTdmaDuAdjType = 7;
7748 } else if (pBtdm8723->curPsTdma == 6) {
7749 btdm_2AntPsTdma(padapter, true, 7);
7750 pBtdm8723->psTdmaDuAdjType = 7;
7751 } else if (pBtdm8723->curPsTdma == 16) {
7752 btdm_2AntPsTdma(padapter, true, 15);
7753 pBtdm8723->psTdmaDuAdjType = 15;
7754 } else if (pBtdm8723->curPsTdma == 15) {
7755 btdm_2AntPsTdma(padapter, true, 15);
7756 pBtdm8723->psTdmaDuAdjType = 15;
7757 } else if (pBtdm8723->curPsTdma == 14) {
7758 btdm_2AntPsTdma(padapter, true, 15);
7759 pBtdm8723->psTdmaDuAdjType = 15;
7763 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7764 if (pBtdm8723->curPsTdma == 5) {
7765 btdm_2AntPsTdma(padapter, true, 3);
7766 pBtdm8723->psTdmaDuAdjType = 3;
7767 } else if (pBtdm8723->curPsTdma == 6) {
7768 btdm_2AntPsTdma(padapter, true, 3);
7769 pBtdm8723->psTdmaDuAdjType = 3;
7770 } else if (pBtdm8723->curPsTdma == 7) {
7771 btdm_2AntPsTdma(padapter, true, 3);
7772 pBtdm8723->psTdmaDuAdjType = 3;
7773 } else if (pBtdm8723->curPsTdma == 8) {
7774 btdm_2AntPsTdma(padapter, true, 4);
7775 pBtdm8723->psTdmaDuAdjType = 4;
7777 if (pBtdm8723->curPsTdma == 13) {
7778 btdm_2AntPsTdma(padapter, true, 11);
7779 pBtdm8723->psTdmaDuAdjType = 11;
7780 } else if (pBtdm8723->curPsTdma == 14) {
7781 btdm_2AntPsTdma(padapter, true, 11);
7782 pBtdm8723->psTdmaDuAdjType = 11;
7783 } else if (pBtdm8723->curPsTdma == 15) {
7784 btdm_2AntPsTdma(padapter, true, 11);
7785 pBtdm8723->psTdmaDuAdjType = 11;
7786 } else if (pBtdm8723->curPsTdma == 16) {
7787 btdm_2AntPsTdma(padapter, true, 12);
7788 pBtdm8723->psTdmaDuAdjType = 12;
7791 if (pBtdm8723->curPsTdma == 1) {
7792 btdm_2AntPsTdma(padapter, true, 3);
7793 pBtdm8723->psTdmaDuAdjType = 3;
7794 } else if (pBtdm8723->curPsTdma == 2) {
7795 btdm_2AntPsTdma(padapter, true, 3);
7796 pBtdm8723->psTdmaDuAdjType = 3;
7797 } else if (pBtdm8723->curPsTdma == 3) {
7798 btdm_2AntPsTdma(padapter, true, 4);
7799 pBtdm8723->psTdmaDuAdjType = 4;
7800 } else if (pBtdm8723->curPsTdma == 9) {
7801 btdm_2AntPsTdma(padapter, true, 11);
7802 pBtdm8723->psTdmaDuAdjType = 11;
7803 } else if (pBtdm8723->curPsTdma == 10) {
7804 btdm_2AntPsTdma(padapter, true, 11);
7805 pBtdm8723->psTdmaDuAdjType = 11;
7806 } else if (pBtdm8723->curPsTdma == 11) {
7807 btdm_2AntPsTdma(padapter, true, 12);
7808 pBtdm8723->psTdmaDuAdjType = 12;
7810 } else if (result == 1) {
7811 if (pBtdm8723->curPsTdma == 4) {
7812 btdm_2AntPsTdma(padapter, true, 3);
7813 pBtdm8723->psTdmaDuAdjType = 3;
7814 } else if (pBtdm8723->curPsTdma == 3) {
7815 btdm_2AntPsTdma(padapter, true, 3);
7816 pBtdm8723->psTdmaDuAdjType = 3;
7817 } else if (pBtdm8723->curPsTdma == 2) {
7818 btdm_2AntPsTdma(padapter, true, 3);
7819 pBtdm8723->psTdmaDuAdjType = 3;
7820 } else if (pBtdm8723->curPsTdma == 12) {
7821 btdm_2AntPsTdma(padapter, true, 11);
7822 pBtdm8723->psTdmaDuAdjType = 11;
7823 } else if (pBtdm8723->curPsTdma == 11) {
7824 btdm_2AntPsTdma(padapter, true, 11);
7825 pBtdm8723->psTdmaDuAdjType = 11;
7826 } else if (pBtdm8723->curPsTdma == 10) {
7827 btdm_2AntPsTdma(padapter, true, 11);
7828 pBtdm8723->psTdmaDuAdjType = 11;
7834 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type : recordPsTdma =%d\n", pBtdm8723->psTdmaDuAdjType));
7835 /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
7836 /* then we have to adjust it back to the previous record one. */
7837 if (pBtdm8723->curPsTdma != pBtdm8723->psTdmaDuAdjType) {
7838 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma =%d, recordPsTdma =%d\n",
7839 pBtdm8723->curPsTdma, pBtdm8723->psTdmaDuAdjType));
7841 if (!check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
7842 btdm_2AntPsTdma(padapter, true, pBtdm8723->psTdmaDuAdjType);
7844 RTPRINT(FBT, BT_TRACE, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
7848 /* default Action */
7849 /* SCO only or SCO+PAN(HS) */
7850 static void btdm_2Ant8723ASCOAction(struct rtw_adapter *padapter)
7852 u8 btRssiState, btRssiState1;
7854 if (btdm_NeedToDecBtPwr(padapter))
7855 btdm_2AntDecBtPwr(padapter, true);
7857 btdm_2AntDecBtPwr(padapter, false);
7859 if (BTDM_IsHT40(padapter)) {
7860 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7861 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7863 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7864 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7865 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7866 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7867 btdm_2AntPsTdma(padapter, true, 11);
7869 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7870 btdm_2AntPsTdma(padapter, true, 15);
7874 btdm_2AntAgcTable(padapter, false);
7875 btdm_2AntAdcBackOff(padapter, true);
7876 btdm_2AntDacSwing(padapter, false, 0xc0);
7878 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7879 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7880 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7883 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7884 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7885 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7886 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7887 btdm_2AntPsTdma(padapter, true, 11);
7889 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7890 btdm_2AntPsTdma(padapter, true, 15);
7894 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7895 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7896 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7897 btdm_2AntAgcTable(padapter, true);
7898 btdm_2AntAdcBackOff(padapter, true);
7899 btdm_2AntDacSwing(padapter, false, 0xc0);
7901 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7902 btdm_2AntAgcTable(padapter, false);
7903 btdm_2AntAdcBackOff(padapter, false);
7904 btdm_2AntDacSwing(padapter, false, 0xc0);
7909 static void btdm_2Ant8723AHIDAction(struct rtw_adapter *padapter)
7911 u8 btRssiState, btRssiState1;
7913 if (btdm_NeedToDecBtPwr(padapter))
7914 btdm_2AntDecBtPwr(padapter, true);
7916 btdm_2AntDecBtPwr(padapter, false);
7918 if (BTDM_IsHT40(padapter)) {
7919 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7920 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7922 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7923 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7924 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7925 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7926 btdm_2AntPsTdma(padapter, true, 9);
7928 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7929 btdm_2AntPsTdma(padapter, true, 13);
7933 btdm_2AntAgcTable(padapter, false);
7934 btdm_2AntAdcBackOff(padapter, false);
7935 btdm_2AntDacSwing(padapter, false, 0xc0);
7937 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7938 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7939 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7942 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7943 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7944 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7945 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7946 btdm_2AntPsTdma(padapter, true, 9);
7948 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7949 btdm_2AntPsTdma(padapter, true, 13);
7953 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7954 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7955 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7956 btdm_2AntAgcTable(padapter, true);
7957 btdm_2AntAdcBackOff(padapter, true);
7958 btdm_2AntDacSwing(padapter, false, 0xc0);
7960 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7961 btdm_2AntAgcTable(padapter, false);
7962 btdm_2AntAdcBackOff(padapter, false);
7963 btdm_2AntDacSwing(padapter, false, 0xc0);
7968 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
7969 static void btdm_2Ant8723AA2DPAction(struct rtw_adapter *padapter)
7971 u8 btRssiState, btRssiState1;
7972 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7973 u8 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
7975 if (btdm_NeedToDecBtPwr(padapter))
7976 btdm_2AntDecBtPwr(padapter, true);
7978 btdm_2AntDecBtPwr(padapter, false);
7980 if (BTDM_IsHT40(padapter)) {
7981 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7982 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7985 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7986 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7987 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7988 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7990 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7991 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7992 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
7994 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7995 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
7998 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7999 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8000 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8001 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
8003 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8004 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8009 btdm_2AntAgcTable(padapter, false);
8010 btdm_2AntAdcBackOff(padapter, true);
8011 btdm_2AntDacSwing(padapter, false, 0xc0);
8013 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8014 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8015 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8018 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8019 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8020 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8021 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8022 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8023 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8024 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
8026 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8027 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8030 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8031 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8032 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8033 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
8035 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8036 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8041 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8042 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8043 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8044 btdm_2AntAgcTable(padapter, true);
8045 btdm_2AntAdcBackOff(padapter, true);
8046 btdm_2AntDacSwing(padapter, false, 0xc0);
8048 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8049 btdm_2AntAgcTable(padapter, false);
8050 btdm_2AntAdcBackOff(padapter, false);
8051 btdm_2AntDacSwing(padapter, false, 0xc0);
8056 static void btdm_2Ant8723APANEDRAction(struct rtw_adapter *padapter)
8058 u8 btRssiState, btRssiState1;
8060 if (btdm_NeedToDecBtPwr(padapter))
8061 btdm_2AntDecBtPwr(padapter, true);
8063 btdm_2AntDecBtPwr(padapter, false);
8065 if (BTDM_IsHT40(padapter)) {
8066 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8067 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8070 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8071 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8072 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8073 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8074 btdm_2AntPsTdma(padapter, true, 2);
8076 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8077 btdm_2AntPsTdma(padapter, true, 6);
8081 btdm_2AntAgcTable(padapter, false);
8082 btdm_2AntAdcBackOff(padapter, true);
8083 btdm_2AntDacSwing(padapter, false, 0xc0);
8085 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8086 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8087 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8090 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8091 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8092 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8093 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8094 btdm_2AntPsTdma(padapter, true, 2);
8096 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8097 btdm_2AntPsTdma(padapter, true, 6);
8101 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8102 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8103 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8104 btdm_2AntAgcTable(padapter, true);
8105 btdm_2AntAdcBackOff(padapter, true);
8106 btdm_2AntDacSwing(padapter, false, 0xc0);
8108 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8109 btdm_2AntAgcTable(padapter, false);
8110 btdm_2AntAdcBackOff(padapter, false);
8111 btdm_2AntDacSwing(padapter, false, 0xc0);
8117 static void btdm_2Ant8723APANHSAction(struct rtw_adapter *padapter)
8121 if (BTDM_IsHT40(padapter)) {
8122 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8123 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8125 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8126 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8127 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8128 btdm_2AntDecBtPwr(padapter, true);
8130 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8131 btdm_2AntDecBtPwr(padapter, false);
8133 btdm_2AntPsTdma(padapter, false, 0);
8136 btdm_2AntAgcTable(padapter, false);
8137 btdm_2AntAdcBackOff(padapter, true);
8138 btdm_2AntDacSwing(padapter, false, 0xc0);
8140 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8141 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8143 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8144 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8145 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high\n"));
8147 btdm_2AntDecBtPwr(padapter, true);
8148 btdm_2AntPsTdma(padapter, false, 0);
8151 btdm_2AntAgcTable(padapter, true);
8152 btdm_2AntAdcBackOff(padapter, true);
8153 btdm_2AntDacSwing(padapter, false, 0xc0);
8155 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low\n"));
8157 btdm_2AntDecBtPwr(padapter, false);
8158 btdm_2AntPsTdma(padapter, false, 0);
8161 btdm_2AntAgcTable(padapter, false);
8162 btdm_2AntAdcBackOff(padapter, false);
8163 btdm_2AntDacSwing(padapter, false, 0xc0);
8169 static void btdm_2Ant8723APANEDRA2DPAction(struct rtw_adapter *padapter)
8171 u8 btRssiState, btRssiState1, btInfoExt;
8172 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8174 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8176 if (btdm_NeedToDecBtPwr(padapter))
8177 btdm_2AntDecBtPwr(padapter, true);
8179 btdm_2AntDecBtPwr(padapter, false);
8181 if (BTDM_IsHT40(padapter)) {
8182 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8183 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8185 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8186 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8187 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8189 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8191 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8192 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8193 btdm_2AntPsTdma(padapter, true, 4);
8195 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8196 btdm_2AntPsTdma(padapter, true, 2);
8199 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8201 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8202 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8203 btdm_2AntPsTdma(padapter, true, 8);
8205 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8206 btdm_2AntPsTdma(padapter, true, 6);
8211 btdm_2AntAgcTable(padapter, false);
8212 btdm_2AntAdcBackOff(padapter, true);
8213 btdm_2AntDacSwing(padapter, false, 0xc0);
8215 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8216 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8217 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8219 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8220 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8221 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8222 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8224 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8225 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8226 btdm_2AntPsTdma(padapter, true, 4);
8228 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8229 btdm_2AntPsTdma(padapter, true, 2);
8232 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8234 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8235 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8236 btdm_2AntPsTdma(padapter, true, 8);
8238 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8239 btdm_2AntPsTdma(padapter, true, 6);
8244 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8245 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8246 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8247 btdm_2AntAgcTable(padapter, true);
8248 btdm_2AntAdcBackOff(padapter, true);
8249 btdm_2AntDacSwing(padapter, false, 0xc0);
8251 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8252 btdm_2AntAgcTable(padapter, false);
8253 btdm_2AntAdcBackOff(padapter, false);
8254 btdm_2AntDacSwing(padapter, false, 0xc0);
8259 static void btdm_2Ant8723APANEDRHIDAction(struct rtw_adapter *padapter)
8261 u8 btRssiState, btRssiState1;
8263 if (btdm_NeedToDecBtPwr(padapter))
8264 btdm_2AntDecBtPwr(padapter, true);
8266 btdm_2AntDecBtPwr(padapter, false);
8268 if (BTDM_IsHT40(padapter)) {
8269 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8270 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8272 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8273 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8274 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8275 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8276 btdm_2AntPsTdma(padapter, true, 10);
8278 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8279 btdm_2AntPsTdma(padapter, true, 14);
8283 btdm_2AntAgcTable(padapter, false);
8284 btdm_2AntAdcBackOff(padapter, true);
8285 btdm_2AntDacSwing(padapter, false, 0xc0);
8287 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8288 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8289 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8292 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8293 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8294 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8295 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8296 btdm_2AntPsTdma(padapter, true, 10);
8298 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8299 btdm_2AntPsTdma(padapter, true, 14);
8303 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8304 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8305 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8306 btdm_2AntAgcTable(padapter, true);
8307 btdm_2AntAdcBackOff(padapter, true);
8308 btdm_2AntDacSwing(padapter, false, 0xc0);
8310 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8311 btdm_2AntAgcTable(padapter, false);
8312 btdm_2AntAdcBackOff(padapter, false);
8313 btdm_2AntDacSwing(padapter, false, 0xc0);
8318 /* HID+A2DP+PAN(EDR) */
8319 static void btdm_2Ant8723AHIDA2DPPANEDRAction(struct rtw_adapter *padapter)
8321 u8 btRssiState, btRssiState1, btInfoExt;
8322 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8324 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8326 if (btdm_NeedToDecBtPwr(padapter))
8327 btdm_2AntDecBtPwr(padapter, true);
8329 btdm_2AntDecBtPwr(padapter, false);
8331 if (BTDM_IsHT40(padapter)) {
8332 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8333 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8334 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8335 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8336 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8337 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8339 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8340 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8341 btdm_2AntPsTdma(padapter, true, 12);
8343 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8344 btdm_2AntPsTdma(padapter, true, 10);
8347 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8348 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8349 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8350 btdm_2AntPsTdma(padapter, true, 16);
8352 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8353 btdm_2AntPsTdma(padapter, true, 14);
8358 btdm_2AntAgcTable(padapter, false);
8359 btdm_2AntAdcBackOff(padapter, true);
8360 btdm_2AntDacSwing(padapter, false, 0xc0);
8362 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8363 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 37, 0);
8364 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8365 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8366 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8367 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8368 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8370 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8371 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8372 btdm_2AntPsTdma(padapter, true, 12);
8374 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8375 btdm_2AntPsTdma(padapter, true, 10);
8378 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8379 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8380 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8381 btdm_2AntPsTdma(padapter, true, 16);
8383 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8384 btdm_2AntPsTdma(padapter, true, 14);
8389 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8390 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8391 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8392 btdm_2AntAgcTable(padapter, true);
8393 btdm_2AntAdcBackOff(padapter, true);
8394 btdm_2AntDacSwing(padapter, false, 0xc0);
8396 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8397 btdm_2AntAgcTable(padapter, false);
8398 btdm_2AntAdcBackOff(padapter, false);
8399 btdm_2AntDacSwing(padapter, false, 0xc0);
8404 static void btdm_2Ant8723AHIDA2DPAction(struct rtw_adapter *padapter)
8406 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8407 u8 btRssiState, btRssiState1, btInfoExt;
8409 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8411 if (btdm_NeedToDecBtPwr(padapter))
8412 btdm_2AntDecBtPwr(padapter, true);
8414 btdm_2AntDecBtPwr(padapter, false);
8416 if (BTDM_IsHT40(padapter)) {
8417 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8418 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8419 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8420 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8421 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8422 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8424 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8425 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8426 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8428 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8429 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8432 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8433 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8434 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8435 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8437 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8438 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8442 btdm_2AntAgcTable(padapter, false);
8443 btdm_2AntAdcBackOff(padapter, true);
8444 btdm_2AntDacSwing(padapter, false, 0xc0);
8446 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8447 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8448 btRssiState1 = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8450 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8451 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8452 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8453 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8455 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8456 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8457 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8459 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8460 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8463 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8464 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8465 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8466 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8468 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8469 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8472 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8473 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8474 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8476 btdm_2AntAgcTable(padapter, true);
8477 btdm_2AntAdcBackOff(padapter, true);
8478 btdm_2AntDacSwing(padapter, false, 0xc0);
8480 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8482 btdm_2AntAgcTable(padapter, false);
8483 btdm_2AntAdcBackOff(padapter, false);
8484 btdm_2AntDacSwing(padapter, false, 0xc0);
8489 static void btdm_2Ant8723AA2dp(struct rtw_adapter *padapter)
8491 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8492 u8 btRssiState, btRssiState1, btInfoExt;
8494 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8496 if (btdm_NeedToDecBtPwr(padapter))
8497 btdm_2AntDecBtPwr(padapter, true);
8499 btdm_2AntDecBtPwr(padapter, false);
8501 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8502 btdm_2AntIgnoreWlanAct(padapter, false);
8504 if (BTDM_IsHT40(padapter)) {
8505 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8506 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8508 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8509 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8510 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8511 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8512 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8514 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8515 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8519 btdm_2AntAgcTable(padapter, false);
8520 btdm_2AntAdcBackOff(padapter, true);
8521 btdm_2AntDacSwing(padapter, false, 0xc0);
8523 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8524 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8525 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8528 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8529 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8530 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8531 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8532 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8534 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8535 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8539 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8540 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8541 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8542 btdm_2AntAgcTable(padapter, true);
8543 btdm_2AntAdcBackOff(padapter, true);
8544 btdm_2AntDacSwing(padapter, false, 0xc0);
8546 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8547 btdm_2AntAgcTable(padapter, false);
8548 btdm_2AntAdcBackOff(padapter, false);
8549 btdm_2AntDacSwing(padapter, false, 0xc0);
8554 /* extern function start with BTDM_ */
8555 static void BTDM_2AntParaInit(struct rtw_adapter *padapter)
8558 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8559 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8561 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2Ant Parameter Init!!\n"));
8563 /* Enable counter statistics */
8564 rtl8723au_write8(padapter, 0x76e, 0x4);
8565 rtl8723au_write8(padapter, 0x778, 0x3);
8566 rtl8723au_write8(padapter, 0x40, 0x20);
8568 /* force to reset coex mechanism */
8569 pBtdm8723->preVal0x6c0 = 0x0;
8570 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8572 pBtdm8723->bPrePsTdmaOn = true;
8573 btdm_2AntPsTdma(padapter, false, 0);
8575 pBtdm8723->preFwDacSwingLvl = 0x10;
8576 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8578 pBtdm8723->bPreDecBtPwr = true;
8579 btdm_2AntDecBtPwr(padapter, false);
8581 pBtdm8723->bPreAgcTableEn = true;
8582 btdm_2AntAgcTable(padapter, false);
8584 pBtdm8723->bPreAdcBackOff = true;
8585 btdm_2AntAdcBackOff(padapter, false);
8587 pBtdm8723->bPreLowPenaltyRa = true;
8588 btdm_2AntLowPenaltyRa(padapter, false);
8590 pBtdm8723->bPreRfRxLpfShrink = true;
8591 btdm_2AntRfShrink(padapter, false);
8593 pBtdm8723->bPreDacSwingOn = true;
8594 btdm_2AntDacSwing(padapter, false, 0xc0);
8596 pBtdm8723->bPreIgnoreWlanAct = true;
8597 btdm_2AntIgnoreWlanAct(padapter, false);
8600 static void BTDM_2AntHwCoexAllOff8723A(struct rtw_adapter *padapter)
8602 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8605 static void BTDM_2AntFwCoexAllOff8723A(struct rtw_adapter *padapter)
8607 btdm_2AntIgnoreWlanAct(padapter, false);
8608 btdm_2AntPsTdma(padapter, false, 0);
8609 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8610 btdm_2AntDecBtPwr(padapter, false);
8613 static void BTDM_2AntSwCoexAllOff8723A(struct rtw_adapter *padapter)
8615 btdm_2AntAgcTable(padapter, false);
8616 btdm_2AntAdcBackOff(padapter, false);
8617 btdm_2AntLowPenaltyRa(padapter, false);
8618 btdm_2AntRfShrink(padapter, false);
8619 btdm_2AntDacSwing(padapter, false, 0xc0);
8622 static void BTDM_2AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
8624 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8625 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8626 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8627 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8629 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
8630 u8 bBtLinkExist = false, bBtHsModeExist = false;
8632 btInfo = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8633 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8635 /* check BIT2 first ==> check if bt is under inquiry or page scan */
8636 if (btInfo & BIT(2)) {
8637 if (!pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
8638 pBtMgnt->ExtConfig.bHoldForBtOperation = true;
8639 pBtMgnt->ExtConfig.bHoldPeriodCnt = 1;
8640 btdm_2AntBtInquiryPage(padapter);
8642 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8643 btdm_HoldForBtInqPage(padapter);
8645 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = true;
8648 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = false;
8649 pBtMgnt->ExtConfig.bHoldForBtOperation = false;
8650 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8653 RTPRINT(FBT, BT_TRACE,
8654 ("[BTC2H], pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage =%x pBtMgnt->ExtConfig.bHoldPeriodCnt =%x pBtMgnt->ExtConfig.bHoldForBtOperation =%x\n",
8655 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage,
8656 pBtMgnt->ExtConfig.bHoldPeriodCnt,
8657 pBtMgnt->ExtConfig.bHoldForBtOperation));
8659 RTPRINT(FBT, BT_TRACE,
8660 ("[BTC2H], btInfo =%x pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal =%x\n",
8661 btInfo, pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal));
8662 if (btInfo&BT_INFO_ACL) {
8663 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = true btInfo =%x\n", btInfo));
8664 bBtLinkExist = true;
8665 if (((btInfo&(BT_INFO_FTP|BT_INFO_A2DP|BT_INFO_HID|BT_INFO_SCO_BUSY)) != 0) ||
8666 pHalData->bt_coexist.halCoex8723.btRetryCnt > 0) {
8667 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
8669 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
8672 if (btInfo&BT_INFO_SCO || btInfo&BT_INFO_SCO_BUSY) {
8673 if (btInfo&BT_INFO_FTP || btInfo&BT_INFO_A2DP || btInfo&BT_INFO_HID) {
8674 switch (btInfo&0xe0) {
8676 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
8677 algorithm = BT_2ANT_COEX_ALGO_HID;
8680 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
8683 if (bBtHsModeExist) {
8684 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
8685 algorithm = BT_2ANT_COEX_ALGO_SCO;
8687 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
8688 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8691 case (BT_INFO_HID | BT_INFO_A2DP):
8692 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8693 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8695 case (BT_INFO_HID | BT_INFO_FTP):
8696 if (bBtHsModeExist) {
8697 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8698 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8700 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8701 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8704 case (BT_INFO_A2DP | BT_INFO_FTP):
8705 if (bBtHsModeExist) {
8706 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8707 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8709 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8710 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8713 case (BT_INFO_HID | BT_INFO_A2DP | BT_INFO_FTP):
8714 if (bBtHsModeExist) {
8715 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8716 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8718 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8719 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8724 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
8725 algorithm = BT_2ANT_COEX_ALGO_SCO;
8728 RTPRINT(FBT, BT_TRACE, ("[BTCoex], non SCO\n"));
8729 switch (btInfo&0xe0) {
8731 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID\n"));
8732 algorithm = BT_2ANT_COEX_ALGO_HID;
8735 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP\n"));
8736 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8739 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR)\n"));
8740 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8742 case (BT_INFO_HID | BT_INFO_A2DP):
8743 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8744 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8746 case (BT_INFO_HID|BT_INFO_FTP):
8747 if (bBtHsModeExist) {
8748 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8749 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8751 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8752 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8755 case (BT_INFO_A2DP|BT_INFO_FTP):
8756 if (bBtHsModeExist) {
8757 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8758 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8760 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8761 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8764 case (BT_INFO_HID|BT_INFO_A2DP|BT_INFO_FTP):
8765 if (bBtHsModeExist) {
8766 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8767 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8769 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8770 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8777 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = false\n"));
8778 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8781 pBtdm8723->curAlgorithm = algorithm;
8782 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8785 BTDM_CheckWiFiState(padapter);
8786 if (pBtMgnt->ExtConfig.bManualControl) {
8787 RTPRINT(FBT, BT_TRACE, ("Action Manual control, won't execute bt coexist mechanism!!\n"));
8792 void BTDM_2AntBtCoexist8723A(struct rtw_adapter *padapter)
8794 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8795 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8796 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
8797 u8 btInfoOriginal = 0;
8798 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8799 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8801 if (BTDM_BtProfileSupport(padapter)) {
8802 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8803 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8806 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8807 RTPRINT(FBT, BT_TRACE, ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8808 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8809 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8810 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8811 /* next time the coexist parameters should be reset again. */
8813 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8818 if (pBtDbg->dbgCtrl)
8819 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8821 pBtdm8723->curAlgorithm = btdm_ActionAlgorithm(padapter);
8822 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8824 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8825 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8826 pBtdm8723->bResetTdmaAdjust = true;
8828 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8829 RTPRINT(FBT, BT_TRACE, ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8830 pBtdm8723->preAlgorithm, pBtdm8723->curAlgorithm));
8831 pBtdm8723->bResetTdmaAdjust = true;
8833 switch (pBtdm8723->curAlgorithm) {
8834 case BT_2ANT_COEX_ALGO_SCO:
8835 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8836 btdm_2Ant8723ASCOAction(padapter);
8838 case BT_2ANT_COEX_ALGO_HID:
8839 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8840 btdm_2Ant8723AHIDAction(padapter);
8842 case BT_2ANT_COEX_ALGO_A2DP:
8843 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8844 btdm_2Ant8723AA2DPAction(padapter);
8846 case BT_2ANT_COEX_ALGO_PANEDR:
8847 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8848 btdm_2Ant8723APANEDRAction(padapter);
8850 case BT_2ANT_COEX_ALGO_PANHS:
8851 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8852 btdm_2Ant8723APANHSAction(padapter);
8854 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8855 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8856 btdm_2Ant8723APANEDRA2DPAction(padapter);
8858 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8859 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8860 btdm_2Ant8723APANEDRHIDAction(padapter);
8862 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8863 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8864 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8866 case BT_2ANT_COEX_ALGO_HID_A2DP:
8867 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8868 btdm_2Ant8723AHIDA2DPAction(padapter);
8871 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8872 btdm_2Ant8723AA2DPAction(padapter);
8875 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8878 RTPRINT(FBT, BT_TRACE, ("[BTCoex] Get bt info by fw!!\n"));
8879 /* msg shows c2h rsp for bt_info is received or not. */
8880 if (pHalData->bt_coexist.halCoex8723.bC2hBtInfoReqSent)
8881 RTPRINT(FBT, BT_TRACE, ("[BTCoex] c2h for btInfo not rcvd yet!!\n"));
8883 btInfoOriginal = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8885 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8886 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8889 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8890 RTPRINT(FBT, BT_TRACE,
8891 ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8892 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8893 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8894 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8895 /* next time the coexist parameters should be reset again. */
8897 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8902 if (pBtDbg->dbgCtrl)
8903 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8904 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8905 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8906 pBtdm8723->bResetTdmaAdjust = true;
8908 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8909 RTPRINT(FBT, BT_TRACE,
8910 ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8911 pBtdm8723->preAlgorithm,
8912 pBtdm8723->curAlgorithm));
8913 pBtdm8723->bResetTdmaAdjust = true;
8915 switch (pBtdm8723->curAlgorithm) {
8916 case BT_2ANT_COEX_ALGO_SCO:
8917 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8918 btdm_2Ant8723ASCOAction(padapter);
8920 case BT_2ANT_COEX_ALGO_HID:
8921 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8922 btdm_2Ant8723AHIDAction(padapter);
8924 case BT_2ANT_COEX_ALGO_A2DP:
8925 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8926 btdm_2Ant8723AA2dp(padapter);
8928 case BT_2ANT_COEX_ALGO_PANEDR:
8929 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8930 btdm_2Ant8723APANEDRAction(padapter);
8932 case BT_2ANT_COEX_ALGO_PANHS:
8933 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8934 btdm_2Ant8723APANHSAction(padapter);
8936 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8937 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8938 btdm_2Ant8723APANEDRA2DPAction(padapter);
8940 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8941 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8942 btdm_2Ant8723APANEDRHIDAction(padapter);
8944 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8945 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8946 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8948 case BT_2ANT_COEX_ALGO_HID_A2DP:
8949 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8950 btdm_2Ant8723AHIDA2DPAction(padapter);
8953 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8954 btdm_2Ant8723AA2DPAction(padapter);
8957 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8962 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
8964 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
8966 static u8 btCoexDbgBuf[BT_TMP_BUF_SIZE];
8968 static const char *const BtProfileString[] = {
8976 static const char *const BtSpecString[] = {
8986 static const char *const BtLinkRoleString[] = {
8991 static u8 btdm_BtWifiAntNum(struct rtw_adapter *padapter)
8993 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8994 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
8996 if (Ant_x2 == pHalData->bt_coexist.BT_Ant_Num) {
8997 if (Ant_x2 == pBtCoex->TotalAntNum)
9007 static void btdm_BtHwCountersMonitor(struct rtw_adapter *padapter)
9009 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9010 u32 regHPTxRx, regLPTxRx, u4Tmp;
9011 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
9013 regHPTxRx = REG_HIGH_PRIORITY_TXRX;
9014 regLPTxRx = REG_LOW_PRIORITY_TXRX;
9016 u4Tmp = rtl8723au_read32(padapter, regHPTxRx);
9017 regHPTx = u4Tmp & bMaskLWord;
9018 regHPRx = (u4Tmp & bMaskHWord)>>16;
9020 u4Tmp = rtl8723au_read32(padapter, regLPTxRx);
9021 regLPTx = u4Tmp & bMaskLWord;
9022 regLPRx = (u4Tmp & bMaskHWord)>>16;
9024 pHalData->bt_coexist.halCoex8723.highPriorityTx = regHPTx;
9025 pHalData->bt_coexist.halCoex8723.highPriorityRx = regHPRx;
9026 pHalData->bt_coexist.halCoex8723.lowPriorityTx = regLPTx;
9027 pHalData->bt_coexist.halCoex8723.lowPriorityRx = regLPRx;
9029 RTPRINT(FBT, BT_TRACE, ("High Priority Tx/Rx = %d / %d\n", regHPTx, regHPRx));
9030 RTPRINT(FBT, BT_TRACE, ("Low Priority Tx/Rx = %d / %d\n", regLPTx, regLPRx));
9033 rtl8723au_write8(padapter, 0x76e, 0xc);
9036 /* This function check if 8723 bt is disabled */
9037 static void btdm_BtEnableDisableCheck8723A(struct rtw_adapter *padapter)
9040 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9042 #ifdef CHECK_BT_EXIST_FROM_REG
9045 /* ox68[28]= 1 => BT enable; otherwise disable */
9046 val8 = rtl8723au_read8(padapter, 0x6B);
9047 if (!(val8 & BIT(4)))
9051 pHalData->bt_coexist.bCurBtDisabled = false;
9053 pHalData->bt_coexist.bCurBtDisabled = true;
9055 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0 &&
9056 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0 &&
9057 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0 &&
9058 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0)
9060 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xeaea &&
9061 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xeaea &&
9062 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xeaea &&
9063 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xeaea)
9065 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xffff &&
9066 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xffff &&
9067 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xffff &&
9068 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xffff)
9071 pHalData->bt_coexist.btActiveZeroCnt = 0;
9072 pHalData->bt_coexist.bCurBtDisabled = false;
9073 RTPRINT(FBT, BT_TRACE, ("8723A BT is enabled !!\n"));
9075 pHalData->bt_coexist.btActiveZeroCnt++;
9076 RTPRINT(FBT, BT_TRACE, ("8723A bt all counters = 0, %d times!!\n",
9077 pHalData->bt_coexist.btActiveZeroCnt));
9078 if (pHalData->bt_coexist.btActiveZeroCnt >= 2) {
9079 pHalData->bt_coexist.bCurBtDisabled = true;
9080 RTPRINT(FBT, BT_TRACE, ("8723A BT is disabled !!\n"));
9085 if (!pHalData->bt_coexist.bCurBtDisabled) {
9086 if (BTDM_IsWifiConnectionExist(padapter))
9087 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
9089 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_DISCONNECT);
9092 if (pHalData->bt_coexist.bPreBtDisabled !=
9093 pHalData->bt_coexist.bCurBtDisabled) {
9094 RTPRINT(FBT, BT_TRACE, ("8723A BT is from %s to %s!!\n",
9095 (pHalData->bt_coexist.bPreBtDisabled ? "disabled":"enabled"),
9096 (pHalData->bt_coexist.bCurBtDisabled ? "disabled":"enabled")));
9097 pHalData->bt_coexist.bPreBtDisabled = pHalData->bt_coexist.bCurBtDisabled;
9101 static void btdm_BTCoexist8723AHandler(struct rtw_adapter *padapter)
9103 struct hal_data_8723a *pHalData;
9105 pHalData = GET_HAL_DATA(padapter);
9107 if (btdm_BtWifiAntNum(padapter) == Ant_x2) {
9108 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2 Ant mechanism\n"));
9109 BTDM_2AntBtCoexist8723A(padapter);
9111 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1 Ant mechanism\n"));
9112 BTDM_1AntBtCoexist8723A(padapter);
9115 if (!BTDM_IsSameCoexistState(padapter)) {
9116 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x\n",
9117 pHalData->bt_coexist.PreviousState,
9118 pHalData->bt_coexist.CurrentState));
9119 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
9121 RTPRINT(FBT, BT_TRACE, ("["));
9122 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT30)
9123 RTPRINT(FBT, BT_TRACE, ("BT 3.0, "));
9124 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT20)
9125 RTPRINT(FBT, BT_TRACE, ("HT20, "));
9126 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT40)
9127 RTPRINT(FBT, BT_TRACE, ("HT40, "));
9128 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_LEGACY)
9129 RTPRINT(FBT, BT_TRACE, ("Legacy, "));
9130 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_LOW)
9131 RTPRINT(FBT, BT_TRACE, ("Rssi_Low, "));
9132 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_MEDIUM)
9133 RTPRINT(FBT, BT_TRACE, ("Rssi_Mid, "));
9134 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_HIGH)
9135 RTPRINT(FBT, BT_TRACE, ("Rssi_High, "));
9136 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_IDLE)
9137 RTPRINT(FBT, BT_TRACE, ("Wifi_Idle, "));
9138 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_UPLINK)
9139 RTPRINT(FBT, BT_TRACE, ("Wifi_Uplink, "));
9140 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_DOWNLINK)
9141 RTPRINT(FBT, BT_TRACE, ("Wifi_Downlink, "));
9142 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)
9143 RTPRINT(FBT, BT_TRACE, ("BT_idle, "));
9144 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_HID)
9145 RTPRINT(FBT, BT_TRACE, ("PRO_HID, "));
9146 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_A2DP)
9147 RTPRINT(FBT, BT_TRACE, ("PRO_A2DP, "));
9148 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_PAN)
9149 RTPRINT(FBT, BT_TRACE, ("PRO_PAN, "));
9150 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_SCO)
9151 RTPRINT(FBT, BT_TRACE, ("PRO_SCO, "));
9152 RTPRINT(FBT, BT_TRACE, ("]\n"));
9156 /* extern function start with BTDM_ */
9157 u32 BTDM_BtTxRxCounterH(struct rtw_adapter *padapter)
9159 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9162 counters = pHalData->bt_coexist.halCoex8723.highPriorityTx+
9163 pHalData->bt_coexist.halCoex8723.highPriorityRx;
9167 u32 BTDM_BtTxRxCounterL(struct rtw_adapter *padapter)
9169 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9172 counters = pHalData->bt_coexist.halCoex8723.lowPriorityTx+
9173 pHalData->bt_coexist.halCoex8723.lowPriorityRx ;
9177 void BTDM_SetFwChnlInfo(struct rtw_adapter *padapter, enum rt_media_status mstatus)
9179 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9180 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9181 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9182 u8 H2C_Parameter[3] = {0};
9186 if (RT_MEDIA_CONNECT == mstatus)
9187 H2C_Parameter[0] = 0x1; /* 0: disconnected, 1:connected */
9189 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) {
9191 chnl = pmlmeext->cur_channel;
9192 if (BTDM_IsHT40(padapter)) {
9193 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
9195 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
9198 H2C_Parameter[1] = chnl;
9199 } else { /* check if HS link is exists */
9201 if (BT_Operation(padapter))
9202 H2C_Parameter[1] = pBtMgnt->BTChannel;
9204 H2C_Parameter[1] = pmlmeext->cur_channel;
9207 if (BTDM_IsHT40(padapter))
9208 H2C_Parameter[2] = 0x30;
9210 H2C_Parameter[2] = 0x20;
9212 FillH2CCmd(padapter, 0x19, 3, H2C_Parameter);
9215 u8 BTDM_IsWifiConnectionExist(struct rtw_adapter *padapter)
9219 if (BTHCI_HsConnectionEstablished(padapter))
9222 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true)
9229 struct rtw_adapter *padapter,
9237 u8 H2C_Parameter[5] = {0};
9239 if (rtl8723a_BT_using_antenna_1(padapter)) {
9240 if ((!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
9241 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
9242 /* for softap mode */
9243 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9244 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9245 u8 BtState = pBtCoex->c2hBtInfo;
9247 if ((BtState != BT_INFO_STATE_NO_CONNECTION) &&
9248 (BtState != BT_INFO_STATE_CONNECT_IDLE)) {
9249 if (byte1 & BIT(4)) {
9261 H2C_Parameter[0] = byte1;
9262 H2C_Parameter[1] = byte2;
9263 H2C_Parameter[2] = byte3;
9264 H2C_Parameter[3] = byte4;
9265 H2C_Parameter[4] = byte5;
9267 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%02x%08x\n",
9269 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
9271 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
9274 void BTDM_QueryBtInformation(struct rtw_adapter *padapter)
9276 u8 H2C_Parameter[1] = {0};
9277 struct hal_data_8723a *pHalData;
9278 struct bt_coexist_8723a *pBtCoex;
9280 pHalData = GET_HAL_DATA(padapter);
9281 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9283 if (!rtl8723a_BT_enabled(padapter)) {
9284 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9285 pBtCoex->bC2hBtInfoReqSent = false;
9289 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9290 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9292 if (pBtCoex->bC2hBtInfoReqSent == true)
9293 RTPRINT(FBT, BT_TRACE, ("[BTCoex], didn't recv previous BtInfo report!\n"));
9295 pBtCoex->bC2hBtInfoReqSent = true;
9297 H2C_Parameter[0] |= BIT(0); /* trigger */
9299 /*RTPRINT(FBT, BT_TRACE, ("[BTCoex], Query Bt information, write 0x38 = 0x%x\n", */
9300 /*H2C_Parameter[0])); */
9302 FillH2CCmd(padapter, 0x38, 1, H2C_Parameter);
9305 void BTDM_SetSwRfRxLpfCorner(struct rtw_adapter *padapter, u8 type)
9307 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9309 if (BT_RF_RX_LPF_CORNER_SHRINK == type) {
9310 /* Shrink RF Rx LPF corner */
9311 RTPRINT(FBT, BT_TRACE, ("Shrink RF Rx LPF corner!!\n"));
9312 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, 0xf0ff7);
9313 pHalData->bt_coexist.bSWCoexistAllOff = false;
9314 } else if (BT_RF_RX_LPF_CORNER_RESUME == type) {
9315 /* Resume RF Rx LPF corner */
9316 RTPRINT(FBT, BT_TRACE, ("Resume RF Rx LPF corner!!\n"));
9317 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, pHalData->bt_coexist.BtRfRegOrigin1E);
9322 BTDM_SetSwPenaltyTxRateAdaptive(
9323 struct rtw_adapter *padapter,
9327 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9330 tmpU1 = rtl8723au_read8(padapter, 0x4fd);
9332 if (BT_TX_RATE_ADAPTIVE_LOW_PENALTY == raType) {
9334 pHalData->bt_coexist.bSWCoexistAllOff = false;
9335 } else if (BT_TX_RATE_ADAPTIVE_NORMAL == raType) {
9339 rtl8723au_write8(padapter, 0x4fd, tmpU1);
9342 void BTDM_SetFwDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
9344 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9345 u8 H2C_Parameter[1] = {0};
9347 H2C_Parameter[0] = 0;
9350 H2C_Parameter[0] |= BIT(1);
9351 pHalData->bt_coexist.bFWCoexistAllOff = false;
9354 RTPRINT(FBT, BT_TRACE, ("[BTCoex], decrease Bt Power : %s, write 0x21 = 0x%x\n",
9355 (bDecBtPwr ? "Yes!!" : "No!!"), H2C_Parameter[0]));
9357 FillH2CCmd(padapter, 0x21, 1, H2C_Parameter);
9360 u8 BTDM_BtProfileSupport(struct rtw_adapter *padapter)
9363 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9364 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9365 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9367 if (pBtMgnt->bSupportProfile &&
9368 !pHalData->bt_coexist.halCoex8723.bForceFwBtInfo)
9374 static void BTDM_AdjustForBtOperation8723A(struct rtw_adapter *padapter)
9376 /* BTDM_2AntAdjustForBtOperation8723(padapter); */
9379 static void BTDM_FwC2hBtRssi8723A(struct rtw_adapter *padapter, u8 *tmpBuf)
9381 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9382 u8 percent = 0, u1tmp = 0;
9385 percent = u1tmp*2+10;
9387 pHalData->bt_coexist.halCoex8723.btRssi = percent;
9388 /*RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", percent)); */
9392 rtl8723a_fw_c2h_BT_info(struct rtw_adapter *padapter, u8 *tmpBuf, u8 length)
9394 struct hal_data_8723a *pHalData;
9395 struct bt_30info *pBTInfo;
9396 struct bt_mgnt *pBtMgnt;
9397 struct bt_coexist_8723a *pBtCoex;
9400 pHalData = GET_HAL_DATA(padapter);
9401 pBTInfo = GET_BT_INFO(padapter);
9402 pBtMgnt = &pBTInfo->BtMgnt;
9403 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9405 pBtCoex->bC2hBtInfoReqSent = false;
9407 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT info[%d]=[", length));
9409 pBtCoex->btRetryCnt = 0;
9410 for (i = 0; i < length; i++) {
9413 pBtCoex->c2hBtInfoOriginal = tmpBuf[i];
9416 pBtCoex->btRetryCnt = tmpBuf[i];
9419 BTDM_FwC2hBtRssi8723A(padapter, &tmpBuf[i]);
9422 pBtCoex->btInfoExt = tmpBuf[i]&BIT(0);
9427 RTPRINT(FBT, BT_TRACE, ("0x%02x]\n", tmpBuf[i]));
9429 RTPRINT(FBT, BT_TRACE, ("0x%02x, ", tmpBuf[i]));
9431 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", pBtCoex->btRssi));
9432 if (pBtCoex->btInfoExt)
9433 RTPRINT(FBT, BT_TRACE, ("[BTC2H], pBtCoex->btInfoExt =%x\n", pBtCoex->btInfoExt));
9435 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9436 BTDM_1AntFwC2hBtInfo8723A(padapter);
9438 BTDM_2AntFwC2hBtInfo8723A(padapter);
9440 if (pBtMgnt->ExtConfig.bManualControl) {
9441 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9445 btdm_BTCoexist8723AHandler(padapter);
9448 static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
9450 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9451 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9452 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9453 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9454 u8 u1Tmp, u1Tmp1, u1Tmp2, i, btInfoExt, psTdmaCase = 0;
9458 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
9459 DCMD_Printf(btCoexDbgBuf);
9461 if (!rtl8723a_BT_coexist(padapter)) {
9462 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");
9463 DCMD_Printf(btCoexDbgBuf);
9467 antNum = btdm_BtWifiAntNum(padapter);
9468 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/%d ", "Ant mechanism PG/Now run :", \
9469 ((pHalData->bt_coexist.BT_Ant_Num == Ant_x2) ? 2 : 1), ((antNum == Ant_x2) ? 2 : 1));
9470 DCMD_Printf(btCoexDbgBuf);
9472 if (pBtMgnt->ExtConfig.bManualControl) {
9473 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
9474 DCMD_Printf(btCoexDbgBuf);
9476 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
9477 ((pBtMgnt->bSupportProfile) ? "Yes" : "No"), pBtMgnt->ExtConfig.HCIExtensionVer);
9478 DCMD_Printf(btCoexDbgBuf);
9481 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = / %d", "Dot11 channel / BT channel", \
9482 pBtMgnt->BTChannel);
9483 DCMD_Printf(btCoexDbgBuf);
9485 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %d / %d / %d", "Wifi/BT/HS rssi", \
9486 BTDM_GetRxSS(padapter),
9487 pHalData->bt_coexist.halCoex8723.btRssi,
9488 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB);
9489 DCMD_Printf(btCoexDbgBuf);
9491 if (!pBtMgnt->ExtConfig.bManualControl) {
9492 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %s / %s ", "WIfi status",
9493 ((BTDM_Legacy(padapter)) ? "Legacy" : (((BTDM_IsHT40(padapter)) ? "HT40" : "HT20"))),
9494 ((!BTDM_IsWifiBusy(padapter)) ? "idle" : ((BTDM_IsWifiUplink(padapter)) ? "uplink" : "downlink")));
9495 DCMD_Printf(btCoexDbgBuf);
9497 if (pBtMgnt->bSupportProfile) {
9498 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
9499 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_SCO)) ? 1 : 0),
9500 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) ? 1 : 0),
9501 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) ? 1 : 0),
9502 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) ? 1 : 0));
9503 DCMD_Printf(btCoexDbgBuf);
9505 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
9506 if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
9507 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role",
9508 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9509 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec],
9510 BtLinkRoleString[pBtMgnt->ExtConfig.linkInfo[i].linkRole]);
9511 DCMD_Printf(btCoexDbgBuf);
9513 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
9514 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "A2DP rate", \
9515 (btInfoExt & BIT(0)) ?
9516 "Basic rate" : "EDR rate");
9517 DCMD_Printf(btCoexDbgBuf);
9519 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
9520 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9521 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec]);
9522 DCMD_Printf(btCoexDbgBuf);
9529 if (!pBtMgnt->ExtConfig.bManualControl) {
9530 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw BT Coex mechanism]============");
9531 DCMD_Printf(btCoexDbgBuf);
9532 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "AGC Table", \
9533 pBtCoex->btdm2Ant.bCurAgcTableEn);
9534 DCMD_Printf(btCoexDbgBuf);
9535 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "ADC Backoff", \
9536 pBtCoex->btdm2Ant.bCurAdcBackOff);
9537 DCMD_Printf(btCoexDbgBuf);
9538 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Low penalty RA", \
9539 pBtCoex->btdm2Ant.bCurLowPenaltyRa);
9540 DCMD_Printf(btCoexDbgBuf);
9541 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "RF Rx LPF Shrink", \
9542 pBtCoex->btdm2Ant.bCurRfRxLpfShrink);
9543 DCMD_Printf(btCoexDbgBuf);
9545 u4Tmp[0] = PHY_QueryRFReg(padapter, PathA, 0x1e, 0xff0);
9546 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "RF-A, 0x1e[11:4]/original val", \
9547 u4Tmp[0], pHalData->bt_coexist.BtRfRegOrigin1E);
9548 DCMD_Printf(btCoexDbgBuf);
9551 if (!pBtMgnt->ExtConfig.bManualControl) {
9552 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw BT Coex mechanism]============");
9553 DCMD_Printf(btCoexDbgBuf);
9555 if (!pBtMgnt->ExtConfig.bManualControl) {
9556 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9557 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm1Ant.curPsTdma;
9559 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm2Ant.curPsTdma;
9560 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA(0x3a)", \
9561 pHalData->bt_coexist.fw3aVal[0], pHalData->bt_coexist.fw3aVal[1],
9562 pHalData->bt_coexist.fw3aVal[2], pHalData->bt_coexist.fw3aVal[3],
9563 pHalData->bt_coexist.fw3aVal[4], psTdmaCase);
9564 DCMD_Printf(btCoexDbgBuf);
9566 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Decrease Bt Power", \
9567 pBtCoex->btdm2Ant.bCurDecBtPwr);
9568 DCMD_Printf(btCoexDbgBuf);
9570 u1Tmp = rtl8723au_read8(padapter, 0x778);
9571 u1Tmp1 = rtl8723au_read8(padapter, 0x783);
9572 u1Tmp2 = rtl8723au_read8(padapter, 0x796);
9573 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
9574 u1Tmp, u1Tmp1, u1Tmp2);
9575 DCMD_Printf(btCoexDbgBuf);
9577 if (!pBtMgnt->ExtConfig.bManualControl) {
9578 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "Sw DacSwing Ctrl/Val", \
9579 pBtCoex->btdm2Ant.bCurDacSwingOn, pBtCoex->btdm2Ant.curDacSwingLvl);
9580 DCMD_Printf(btCoexDbgBuf);
9582 u4Tmp[0] = rtl8723au_read32(padapter, 0x880);
9583 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \
9585 DCMD_Printf(btCoexDbgBuf);
9588 if (!pBtMgnt->ExtConfig.bManualControl) {
9589 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw BT Coex mechanism]============");
9590 DCMD_Printf(btCoexDbgBuf);
9593 u1Tmp = rtl8723au_read8(padapter, 0x40);
9594 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
9596 DCMD_Printf(btCoexDbgBuf);
9598 u4Tmp[0] = rtl8723au_read32(padapter, 0x550);
9599 u1Tmp = rtl8723au_read8(padapter, 0x522);
9600 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x", "0x550(bcn contrl)/0x522", \
9602 DCMD_Printf(btCoexDbgBuf);
9604 u4Tmp[0] = rtl8723au_read32(padapter, 0x484);
9605 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
9607 DCMD_Printf(btCoexDbgBuf);
9609 u4Tmp[0] = rtl8723au_read32(padapter, 0x50);
9610 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
9612 DCMD_Printf(btCoexDbgBuf);
9614 u4Tmp[0] = rtl8723au_read32(padapter, 0xda0);
9615 u4Tmp[1] = rtl8723au_read32(padapter, 0xda4);
9616 u4Tmp[2] = rtl8723au_read32(padapter, 0xda8);
9617 u4Tmp[3] = rtl8723au_read32(padapter, 0xdac);
9618 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
9619 u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);
9620 DCMD_Printf(btCoexDbgBuf);
9622 u4Tmp[0] = rtl8723au_read32(padapter, 0x6c0);
9623 u4Tmp[1] = rtl8723au_read32(padapter, 0x6c4);
9624 u4Tmp[2] = rtl8723au_read32(padapter, 0x6c8);
9625 u1Tmp = rtl8723au_read8(padapter, 0x6cc);
9626 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
9627 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp);
9628 DCMD_Printf(btCoexDbgBuf);
9630 /* u4Tmp = rtl8723au_read32(padapter, 0x770); */
9631 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x770(Hi pri Rx[31:16]/Tx[15:0])", \
9632 pHalData->bt_coexist.halCoex8723.highPriorityRx,
9633 pHalData->bt_coexist.halCoex8723.highPriorityTx);
9634 DCMD_Printf(btCoexDbgBuf);
9635 /* u4Tmp = rtl8723au_read32(padapter, 0x774); */
9636 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x774(Lo pri Rx[31:16]/Tx[15:0])", \
9637 pHalData->bt_coexist.halCoex8723.lowPriorityRx,
9638 pHalData->bt_coexist.halCoex8723.lowPriorityTx);
9639 DCMD_Printf(btCoexDbgBuf);
9641 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang */
9642 u1Tmp = rtl8723au_read8(padapter, 0x41b);
9643 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x41b (hang chk == 0xf)", \
9645 DCMD_Printf(btCoexDbgBuf);
9646 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
9647 pHalData->LastHMEBoxNum);
9648 DCMD_Printf(btCoexDbgBuf);
9652 BTDM_8723ASignalCompensation(struct rtw_adapter *padapter,
9653 u8 *rssi_wifi, u8 *rssi_bt)
9655 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9656 BTDM_1AntSignalCompensation(padapter, rssi_wifi, rssi_bt);
9659 static void BTDM_8723AInit(struct rtw_adapter *padapter)
9661 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9662 BTDM_2AntParaInit(padapter);
9664 BTDM_1AntParaInit(padapter);
9667 static void BTDM_HWCoexAllOff8723A(struct rtw_adapter *padapter)
9669 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9670 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9672 if (pBtMgnt->ExtConfig.bManualControl)
9675 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9676 BTDM_2AntHwCoexAllOff8723A(padapter);
9679 static void BTDM_FWCoexAllOff8723A(struct rtw_adapter *padapter)
9681 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9682 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9684 if (pBtMgnt->ExtConfig.bManualControl)
9687 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9688 BTDM_2AntFwCoexAllOff8723A(padapter);
9691 static void BTDM_SWCoexAllOff8723A(struct rtw_adapter *padapter)
9693 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9694 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9696 if (pBtMgnt->ExtConfig.bManualControl)
9699 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9700 BTDM_2AntSwCoexAllOff8723A(padapter);
9704 BTDM_Set8723ABtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
9706 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9707 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9710 pBtCoex->TotalAntNum = Ant_x1;
9711 else if (antNum == 2)
9712 pBtCoex->TotalAntNum = Ant_x2;
9715 void rtl8723a_BT_lps_leave(struct rtw_adapter *padapter)
9717 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9718 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9720 if (pBtMgnt->ExtConfig.bManualControl)
9723 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9724 BTDM_1AntLpsLeave(padapter);
9727 static void BTDM_ForHalt8723A(struct rtw_adapter *padapter)
9729 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9730 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9732 if (pBtMgnt->ExtConfig.bManualControl)
9735 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9736 BTDM_1AntForHalt(padapter);
9739 static void BTDM_WifiScanNotify8723A(struct rtw_adapter *padapter, u8 scanType)
9741 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9742 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9744 if (pBtMgnt->ExtConfig.bManualControl)
9747 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9748 BTDM_1AntWifiScanNotify(padapter, scanType);
9752 BTDM_WifiAssociateNotify8723A(struct rtw_adapter *padapter, u8 action)
9754 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9755 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9757 if (pBtMgnt->ExtConfig.bManualControl)
9760 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9761 BTDM_1AntWifiAssociateNotify(padapter, action);
9765 BTDM_MediaStatusNotify8723A(struct rtw_adapter *padapter,
9766 enum rt_media_status mstatus)
9768 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9769 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9771 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatusNotify, %s\n",
9772 mstatus?"connect":"disconnect"));
9774 BTDM_SetFwChnlInfo(padapter, mstatus);
9776 if (pBtMgnt->ExtConfig.bManualControl)
9779 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9780 BTDM_1AntMediaStatusNotify(padapter, mstatus);
9783 static void BTDM_ForDhcp8723A(struct rtw_adapter *padapter)
9785 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9786 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9788 if (pBtMgnt->ExtConfig.bManualControl)
9791 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9792 BTDM_1AntForDhcp(padapter);
9795 bool rtl8723a_BT_using_antenna_1(struct rtw_adapter *padapter)
9797 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9803 static void BTDM_BTCoexist8723A(struct rtw_adapter *padapter)
9805 struct hal_data_8723a *pHalData;
9806 struct bt_30info *pBTInfo;
9807 struct bt_mgnt *pBtMgnt;
9808 struct bt_coexist_8723a *pBtCoex;
9810 pHalData = GET_HAL_DATA(padapter);
9811 pBTInfo = GET_BT_INFO(padapter);
9812 pBtMgnt = &pBTInfo->BtMgnt;
9813 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9815 RTPRINT(FBT, BT_TRACE, ("[BTCoex], beacon RSSI = 0x%x(%d)\n",
9816 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB,
9817 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB));
9819 btdm_BtHwCountersMonitor(padapter);
9820 btdm_BtEnableDisableCheck8723A(padapter);
9822 if (pBtMgnt->ExtConfig.bManualControl) {
9823 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9827 if (pBtCoex->bC2hBtInfoReqSent) {
9828 if (!rtl8723a_BT_enabled(padapter)) {
9829 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9831 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9832 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9835 btdm_BTCoexist8723AHandler(padapter);
9836 } else if (!rtl8723a_BT_enabled(padapter)) {
9837 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9838 btdm_BTCoexist8723AHandler(padapter);
9841 BTDM_QueryBtInformation(padapter);
9844 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
9846 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
9848 /* local function start with btdm_ */
9849 /* extern function start with BTDM_ */
9851 static void BTDM_SetAntenna(struct rtw_adapter *padapter, u8 who)
9857 struct rtw_adapter *padapter,
9863 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9864 u8 H2C_Parameter[3] = {0};
9866 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9869 H2C_Parameter[2] = 0;
9870 H2C_Parameter[1] = 0;
9871 H2C_Parameter[0] = 0;
9874 H2C_Parameter[2] |= 0x02; /* BIT1 */
9875 pHalData->bt_coexist.bFWCoexistAllOff = false;
9877 pHalData->bt_coexist.bInterruptOn = bInterruptOn;
9880 H2C_Parameter[2] |= 0x10; /* BIT4 */
9881 pHalData->bt_coexist.bFWCoexistAllOff = false;
9883 pHalData->bt_coexist.bSingleAntOn = bSingleAntOn;
9886 H2C_Parameter[2] |= 0x20; /* BIT5 */
9887 pHalData->bt_coexist.bFWCoexistAllOff = false;
9889 pHalData->bt_coexist.bMultiNAVOn = bMultiNAVOn;
9891 RTPRINT(FBT, BT_TRACE, ("[DM][BT], SingleAntenna =[%s:%s:%s], write 0xe = 0x%x\n",
9892 bSingleAntOn?"ON":"OFF", bInterruptOn?"ON":"OFF", bMultiNAVOn?"ON":"OFF",
9893 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
9896 void BTDM_CheckBTIdleChange1Ant(struct rtw_adapter *padapter)
9898 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9899 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9900 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9901 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
9902 u8 stateChange = false;
9903 u32 BT_Polling, Ratio_Act, Ratio_STA;
9904 u32 BT_Active, BT_State;
9905 u32 regBTActive = 0, regBTState = 0, regBTPolling = 0;
9907 if (!rtl8723a_BT_coexist(padapter))
9909 if (pBtMgnt->ExtConfig.bManualControl)
9911 if (pHalData->bt_coexist.BT_CoexistType != BT_CSR_BC8)
9913 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9916 /* The following we only consider CSR BC8 and fw version should be >= 62 */
9917 RTPRINT(FBT, BT_TRACE, ("[DM][BT], FirmwareVersion = 0x%x(%d)\n",
9918 pHalData->FirmwareVersion, pHalData->FirmwareVersion));
9919 regBTActive = REG_BT_ACTIVE;
9920 regBTState = REG_BT_STATE;
9921 if (pHalData->FirmwareVersion >= FW_VER_BT_REG1)
9922 regBTPolling = REG_BT_POLLING1;
9924 regBTPolling = REG_BT_POLLING;
9926 BT_Active = rtl8723au_read32(padapter, regBTActive);
9927 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Active(0x%x) =%x\n", regBTActive, BT_Active));
9928 BT_Active = BT_Active & 0x00ffffff;
9930 BT_State = rtl8723au_read32(padapter, regBTState);
9931 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_State(0x%x) =%x\n", regBTState, BT_State));
9932 BT_State = BT_State & 0x00ffffff;
9934 BT_Polling = rtl8723au_read32(padapter, regBTPolling);
9935 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Polling(0x%x) =%x\n", regBTPolling, BT_Polling));
9937 if (BT_Active == 0xffffffff && BT_State == 0xffffffff && BT_Polling == 0xffffffff)
9939 if (BT_Polling == 0)
9942 Ratio_Act = BT_Active*1000/BT_Polling;
9943 Ratio_STA = BT_State*1000/BT_Polling;
9945 pHalData->bt_coexist.Ratio_Tx = Ratio_Act;
9946 pHalData->bt_coexist.Ratio_PRI = Ratio_STA;
9948 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_Act =%d\n", Ratio_Act));
9949 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_STA =%d\n", Ratio_STA));
9951 if (Ratio_STA < 60 && Ratio_Act < 500) { /* BT PAN idle */
9952 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_IDLE;
9953 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9954 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9956 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_IDLE;
9959 /* Check if BT PAN (under BT 2.1) is uplink or downlink */
9960 if ((Ratio_Act/Ratio_STA) < 2) {
9962 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = true;
9963 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_UPLINK;
9964 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = false;
9965 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9967 /* BT PAN downlink */
9968 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9969 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9970 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9971 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9974 /* BT PAN downlink */
9975 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9976 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9977 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9978 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9982 /* Check BT is idle or not */
9983 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9984 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9985 pBtMgnt->ExtConfig.bBTBusy = false;
9986 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9988 if (Ratio_STA < 60) {
9989 pBtMgnt->ExtConfig.bBTBusy = false;
9990 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9992 pBtMgnt->ExtConfig.bBTBusy = true;
9993 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_IDLE;
9997 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9998 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9999 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
10000 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
10001 BTDM_SetAntenna(padapter, BTDM_ANT_BT_IDLE);
10003 if (pBtMgnt->ExtConfig.MIN_BT_RSSI <= -5) {
10004 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_RSSI_LOW;
10005 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Low\n"));
10007 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
10008 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Normal\n"));
10012 if (pHalData->bt_coexist.bBTBusyTraffic != pBtMgnt->ExtConfig.bBTBusy) {
10013 /* BT idle or BT non-idle */
10014 pHalData->bt_coexist.bBTBusyTraffic = pBtMgnt->ExtConfig.bBTBusy;
10015 stateChange = true;
10019 if (!pBtMgnt->ExtConfig.bBTBusy)
10020 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
10022 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is non-idle\n"));
10024 if (!pBtMgnt->ExtConfig.bBTBusy) {
10025 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
10026 if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING|WIFI_SITE_MONITOR) == true)
10027 BTDM_SetAntenna(padapter, BTDM_ANT_WIFI);
10031 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
10033 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
10035 /* local function start with btdm_ */
10038 /* In the following, FW should be done before SW mechanism. */
10039 /* BTDM_Balance(), BTDM_DiminishWiFi(), BT_NAV() should be done */
10040 /* before BTDM_AGCTable(), BTDM_BBBackOffLevel(), btdm_DacSwing(). */
10042 /* extern function start with BTDM_ */
10046 struct rtw_adapter *padapter,
10053 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10054 u8 H2C_Parameter[3] = {0};
10056 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x2)
10059 if ((pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_RSSI_LOW) &&
10060 (DACSwingLevel == 0x20)) {
10061 RTPRINT(FBT, BT_TRACE, ("[BT]DiminishWiFi 0x20 original, but set 0x18 for Low RSSI!\n"));
10062 DACSwingLevel = 0x18;
10065 H2C_Parameter[2] = 0;
10066 H2C_Parameter[1] = DACSwingLevel;
10067 H2C_Parameter[0] = 0;
10069 H2C_Parameter[2] |= 0x01; /* BIT0 */
10071 H2C_Parameter[2] |= 0x02; /* BIT1 */
10072 pHalData->bt_coexist.bFWCoexistAllOff = false;
10075 H2C_Parameter[2] |= 0x08; /* BIT3 */
10076 pHalData->bt_coexist.bFWCoexistAllOff = false;
10079 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bDACOn = %s, bInterruptOn = %s, write 0xe = 0x%x\n",
10080 bDACOn?"ON":"OFF", bInterruptOn?"ON":"OFF",
10081 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10082 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bNAVOn = %s\n",
10083 bNAVOn?"ON":"OFF"));
10086 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
10088 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
10090 /* local function */
10091 static void btdm_ResetFWCoexState(struct rtw_adapter *padapter)
10093 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10095 pHalData->bt_coexist.CurrentState = 0;
10096 pHalData->bt_coexist.PreviousState = 0;
10099 static void btdm_InitBtCoexistDM(struct rtw_adapter *padapter)
10101 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10103 /* 20100415 Joseph: Restore RF register 0x1E and 0x1F value for further usage. */
10104 pHalData->bt_coexist.BtRfRegOrigin1E = PHY_QueryRFReg(padapter, PathA, RF_RCK1, bRFRegOffsetMask);
10105 pHalData->bt_coexist.BtRfRegOrigin1F = PHY_QueryRFReg(padapter, PathA, RF_RCK2, 0xf0);
10107 pHalData->bt_coexist.CurrentState = 0;
10108 pHalData->bt_coexist.PreviousState = 0;
10110 BTDM_8723AInit(padapter);
10111 pHalData->bt_coexist.bInitlized = true;
10115 /* extern function */
10117 void BTDM_CheckAntSelMode(struct rtw_adapter *padapter)
10121 void BTDM_FwC2hBtRssi(struct rtw_adapter *padapter, u8 *tmpBuf)
10123 BTDM_FwC2hBtRssi8723A(padapter, tmpBuf);
10126 void BTDM_DisplayBtCoexInfo(struct rtw_adapter *padapter)
10128 BTDM_Display8723ABtCoexInfo(padapter);
10131 void BTDM_RejectAPAggregatedPacket(struct rtw_adapter *padapter, u8 bReject)
10135 u8 BTDM_IsHT40(struct rtw_adapter *padapter)
10138 enum ht_channel_width bw;
10140 bw = padapter->mlmeextpriv.cur_bwmode;
10142 if (bw == HT_CHANNEL_WIDTH_20)
10144 else if (bw == HT_CHANNEL_WIDTH_40)
10150 u8 BTDM_Legacy(struct rtw_adapter *padapter)
10152 struct mlme_ext_priv *pmlmeext;
10153 u8 isLegacy = false;
10155 pmlmeext = &padapter->mlmeextpriv;
10156 if ((pmlmeext->cur_wireless_mode == WIRELESS_11B) ||
10157 (pmlmeext->cur_wireless_mode == WIRELESS_11G) ||
10158 (pmlmeext->cur_wireless_mode == WIRELESS_11BG))
10164 void BTDM_CheckWiFiState(struct rtw_adapter *padapter)
10166 struct hal_data_8723a *pHalData;
10167 struct mlme_priv *pmlmepriv;
10168 struct bt_30info *pBTInfo;
10169 struct bt_mgnt *pBtMgnt;
10171 pHalData = GET_HAL_DATA(padapter);
10172 pmlmepriv = &padapter->mlmepriv;
10173 pBTInfo = GET_BT_INFO(padapter);
10174 pBtMgnt = &pBTInfo->BtMgnt;
10176 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
10177 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_IDLE;
10179 if (pmlmepriv->LinkDetectInfo.bTxBusyTraffic)
10180 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_UPLINK;
10182 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10184 if (pmlmepriv->LinkDetectInfo.bRxBusyTraffic)
10185 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_DOWNLINK;
10187 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10189 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_IDLE;
10190 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10191 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10194 if (BTDM_Legacy(padapter)) {
10195 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_LEGACY;
10196 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10197 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10199 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_LEGACY;
10200 if (BTDM_IsHT40(padapter)) {
10201 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT40;
10202 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10204 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT20;
10205 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10209 if (pBtMgnt->BtOperationOn)
10210 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT30;
10212 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT30;
10215 s32 BTDM_GetRxSS(struct rtw_adapter *padapter)
10217 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10218 struct mlme_priv *pmlmepriv;
10219 struct hal_data_8723a *pHalData;
10220 s32 UndecoratedSmoothedPWDB = 0;
10222 pmlmepriv = &padapter->mlmepriv;
10223 pHalData = GET_HAL_DATA(padapter);
10225 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10226 UndecoratedSmoothedPWDB = GET_UNDECORATED_AVERAGE_RSSI(padapter);
10227 } else { /* associated entry pwdb */
10228 UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10229 /* pHalData->BT_EntryMinUndecoratedSmoothedPWDB */
10231 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxSS() = %d\n", UndecoratedSmoothedPWDB));
10232 return UndecoratedSmoothedPWDB;
10235 static s32 BTDM_GetRxBeaconSS(struct rtw_adapter *padapter)
10237 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10238 struct mlme_priv *pmlmepriv;
10239 struct hal_data_8723a *pHalData;
10240 s32 pwdbBeacon = 0;
10242 pmlmepriv = &padapter->mlmepriv;
10243 pHalData = GET_HAL_DATA(padapter);
10245 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10246 /* pwdbBeacon = pHalData->dmpriv.UndecoratedSmoothedBeacon; */
10247 pwdbBeacon = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10249 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxBeaconSS() = %d\n", pwdbBeacon));
10253 /* Get beacon rssi state */
10254 u8 BTDM_CheckCoexBcnRssiState(struct rtw_adapter *padapter, u8 levelNum,
10255 u8 RssiThresh, u8 RssiThresh1)
10257 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10258 s32 pwdbBeacon = 0;
10259 u8 bcnRssiState = 0;
10261 pwdbBeacon = BTDM_GetRxBeaconSS(padapter);
10263 if (levelNum == 2) {
10264 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10266 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10267 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10268 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10269 bcnRssiState = BT_RSSI_STATE_HIGH;
10270 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10271 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10272 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10274 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10275 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10278 if (pwdbBeacon < RssiThresh) {
10279 bcnRssiState = BT_RSSI_STATE_LOW;
10280 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10281 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10282 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10284 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10285 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10288 } else if (levelNum == 3) {
10289 if (RssiThresh > RssiThresh1) {
10290 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON thresh error!!\n"));
10291 return pHalData->bt_coexist.preRssiStateBeacon;
10294 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10295 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10296 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10297 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10298 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10299 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10300 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10301 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10303 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10304 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10306 } else if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_MEDIUM) ||
10307 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_MEDIUM)) {
10308 if (pwdbBeacon >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10309 bcnRssiState = BT_RSSI_STATE_HIGH;
10310 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10311 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10312 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10313 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10314 } else if (pwdbBeacon < RssiThresh) {
10315 bcnRssiState = BT_RSSI_STATE_LOW;
10316 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10317 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10318 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10319 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10321 bcnRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10322 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Medium\n"));
10325 if (pwdbBeacon < RssiThresh1) {
10326 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10327 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10328 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10329 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10330 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10332 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10333 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10338 pHalData->bt_coexist.preRssiStateBeacon = bcnRssiState;
10340 return bcnRssiState;
10343 u8 BTDM_CheckCoexRSSIState1(struct rtw_adapter *padapter, u8 levelNum,
10344 u8 RssiThresh, u8 RssiThresh1)
10346 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10347 s32 UndecoratedSmoothedPWDB = 0;
10348 u8 btRssiState = 0;
10350 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10352 if (levelNum == 2) {
10353 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10355 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10356 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10357 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10358 btRssiState = BT_RSSI_STATE_HIGH;
10359 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10360 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10361 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10363 btRssiState = BT_RSSI_STATE_STAY_LOW;
10364 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10367 if (UndecoratedSmoothedPWDB < RssiThresh) {
10368 btRssiState = BT_RSSI_STATE_LOW;
10369 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10370 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10371 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10373 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10374 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10377 } else if (levelNum == 3) {
10378 if (RssiThresh > RssiThresh1) {
10379 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 thresh error!!\n"));
10380 return pHalData->bt_coexist.preRssiState1;
10383 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10384 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10385 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10386 btRssiState = BT_RSSI_STATE_MEDIUM;
10387 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10388 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10389 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10390 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10392 btRssiState = BT_RSSI_STATE_STAY_LOW;
10393 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10395 } else if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_MEDIUM) ||
10396 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_MEDIUM)) {
10397 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10398 btRssiState = BT_RSSI_STATE_HIGH;
10399 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10400 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10401 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10402 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10403 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10404 btRssiState = BT_RSSI_STATE_LOW;
10405 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10406 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10407 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10408 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10410 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10411 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Medium\n"));
10414 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10415 btRssiState = BT_RSSI_STATE_MEDIUM;
10416 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10417 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10418 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10419 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10421 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10422 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10427 pHalData->bt_coexist.preRssiState1 = btRssiState;
10429 return btRssiState;
10432 u8 BTDM_CheckCoexRSSIState(struct rtw_adapter *padapter, u8 levelNum,
10433 u8 RssiThresh, u8 RssiThresh1)
10435 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10436 s32 UndecoratedSmoothedPWDB = 0;
10437 u8 btRssiState = 0;
10439 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10441 if (levelNum == 2) {
10442 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10444 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10445 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10446 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10447 btRssiState = BT_RSSI_STATE_HIGH;
10448 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10449 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10450 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10452 btRssiState = BT_RSSI_STATE_STAY_LOW;
10453 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10456 if (UndecoratedSmoothedPWDB < RssiThresh) {
10457 btRssiState = BT_RSSI_STATE_LOW;
10458 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10459 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10460 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10462 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10463 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10466 } else if (levelNum == 3) {
10467 if (RssiThresh > RssiThresh1) {
10468 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI thresh error!!\n"));
10469 return pHalData->bt_coexist.preRssiState;
10472 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10473 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10474 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10475 btRssiState = BT_RSSI_STATE_MEDIUM;
10476 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10477 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10478 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10479 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10481 btRssiState = BT_RSSI_STATE_STAY_LOW;
10482 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10484 } else if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_MEDIUM) ||
10485 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_MEDIUM)) {
10486 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10487 btRssiState = BT_RSSI_STATE_HIGH;
10488 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10489 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10490 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10491 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10492 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10493 btRssiState = BT_RSSI_STATE_LOW;
10494 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10495 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10496 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10497 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10499 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10500 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Medium\n"));
10503 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10504 btRssiState = BT_RSSI_STATE_MEDIUM;
10505 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10506 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10507 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10508 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10510 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10511 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10516 pHalData->bt_coexist.preRssiState = btRssiState;
10518 return btRssiState;
10521 bool rtl8723a_BT_disable_EDCA_turbo(struct rtw_adapter *padapter)
10523 struct bt_mgnt *pBtMgnt;
10524 struct hal_data_8723a *pHalData;
10525 u8 bBtChangeEDCA = false;
10526 u32 EDCA_BT_BE = 0x5ea42b, cur_EDCA_reg;
10529 pHalData = GET_HAL_DATA(padapter);
10530 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10532 if (!rtl8723a_BT_coexist(padapter)) {
10534 pHalData->bt_coexist.lastBtEdca = 0;
10537 if (!((pBtMgnt->bSupportProfile) ||
10538 (pHalData->bt_coexist.BT_CoexistType == BT_CSR_BC8))) {
10540 pHalData->bt_coexist.lastBtEdca = 0;
10544 if (rtl8723a_BT_using_antenna_1(padapter)) {
10546 pHalData->bt_coexist.lastBtEdca = 0;
10550 if (pHalData->bt_coexist.exec_cnt < 3)
10551 pHalData->bt_coexist.exec_cnt++;
10553 pHalData->bt_coexist.bEDCAInitialized = true;
10555 /* When BT is non idle */
10556 if (!(pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)) {
10557 RTPRINT(FBT, BT_TRACE, ("BT state non idle, set bt EDCA\n"));
10559 /* aggr_num = 0x0909; */
10560 if (pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA) {
10561 bBtChangeEDCA = true;
10562 pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA = false;
10563 pHalData->dmpriv.prv_traffic_idx = 3;
10565 cur_EDCA_reg = rtl8723au_read32(padapter, REG_EDCA_BE_PARAM);
10567 if (cur_EDCA_reg != EDCA_BT_BE)
10568 bBtChangeEDCA = true;
10569 if (bBtChangeEDCA || !pHalData->bt_coexist.bEDCAInitialized) {
10570 rtl8723au_write32(padapter, REG_EDCA_BE_PARAM,
10572 pHalData->bt_coexist.lastBtEdca = EDCA_BT_BE;
10576 RTPRINT(FBT, BT_TRACE, ("BT state idle, set original EDCA\n"));
10577 pHalData->bt_coexist.lastBtEdca = 0;
10585 struct rtw_adapter *padapter,
10591 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10592 u8 H2C_Parameter[3] = {0};
10595 H2C_Parameter[2] = 1;
10596 H2C_Parameter[1] = ms1;
10597 H2C_Parameter[0] = ms0;
10598 pHalData->bt_coexist.bFWCoexistAllOff = false;
10600 H2C_Parameter[2] = 0;
10601 H2C_Parameter[1] = 0;
10602 H2C_Parameter[0] = 0;
10604 pHalData->bt_coexist.bBalanceOn = bBalanceOn;
10606 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Balance =[%s:%dms:%dms], write 0xc = 0x%x\n",
10607 bBalanceOn?"ON":"OFF", ms0, ms1,
10608 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10610 FillH2CCmd(padapter, 0xc, 3, H2C_Parameter);
10613 void BTDM_AGCTable(struct rtw_adapter *padapter, u8 type)
10615 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10616 if (type == BT_AGCTABLE_OFF) {
10617 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable Off!\n"));
10618 rtl8723au_write32(padapter, 0xc78, 0x641c0001);
10619 rtl8723au_write32(padapter, 0xc78, 0x631d0001);
10620 rtl8723au_write32(padapter, 0xc78, 0x621e0001);
10621 rtl8723au_write32(padapter, 0xc78, 0x611f0001);
10622 rtl8723au_write32(padapter, 0xc78, 0x60200001);
10624 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x32000);
10625 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x71000);
10626 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xb0000);
10627 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xfc000);
10628 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x30355);
10630 pHalData->bt_coexist.b8723aAgcTableOn = false;
10631 } else if (type == BT_AGCTABLE_ON) {
10632 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable On!\n"));
10633 rtl8723au_write32(padapter, 0xc78, 0x4e1c0001);
10634 rtl8723au_write32(padapter, 0xc78, 0x4d1d0001);
10635 rtl8723au_write32(padapter, 0xc78, 0x4c1e0001);
10636 rtl8723au_write32(padapter, 0xc78, 0x4b1f0001);
10637 rtl8723au_write32(padapter, 0xc78, 0x4a200001);
10639 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xdc000);
10640 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x90000);
10641 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x51000);
10642 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x12000);
10643 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x00355);
10645 pHalData->bt_coexist.b8723aAgcTableOn = true;
10647 pHalData->bt_coexist.bSWCoexistAllOff = false;
10651 void BTDM_BBBackOffLevel(struct rtw_adapter *padapter, u8 type)
10653 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10655 if (type == BT_BB_BACKOFF_OFF) {
10656 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel Off!\n"));
10657 rtl8723au_write32(padapter, 0xc04, 0x3a05611);
10658 } else if (type == BT_BB_BACKOFF_ON) {
10659 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel On!\n"));
10660 rtl8723au_write32(padapter, 0xc04, 0x3a07611);
10661 pHalData->bt_coexist.bSWCoexistAllOff = false;
10665 void BTDM_FWCoexAllOff(struct rtw_adapter *padapter)
10667 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10669 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff()\n"));
10670 if (pHalData->bt_coexist.bFWCoexistAllOff)
10672 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff(), real Do\n"));
10674 BTDM_FWCoexAllOff8723A(padapter);
10676 pHalData->bt_coexist.bFWCoexistAllOff = true;
10679 void BTDM_SWCoexAllOff(struct rtw_adapter *padapter)
10681 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10683 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff()\n"));
10684 if (pHalData->bt_coexist.bSWCoexistAllOff)
10686 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff(), real Do\n"));
10687 BTDM_SWCoexAllOff8723A(padapter);
10689 pHalData->bt_coexist.bSWCoexistAllOff = true;
10692 void BTDM_HWCoexAllOff(struct rtw_adapter *padapter)
10694 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10696 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff()\n"));
10697 if (pHalData->bt_coexist.bHWCoexistAllOff)
10699 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff(), real Do\n"));
10701 BTDM_HWCoexAllOff8723A(padapter);
10703 pHalData->bt_coexist.bHWCoexistAllOff = true;
10706 void BTDM_CoexAllOff(struct rtw_adapter *padapter)
10708 BTDM_FWCoexAllOff(padapter);
10709 BTDM_SWCoexAllOff(padapter);
10710 BTDM_HWCoexAllOff(padapter);
10713 void rtl8723a_BT_disable_coexist(struct rtw_adapter *padapter)
10715 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
10717 if (!rtl8723a_BT_coexist(padapter))
10720 /* 8723 1Ant doesn't need to turn off bt coexist mechanism. */
10721 if (rtl8723a_BT_using_antenna_1(padapter))
10724 /* Before enter IPS, turn off FW BT Co-exist mechanism */
10725 if (ppwrctrl->reg_rfoff == rf_on) {
10726 RTPRINT(FBT, BT_TRACE, ("[BT][DM], Before enter IPS, turn off all Coexist DM\n"));
10727 btdm_ResetFWCoexState(padapter);
10728 BTDM_CoexAllOff(padapter);
10729 BTDM_SetAntenna(padapter, BTDM_ANT_BT);
10733 void BTDM_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
10735 BTDM_8723ASignalCompensation(padapter, rssi_wifi, rssi_bt);
10738 void rtl8723a_BT_do_coexist(struct rtw_adapter *padapter)
10740 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10742 if (!rtl8723a_BT_coexist(padapter)) {
10743 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT not exists!!\n"));
10747 if (!pHalData->bt_coexist.bInitlized) {
10748 RTPRINT(FBT, BT_TRACE, ("[DM][BT], btdm_InitBtCoexistDM()\n"));
10749 btdm_InitBtCoexistDM(padapter);
10752 RTPRINT(FBT, BT_TRACE, ("\n\n[DM][BT], BTDM start!!\n"));
10754 BTDM_PWDBMonitor(padapter);
10756 RTPRINT(FBT, BT_TRACE, ("[DM][BT], HW type is 8723\n"));
10757 BTDM_BTCoexist8723A(padapter);
10758 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BTDM end!!\n\n"));
10761 void BTDM_UpdateCoexState(struct rtw_adapter *padapter)
10763 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10765 if (!BTDM_IsSameCoexistState(padapter)) {
10766 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x, changeBits = 0x%"i64fmt"x\n",
10767 pHalData->bt_coexist.PreviousState,
10768 pHalData->bt_coexist.CurrentState,
10769 (pHalData->bt_coexist.PreviousState^pHalData->bt_coexist.CurrentState)));
10770 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
10774 u8 BTDM_IsSameCoexistState(struct rtw_adapter *padapter)
10776 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10778 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState) {
10781 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Coexist state changed!!\n"));
10786 void BTDM_PWDBMonitor(struct rtw_adapter *padapter)
10788 struct bt_30info *pBTInfo = GET_BT_INFO(GetDefaultAdapter(padapter));
10789 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10790 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10791 u8 H2C_Parameter[3] = {0};
10792 s32 tmpBTEntryMaxPWDB = 0, tmpBTEntryMinPWDB = 0xff;
10795 if (pBtMgnt->BtOperationOn) {
10796 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
10797 if (pBTInfo->BtAsocEntry[i].bUsed) {
10798 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB < tmpBTEntryMinPWDB)
10799 tmpBTEntryMinPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10800 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB > tmpBTEntryMaxPWDB)
10801 tmpBTEntryMaxPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10802 /* Report every BT connection (HS mode) RSSI to FW */
10803 H2C_Parameter[2] = (u8)(pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB & 0xFF);
10804 H2C_Parameter[0] = (MAX_FW_SUPPORT_MACID_NUM-1-i);
10805 RTPRINT(FDM, DM_BT30, ("RSSI report for BT[%d], H2C_Par = 0x%x\n", i, H2C_Parameter[0]));
10806 FillH2CCmd(padapter, RSSI_SETTING_EID, 3, H2C_Parameter);
10807 RTPRINT_ADDR(FDM, (DM_PWDB|DM_BT30), ("BT_Entry Mac :"),
10808 pBTInfo->BtAsocEntry[i].BTRemoteMACAddr)
10809 RTPRINT(FDM, (DM_PWDB|DM_BT30),
10810 ("BT rx pwdb[%d] = 0x%x(%d)\n", i,
10811 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB,
10812 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB));
10815 if (tmpBTEntryMaxPWDB != 0) { /* If associated entry is found */
10816 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = tmpBTEntryMaxPWDB;
10817 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMaxPWDB = 0x%x(%d)\n",
10818 tmpBTEntryMaxPWDB, tmpBTEntryMaxPWDB));
10820 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = 0;
10822 if (tmpBTEntryMinPWDB != 0xff) { /* If associated entry is found */
10823 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = tmpBTEntryMinPWDB;
10824 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMinPWDB = 0x%x(%d)\n",
10825 tmpBTEntryMinPWDB, tmpBTEntryMinPWDB));
10827 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = 0;
10832 u8 BTDM_IsBTBusy(struct rtw_adapter *padapter)
10834 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10835 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10837 if (pBtMgnt->ExtConfig.bBTBusy)
10843 u8 BTDM_IsWifiBusy(struct rtw_adapter *padapter)
10845 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10846 struct mlme_priv *pmlmepriv = &GetDefaultAdapter(padapter)->mlmepriv;
10847 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10848 struct bt_traffic *pBtTraffic = &pBTInfo->BtTraffic;
10850 if (pmlmepriv->LinkDetectInfo.bBusyTraffic ||
10851 pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic ||
10852 pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic)
10858 u8 BTDM_IsCoexistStateChanged(struct rtw_adapter *padapter)
10860 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10862 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState)
10868 u8 BTDM_IsWifiUplink(struct rtw_adapter *padapter)
10870 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10871 struct mlme_priv *pmlmepriv;
10872 struct bt_30info *pBTInfo;
10873 struct bt_traffic *pBtTraffic;
10875 pmlmepriv = &padapter->mlmepriv;
10876 pBTInfo = GET_BT_INFO(padapter);
10877 pBtTraffic = &pBTInfo->BtTraffic;
10879 if ((pmlmepriv->LinkDetectInfo.bTxBusyTraffic) ||
10880 (pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic))
10886 u8 BTDM_IsWifiDownlink(struct rtw_adapter *padapter)
10888 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10889 struct mlme_priv *pmlmepriv;
10890 struct bt_30info *pBTInfo;
10891 struct bt_traffic *pBtTraffic;
10893 pmlmepriv = &padapter->mlmepriv;
10894 pBTInfo = GET_BT_INFO(padapter);
10895 pBtTraffic = &pBTInfo->BtTraffic;
10897 if ((pmlmepriv->LinkDetectInfo.bRxBusyTraffic) ||
10898 (pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic))
10904 u8 BTDM_IsBTHSMode(struct rtw_adapter *padapter)
10906 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10907 struct hal_data_8723a *pHalData;
10908 struct bt_mgnt *pBtMgnt;
10910 pHalData = GET_HAL_DATA(padapter);
10911 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10913 if (pBtMgnt->BtOperationOn)
10919 u8 BTDM_IsBTUplink(struct rtw_adapter *padapter)
10921 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10923 if (pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic)
10929 u8 BTDM_IsBTDownlink(struct rtw_adapter *padapter)
10931 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10933 if (pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic)
10939 void BTDM_AdjustForBtOperation(struct rtw_adapter *padapter)
10941 RTPRINT(FBT, BT_TRACE, ("[BT][DM], BTDM_AdjustForBtOperation()\n"));
10942 BTDM_AdjustForBtOperation8723A(padapter);
10945 void BTDM_SetBtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
10947 BTDM_Set8723ABtCoexCurrAntNum(padapter, antNum);
10950 void BTDM_ForHalt(struct rtw_adapter *padapter)
10952 if (!rtl8723a_BT_coexist(padapter))
10955 BTDM_ForHalt8723A(padapter);
10956 GET_HAL_DATA(padapter)->bt_coexist.bInitlized = false;
10959 void BTDM_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
10961 if (!rtl8723a_BT_coexist(padapter))
10964 BTDM_WifiScanNotify8723A(padapter, scanType);
10967 void BTDM_WifiAssociateNotify(struct rtw_adapter *padapter, u8 action)
10969 if (!rtl8723a_BT_coexist(padapter))
10972 BTDM_WifiAssociateNotify8723A(padapter, action);
10975 void rtl8723a_BT_mediastatus_notify(struct rtw_adapter *padapter,
10976 enum rt_media_status mstatus)
10978 if (!rtl8723a_BT_coexist(padapter))
10981 BTDM_MediaStatusNotify8723A(padapter, mstatus);
10984 void rtl8723a_BT_specialpacket_notify(struct rtw_adapter *padapter)
10986 if (!rtl8723a_BT_coexist(padapter))
10989 BTDM_ForDhcp8723A(padapter);
10992 void BTDM_ResetActionProfileState(struct rtw_adapter *padapter)
10994 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10996 pHalData->bt_coexist.CurrentState &= ~\
10997 (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP|
10998 BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_SCO);
11001 u8 BTDM_IsActionSCO(struct rtw_adapter *padapter)
11003 struct hal_data_8723a *pHalData;
11004 struct bt_30info *pBTInfo;
11005 struct bt_mgnt *pBtMgnt;
11006 struct bt_dgb *pBtDbg;
11009 pHalData = GET_HAL_DATA(padapter);
11010 pBTInfo = GET_BT_INFO(padapter);
11011 pBtMgnt = &pBTInfo->BtMgnt;
11012 pBtDbg = &pBTInfo->BtDbg;
11015 if (pBtDbg->dbgCtrl) {
11016 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_SCO) {
11017 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
11021 if (pBtMgnt->ExtConfig.NumberOfSCO > 0) {
11022 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
11029 u8 BTDM_IsActionHID(struct rtw_adapter *padapter)
11031 struct bt_30info *pBTInfo;
11032 struct hal_data_8723a *pHalData;
11033 struct bt_mgnt *pBtMgnt;
11034 struct bt_dgb *pBtDbg;
11037 pHalData = GET_HAL_DATA(padapter);
11038 pBTInfo = GET_BT_INFO(padapter);
11039 pBtMgnt = &pBTInfo->BtMgnt;
11040 pBtDbg = &pBTInfo->BtDbg;
11043 if (pBtDbg->dbgCtrl) {
11044 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID) {
11045 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11049 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11050 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11051 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11058 u8 BTDM_IsActionA2DP(struct rtw_adapter *padapter)
11060 struct hal_data_8723a *pHalData;
11061 struct bt_30info *pBTInfo;
11062 struct bt_mgnt *pBtMgnt;
11063 struct bt_dgb *pBtDbg;
11066 pHalData = GET_HAL_DATA(padapter);
11067 pBTInfo = GET_BT_INFO(padapter);
11068 pBtMgnt = &pBTInfo->BtMgnt;
11069 pBtDbg = &pBTInfo->BtDbg;
11072 if (pBtDbg->dbgCtrl) {
11073 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_A2DP) {
11074 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11078 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP) &&
11079 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11080 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11087 u8 BTDM_IsActionPAN(struct rtw_adapter *padapter)
11089 struct hal_data_8723a *pHalData;
11090 struct bt_30info *pBTInfo;
11091 struct bt_mgnt *pBtMgnt;
11092 struct bt_dgb *pBtDbg;
11095 pHalData = GET_HAL_DATA(padapter);
11096 pBTInfo = GET_BT_INFO(padapter);
11097 pBtMgnt = &pBTInfo->BtMgnt;
11098 pBtDbg = &pBTInfo->BtDbg;
11101 if (pBtDbg->dbgCtrl) {
11102 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN) {
11103 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11107 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
11108 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11109 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11116 u8 BTDM_IsActionHIDA2DP(struct rtw_adapter *padapter)
11118 struct hal_data_8723a *pHalData;
11119 struct bt_30info *pBTInfo;
11120 struct bt_mgnt *pBtMgnt;
11121 struct bt_dgb *pBtDbg;
11124 pHalData = GET_HAL_DATA(padapter);
11125 pBTInfo = GET_BT_INFO(padapter);
11126 pBtMgnt = &pBTInfo->BtMgnt;
11127 pBtDbg = &pBTInfo->BtDbg;
11130 if (pBtDbg->dbgCtrl) {
11131 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_A2DP) {
11132 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11136 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11137 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11138 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11145 u8 BTDM_IsActionHIDPAN(struct rtw_adapter *padapter)
11147 struct hal_data_8723a *pHalData;
11148 struct bt_30info *pBTInfo;
11149 struct bt_dgb *pBtDbg;
11152 pHalData = GET_HAL_DATA(padapter);
11153 pBTInfo = GET_BT_INFO(padapter);
11154 pBtDbg = &pBTInfo->BtDbg;
11157 if (pBtDbg->dbgCtrl) {
11158 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_PAN) {
11159 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11163 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11164 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
11165 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11172 u8 BTDM_IsActionPANA2DP(struct rtw_adapter *padapter)
11174 struct hal_data_8723a *pHalData;
11175 struct bt_30info *pBTInfo;
11176 struct bt_dgb *pBtDbg;
11179 pHalData = GET_HAL_DATA(padapter);
11180 pBTInfo = GET_BT_INFO(padapter);
11181 pBtDbg = &pBTInfo->BtDbg;
11184 if (pBtDbg->dbgCtrl) {
11185 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN_A2DP) {
11186 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11190 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) && BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11191 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11198 bool rtl8723a_BT_enabled(struct rtw_adapter *padapter)
11200 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11202 if (pHalData->bt_coexist.bCurBtDisabled)
11208 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
11210 /* ===== Below this line is sync from SD7 driver HAL/HalBT.c ===== */
11213 /*local function */
11216 static void halbt_InitHwConfig8723A(struct rtw_adapter *padapter)
11221 /*extern function */
11223 u8 HALBT_GetPGAntNum(struct rtw_adapter *padapter)
11225 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11227 return pHalData->bt_coexist.BT_Ant_Num;
11230 void HALBT_SetKey(struct rtw_adapter *padapter, u8 EntryNum)
11232 struct bt_30info *pBTinfo;
11233 struct bt_asoc_entry *pBtAssocEntry;
11236 pBTinfo = GET_BT_INFO(padapter);
11237 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11239 pBtAssocEntry->HwCAMIndex = BT_HWCAM_STAR + EntryNum;
11241 usConfig = CAM_VALID | (CAM_AES << 2);
11242 rtl8723a_cam_write(padapter, pBtAssocEntry->HwCAMIndex, usConfig,
11243 pBtAssocEntry->BTRemoteMACAddr,
11244 pBtAssocEntry->PTK + TKIP_ENC_KEY_POS);
11247 void HALBT_RemoveKey(struct rtw_adapter *padapter, u8 EntryNum)
11249 struct bt_30info *pBTinfo;
11250 struct bt_asoc_entry *pBtAssocEntry;
11252 pBTinfo = GET_BT_INFO(padapter);
11253 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11255 if (pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex != 0) {
11256 /* ToDo : add New HALBT_RemoveKey function !! */
11257 if (pBtAssocEntry->HwCAMIndex >= BT_HWCAM_STAR &&
11258 pBtAssocEntry->HwCAMIndex < HALF_CAM_ENTRY)
11259 rtl8723a_cam_empty_entry(padapter,
11260 pBtAssocEntry->HwCAMIndex);
11261 pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex = 0;
11265 void rtl8723a_BT_init_hal_vars(struct rtw_adapter *padapter)
11267 struct hal_data_8723a *pHalData;
11269 pHalData = GET_HAL_DATA(padapter);
11271 pHalData->bt_coexist.BluetoothCoexist = pHalData->EEPROMBluetoothCoexist;
11272 pHalData->bt_coexist.BT_Ant_Num = pHalData->EEPROMBluetoothAntNum;
11273 pHalData->bt_coexist.BT_CoexistType = pHalData->EEPROMBluetoothType;
11274 pHalData->bt_coexist.BT_Ant_isolation = pHalData->EEPROMBluetoothAntIsolation;
11275 pHalData->bt_coexist.bt_radiosharedtype = pHalData->EEPROMBluetoothRadioShared;
11277 RT_TRACE(_module_hal_init_c_, _drv_info_,
11278 ("BT Coexistance = 0x%x\n", rtl8723a_BT_coexist(padapter)));
11280 if (rtl8723a_BT_coexist(padapter)) {
11281 if (pHalData->bt_coexist.BT_Ant_Num == Ant_x2) {
11282 BTDM_SetBtCoexCurrAntNum(padapter, 2);
11283 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx2\n"));
11284 } else if (pHalData->bt_coexist.BT_Ant_Num == Ant_x1) {
11285 BTDM_SetBtCoexCurrAntNum(padapter, 1);
11286 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx1\n"));
11288 pHalData->bt_coexist.bBTBusyTraffic = false;
11289 pHalData->bt_coexist.bBTTrafficModeSet = false;
11290 pHalData->bt_coexist.bBTNonTrafficModeSet = false;
11291 pHalData->bt_coexist.CurrentState = 0;
11292 pHalData->bt_coexist.PreviousState = 0;
11294 RT_TRACE(_module_hal_init_c_, _drv_info_,
11295 ("bt_radiosharedType = 0x%x\n",
11296 pHalData->bt_coexist.bt_radiosharedtype));
11300 bool rtl8723a_BT_coexist(struct rtw_adapter *padapter)
11302 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11304 if (pHalData->bt_coexist.BluetoothCoexist)
11310 u8 HALBT_BTChipType(struct rtw_adapter *padapter)
11312 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11314 return pHalData->bt_coexist.BT_CoexistType;
11317 void rtl8723a_BT_init_hwconfig(struct rtw_adapter *padapter)
11319 halbt_InitHwConfig8723A(padapter);
11320 rtl8723a_BT_do_coexist(padapter);
11323 void HALBT_SetRtsCtsNoLenLimit(struct rtw_adapter *padapter)
11327 /* ===== End of sync from SD7 driver HAL/HalBT.c ===== */
11329 void rtl8723a_dual_antenna_detection(struct rtw_adapter *padapter)
11331 struct hal_data_8723a *pHalData;
11332 struct dm_odm_t *pDM_Odm;
11333 struct sw_ant_sw *pDM_SWAT_Table;
11336 pHalData = GET_HAL_DATA(padapter);
11337 pDM_Odm = &pHalData->odmpriv;
11338 pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
11341 /* <Roger_Notes> RTL8723A Single and Dual antenna dynamic detection
11342 mechanism when RF power state is on. */
11343 /* We should take power tracking, IQK, LCK, RCK RF read/write
11344 operation into consideration. */
11347 if (!pHalData->bAntennaDetected) {
11348 u8 btAntNum = BT_GetPGAntNum(padapter);
11350 /* Set default antenna B status */
11351 if (btAntNum == Ant_x2)
11352 pDM_SWAT_Table->ANTB_ON = true;
11353 else if (btAntNum == Ant_x1)
11354 pDM_SWAT_Table->ANTB_ON = false;
11356 pDM_SWAT_Table->ANTB_ON = true;
11358 if (pHalData->CustomerID != RT_CID_TOSHIBA) {
11359 for (i = 0; i < MAX_ANTENNA_DETECTION_CNT; i++) {
11360 if (ODM_SingleDualAntennaDetection
11361 (&pHalData->odmpriv, ANTTESTALL) == true)
11365 /* Set default antenna number for BT coexistence */
11366 if (btAntNum == Ant_x2)
11367 BT_SetBtCoexCurrAntNum(padapter,
11371 pHalData->bAntennaDetected = true;