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 le16_to_cpus(&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_CmdWriteConnectionAcceptTimeout(
1765 struct rtw_adapter *padapter,
1766 struct packet_irp_hcicmd_data *pHciCmd
1769 enum hci_status status = HCI_STATUS_SUCCESS;
1770 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1771 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1773 u8 localBuf[6] = "";
1776 struct packet_irp_hcievent_data *PPacketIrpEvent;
1778 pu2Temp = (u16 *)&pHciCmd->Data[0];
1779 pBtHciInfo->ConnAcceptTimeout = *pu2Temp;
1780 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ConnAcceptTimeout = 0x%x",
1781 pBtHciInfo->ConnAcceptTimeout));
1783 /* send command complete event here when all data are received. */
1784 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1786 len += bthci_CommandCompleteHeader(&localBuf[0],
1787 OGF_SET_EVENT_MASK_COMMAND,
1788 HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT,
1791 /* Return parameters starts from here */
1792 pRetPar = &PPacketIrpEvent->Data[len];
1793 pRetPar[0] = status; /* status */
1795 PPacketIrpEvent->Length = len;
1797 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1802 static enum hci_status
1803 bthci_CmdReadPageTimeout(
1804 struct rtw_adapter *padapter,
1805 struct packet_irp_hcicmd_data *pHciCmd
1808 enum hci_status status = HCI_STATUS_SUCCESS;
1809 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1810 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1811 u8 localBuf[8] = "";
1814 struct packet_irp_hcievent_data *PPacketIrpEvent;
1817 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1819 len += bthci_CommandCompleteHeader(&localBuf[0],
1820 OGF_SET_EVENT_MASK_COMMAND,
1821 HCI_READ_PAGE_TIMEOUT,
1824 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Read PageTimeout = 0x%x\n", pBtHciInfo->PageTimeout));
1825 /* Return parameters starts from here */
1826 pRetPar = &PPacketIrpEvent->Data[len];
1827 pRetPar[0] = status; /* status */
1828 pu2Temp = (u16 *)&pRetPar[1]; /* Page_Timeout */
1829 *pu2Temp = pBtHciInfo->PageTimeout;
1831 PPacketIrpEvent->Length = len;
1833 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1838 static enum hci_status
1839 bthci_CmdWritePageTimeout(
1840 struct rtw_adapter *padapter,
1841 struct packet_irp_hcicmd_data *pHciCmd
1844 enum hci_status status = HCI_STATUS_SUCCESS;
1845 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1846 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1849 pu2Temp = (u16 *)&pHciCmd->Data[0];
1850 pBtHciInfo->PageTimeout = *pu2Temp;
1851 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Write PageTimeout = 0x%x\n",
1852 pBtHciInfo->PageTimeout));
1854 /* send command complete event here when all data are received. */
1856 u8 localBuf[6] = "";
1859 struct packet_irp_hcievent_data *PPacketIrpEvent;
1861 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1863 len += bthci_CommandCompleteHeader(&localBuf[0],
1864 OGF_SET_EVENT_MASK_COMMAND,
1865 HCI_WRITE_PAGE_TIMEOUT,
1868 /* Return parameters starts from here */
1869 pRetPar = &PPacketIrpEvent->Data[len];
1870 pRetPar[0] = status; /* status */
1872 PPacketIrpEvent->Length = len;
1874 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1880 static enum hci_status
1881 bthci_CmdReadLinkSupervisionTimeout(
1882 struct rtw_adapter *padapter,
1883 struct packet_irp_hcicmd_data *pHciCmd
1886 enum hci_status status = HCI_STATUS_SUCCESS;
1887 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1888 u8 physicalLinkHandle, EntryNum;
1890 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1892 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1894 if (EntryNum == 0xff) {
1895 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLinkSupervisionTimeout, No such Handle in the Entry\n"));
1896 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1900 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle)
1901 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1904 u8 localBuf[10] = "";
1907 struct packet_irp_hcievent_data *PPacketIrpEvent;
1910 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1912 len += bthci_CommandCompleteHeader(&localBuf[0],
1913 OGF_SET_EVENT_MASK_COMMAND,
1914 HCI_READ_LINK_SUPERVISION_TIMEOUT,
1917 /* Return parameters starts from here */
1918 pRetPar = &PPacketIrpEvent->Data[len];
1919 pRetPar[0] = status;
1920 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1922 pu2Temp = (u16 *)&pRetPar[3]; /* Conn_Accept_Timeout */
1923 *pu2Temp = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout;
1925 PPacketIrpEvent->Length = len;
1927 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1933 static enum hci_status
1934 bthci_CmdWriteLinkSupervisionTimeout(
1935 struct rtw_adapter *padapter,
1936 struct packet_irp_hcicmd_data *pHciCmd
1939 enum hci_status status = HCI_STATUS_SUCCESS;
1940 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1941 u8 physicalLinkHandle, EntryNum;
1943 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1945 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1947 if (EntryNum == 0xff) {
1948 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("WriteLinkSupervisionTimeout, No such Handle in the Entry\n"));
1949 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1951 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle) {
1952 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1954 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = *((u16 *)(((u8 *)pHciCmd->Data)+2));
1955 RTPRINT(FIOCTL, IOCTL_STATE, ("BT Write LinkSuperversionTimeout[%d] = 0x%x\n",
1956 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout));
1961 u8 localBuf[8] = "";
1964 struct packet_irp_hcievent_data *PPacketIrpEvent;
1966 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1968 len += bthci_CommandCompleteHeader(&localBuf[0],
1969 OGF_SET_EVENT_MASK_COMMAND,
1970 HCI_WRITE_LINK_SUPERVISION_TIMEOUT,
1973 /* Return parameters starts from here */
1974 pRetPar = &PPacketIrpEvent->Data[len];
1975 pRetPar[0] = status;
1976 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1979 PPacketIrpEvent->Length = len;
1981 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1987 static enum hci_status
1988 bthci_CmdEnhancedFlush(
1989 struct rtw_adapter *padapter,
1990 struct packet_irp_hcicmd_data *pHciCmd
1993 enum hci_status status = HCI_STATUS_SUCCESS;
1994 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1995 struct bt_hci_info *pBtHciInfo = &pBTinfo->BtHciInfo;
1999 logicHandle = *((u16 *)&pHciCmd->Data[0]);
2000 Packet_Type = pHciCmd->Data[2];
2002 if (Packet_Type != 0)
2003 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
2005 pBtHciInfo->enFlush_LLH = logicHandle;
2007 if (bthci_DiscardTxPackets(padapter, pBtHciInfo->enFlush_LLH))
2008 bthci_EventFlushOccurred(padapter, pBtHciInfo->enFlush_LLH);
2010 /* should send command status event */
2011 bthci_EventCommandStatus(padapter,
2012 OGF_SET_EVENT_MASK_COMMAND,
2016 if (pBtHciInfo->enFlush_LLH) {
2017 bthci_EventEnhancedFlushComplete(padapter, pBtHciInfo->enFlush_LLH);
2018 pBtHciInfo->enFlush_LLH = 0;
2024 static enum hci_status
2025 bthci_CmdReadLogicalLinkAcceptTimeout(
2026 struct rtw_adapter *padapter,
2027 struct packet_irp_hcicmd_data *pHciCmd
2030 enum hci_status status = HCI_STATUS_SUCCESS;
2031 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2032 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2033 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2034 u8 localBuf[8] = "";
2037 struct packet_irp_hcievent_data *PPacketIrpEvent;
2040 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2042 len += bthci_CommandCompleteHeader(&localBuf[0],
2043 OGF_SET_EVENT_MASK_COMMAND,
2044 HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT,
2047 /* Return parameters starts from here */
2048 pRetPar = &PPacketIrpEvent->Data[len];
2049 pRetPar[0] = status;
2051 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
2052 *pu2Temp = pBtHciInfo->LogicalAcceptTimeout;
2054 PPacketIrpEvent->Length = len;
2056 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2061 static enum hci_status
2062 bthci_CmdWriteLogicalLinkAcceptTimeout(
2063 struct rtw_adapter *padapter,
2064 struct packet_irp_hcicmd_data *pHciCmd
2067 enum hci_status status = HCI_STATUS_SUCCESS;
2068 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2069 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2070 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2071 u8 localBuf[6] = "";
2074 struct packet_irp_hcievent_data *PPacketIrpEvent;
2076 pBtHciInfo->LogicalAcceptTimeout = *((u16 *)pHciCmd->Data);
2078 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2080 len += bthci_CommandCompleteHeader(&localBuf[0],
2081 OGF_SET_EVENT_MASK_COMMAND,
2082 HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT,
2085 /* Return parameters starts from here */
2086 pRetPar = &PPacketIrpEvent->Data[len];
2087 pRetPar[0] = status;
2090 PPacketIrpEvent->Length = len;
2092 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2096 static enum hci_status
2097 bthci_CmdSetEventMask(
2098 struct rtw_adapter *padapter,
2099 struct packet_irp_hcicmd_data *pHciCmd
2102 enum hci_status status = HCI_STATUS_SUCCESS;
2103 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2104 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2105 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2107 u8 localBuf[6] = "";
2110 struct packet_irp_hcievent_data *PPacketIrpEvent;
2112 pu8Temp = (u8 *)&pHciCmd->Data[0];
2113 pBtHciInfo->BTEventMask = *pu8Temp;
2114 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("BTEventMask = 0x%"i64fmt"x\n",
2115 pBtHciInfo->BTEventMask));
2117 /* send command complete event here when all data are received. */
2118 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2120 len += bthci_CommandCompleteHeader(&localBuf[0],
2121 OGF_SET_EVENT_MASK_COMMAND,
2125 /* Return parameters starts from here */
2126 pRetPar = &PPacketIrpEvent->Data[len];
2127 pRetPar[0] = status; /* status */
2129 PPacketIrpEvent->Length = len;
2131 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2137 static enum hci_status
2138 bthci_CmdSetEventMaskPage2(
2139 struct rtw_adapter *padapter,
2140 struct packet_irp_hcicmd_data *pHciCmd
2143 enum hci_status status = HCI_STATUS_SUCCESS;
2144 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2145 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2147 u8 localBuf[6] = "";
2150 struct packet_irp_hcievent_data *PPacketIrpEvent;
2152 pu8Temp = (u8 *)&pHciCmd->Data[0];
2153 pBtHciInfo->BTEventMaskPage2 = *pu8Temp;
2154 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("BTEventMaskPage2 = 0x%"i64fmt"x\n",
2155 pBtHciInfo->BTEventMaskPage2));
2157 /* send command complete event here when all data are received. */
2158 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2160 len += bthci_CommandCompleteHeader(&localBuf[0],
2161 OGF_SET_EVENT_MASK_COMMAND,
2162 HCI_SET_EVENT_MASK_PAGE_2,
2165 /* Return parameters starts from here */
2166 pRetPar = &PPacketIrpEvent->Data[len];
2167 pRetPar[0] = status; /* status */
2169 PPacketIrpEvent->Length = len;
2171 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2176 static enum hci_status
2177 bthci_CmdReadLocationData(
2178 struct rtw_adapter *padapter,
2179 struct packet_irp_hcicmd_data *pHciCmd
2182 enum hci_status status = HCI_STATUS_SUCCESS;
2183 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2184 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2185 u8 localBuf[12] = "";
2188 struct packet_irp_hcievent_data *PPacketIrpEvent;
2191 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2193 len += bthci_CommandCompleteHeader(&localBuf[0],
2194 OGF_SET_EVENT_MASK_COMMAND,
2195 HCI_READ_LOCATION_DATA,
2197 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2198 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2199 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2200 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2202 /* Return parameters starts from here */
2203 pRetPar = &PPacketIrpEvent->Data[len];
2204 pRetPar[0] = status;
2206 pRetPar[1] = pBtHciInfo->LocationDomainAware; /* 0x0; Location_Domain_Aware */
2207 pu2Temp = (u16 *)&pRetPar[2]; /* Location_Domain */
2208 *pu2Temp = pBtHciInfo->LocationDomain; /* 0x5858; */
2209 pRetPar[4] = pBtHciInfo->LocationDomainOptions; /* 0x58; Location_Domain_Options */
2210 pRetPar[5] = pBtHciInfo->LocationOptions; /* 0x0; Location_Options */
2212 PPacketIrpEvent->Length = len;
2214 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2218 static enum hci_status
2219 bthci_CmdWriteLocationData(
2220 struct rtw_adapter *padapter,
2221 struct packet_irp_hcicmd_data *pHciCmd
2224 enum hci_status status = HCI_STATUS_SUCCESS;
2225 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2226 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2228 u8 localBuf[6] = "";
2231 struct packet_irp_hcievent_data *PPacketIrpEvent;
2233 pBtHciInfo->LocationDomainAware = pHciCmd->Data[0];
2234 pu2Temp = (u16 *)&pHciCmd->Data[1];
2235 pBtHciInfo->LocationDomain = *pu2Temp;
2236 pBtHciInfo->LocationDomainOptions = pHciCmd->Data[3];
2237 pBtHciInfo->LocationOptions = pHciCmd->Data[4];
2238 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2239 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2240 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2241 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2243 /* send command complete event here when all data are received. */
2244 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2246 len += bthci_CommandCompleteHeader(&localBuf[0],
2247 OGF_SET_EVENT_MASK_COMMAND,
2248 HCI_WRITE_LOCATION_DATA,
2251 /* Return parameters starts from here */
2252 pRetPar = &PPacketIrpEvent->Data[len];
2253 pRetPar[0] = status; /* status */
2255 PPacketIrpEvent->Length = len;
2257 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2262 static enum hci_status
2263 bthci_CmdReadFlowControlMode(
2264 struct rtw_adapter *padapter,
2265 struct packet_irp_hcicmd_data *pHciCmd
2268 enum hci_status status = HCI_STATUS_SUCCESS;
2269 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2270 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2271 u8 localBuf[7] = "";
2274 struct packet_irp_hcievent_data *PPacketIrpEvent;
2276 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2278 len += bthci_CommandCompleteHeader(&localBuf[0],
2279 OGF_SET_EVENT_MASK_COMMAND,
2280 HCI_READ_FLOW_CONTROL_MODE,
2283 /* Return parameters starts from here */
2284 pRetPar = &PPacketIrpEvent->Data[len];
2285 pRetPar[0] = status;
2286 pRetPar[1] = pBtHciInfo->FlowControlMode; /* Flow Control Mode */
2288 PPacketIrpEvent->Length = len;
2290 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2294 static enum hci_status
2295 bthci_CmdWriteFlowControlMode(
2296 struct rtw_adapter *padapter,
2297 struct packet_irp_hcicmd_data *pHciCmd
2300 enum hci_status status = HCI_STATUS_SUCCESS;
2301 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2302 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2303 u8 localBuf[6] = "";
2306 struct packet_irp_hcievent_data *PPacketIrpEvent;
2308 pBtHciInfo->FlowControlMode = pHciCmd->Data[0];
2310 /* send command complete event here when all data are received. */
2311 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2313 len += bthci_CommandCompleteHeader(&localBuf[0],
2314 OGF_SET_EVENT_MASK_COMMAND,
2315 HCI_WRITE_FLOW_CONTROL_MODE,
2318 /* Return parameters starts from here */
2319 pRetPar = &PPacketIrpEvent->Data[len];
2320 pRetPar[0] = status; /* status */
2322 PPacketIrpEvent->Length = len;
2324 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2329 static enum hci_status
2330 bthci_CmdReadBestEffortFlushTimeout(
2331 struct rtw_adapter *padapter,
2332 struct packet_irp_hcicmd_data *pHciCmd
2335 enum hci_status status = HCI_STATUS_SUCCESS;
2336 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2337 u16 i, j, logicHandle;
2338 u32 BestEffortFlushTimeout = 0xffffffff;
2341 logicHandle = *((u16 *)pHciCmd->Data);
2342 /* find an matched logical link index and copy the data */
2343 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2344 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2345 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2346 BestEffortFlushTimeout = pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout;
2354 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2357 u8 localBuf[10] = "";
2360 struct packet_irp_hcievent_data *PPacketIrpEvent;
2363 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2365 len += bthci_CommandCompleteHeader(&localBuf[0],
2366 OGF_SET_EVENT_MASK_COMMAND,
2367 HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT,
2370 /* Return parameters starts from here */
2371 pRetPar = &PPacketIrpEvent->Data[len];
2372 pRetPar[0] = status;
2373 pu4Temp = (u32 *)&pRetPar[1]; /* Best_Effort_Flush_Timeout */
2374 *pu4Temp = BestEffortFlushTimeout;
2376 PPacketIrpEvent->Length = len;
2378 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2383 static enum hci_status
2384 bthci_CmdWriteBestEffortFlushTimeout(
2385 struct rtw_adapter *padapter,
2386 struct packet_irp_hcicmd_data *pHciCmd
2389 enum hci_status status = HCI_STATUS_SUCCESS;
2390 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2391 u16 i, j, logicHandle;
2392 u32 BestEffortFlushTimeout = 0xffffffff;
2395 logicHandle = *((u16 *)pHciCmd->Data);
2396 BestEffortFlushTimeout = *((u32 *)(pHciCmd->Data+1));
2398 /* find an matched logical link index and copy the data */
2399 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2400 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2401 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2402 pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout = BestEffortFlushTimeout;
2410 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2413 u8 localBuf[6] = "";
2416 struct packet_irp_hcievent_data *PPacketIrpEvent;
2418 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2420 len += bthci_CommandCompleteHeader(&localBuf[0],
2421 OGF_SET_EVENT_MASK_COMMAND,
2422 HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT,
2425 /* Return parameters starts from here */
2426 pRetPar = &PPacketIrpEvent->Data[len];
2427 pRetPar[0] = status;
2429 PPacketIrpEvent->Length = len;
2431 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2436 static enum hci_status
2437 bthci_CmdShortRangeMode(
2438 struct rtw_adapter *padapter,
2439 struct packet_irp_hcicmd_data *pHciCmd
2442 enum hci_status status = HCI_STATUS_SUCCESS;
2443 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2444 u8 PhyLinkHandle, EntryNum, ShortRangeMode;
2446 PhyLinkHandle = pHciCmd->Data[0];
2447 ShortRangeMode = pHciCmd->Data[1];
2448 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x, Short_Range_Mode = 0x%x\n", PhyLinkHandle, ShortRangeMode));
2450 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2451 if (EntryNum != 0xff) {
2452 pBTInfo->BtAsocEntry[EntryNum].ShortRangeMode = ShortRangeMode;
2454 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PhyLinkHandle));
2455 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2458 bthci_EventCommandStatus(padapter,
2459 OGF_SET_EVENT_MASK_COMMAND,
2460 HCI_SHORT_RANGE_MODE,
2463 bthci_EventShortRangeModeChangeComplete(padapter, status, ShortRangeMode, EntryNum);
2468 static enum hci_status bthci_CmdReadLocalSupportedCommands(struct rtw_adapter *padapter)
2470 enum hci_status status = HCI_STATUS_SUCCESS;
2471 u8 localBuf[TmpLocalBufSize] = "";
2472 u8 *pRetPar, *pSupportedCmds;
2474 struct packet_irp_hcievent_data *PPacketIrpEvent;
2476 /* send command complete event here when all data are received. */
2477 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2478 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2480 len += bthci_CommandCompleteHeader(&localBuf[0],
2481 OGF_INFORMATIONAL_PARAMETERS,
2482 HCI_READ_LOCAL_SUPPORTED_COMMANDS,
2485 /* Return parameters starts from here */
2486 pRetPar = &PPacketIrpEvent->Data[len];
2487 pRetPar[0] = status; /* status */
2489 pSupportedCmds = &pRetPar[1];
2490 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[5]= 0xc0\nBit [6]= Set Event Mask, [7]= Reset\n"));
2491 pSupportedCmds[5] = 0xc0;
2492 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[6]= 0x01\nBit [0]= Set Event Filter\n"));
2493 pSupportedCmds[6] = 0x01;
2494 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[7]= 0x0c\nBit [2]= Read Connection Accept Timeout, [3]= Write Connection Accept Timeout\n"));
2495 pSupportedCmds[7] = 0x0c;
2496 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[10]= 0x80\nBit [7]= Host Number Of Completed Packets\n"));
2497 pSupportedCmds[10] = 0x80;
2498 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[11]= 0x03\nBit [0]= Read Link Supervision Timeout, [1]= Write Link Supervision Timeout\n"));
2499 pSupportedCmds[11] = 0x03;
2500 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"));
2501 pSupportedCmds[14] = 0xa8;
2502 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"));
2503 pSupportedCmds[15] = 0x1c;
2504 /* pSupportedCmds[16] = 0x04; */
2505 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[19]= 0x40\nBit [6]= Enhanced Flush\n"));
2506 pSupportedCmds[19] = 0x40;
2507 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"));
2508 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"));
2509 pSupportedCmds[21] = 0xff;
2510 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"));
2511 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"));
2512 pSupportedCmds[22] = 0xff;
2513 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"));
2514 pSupportedCmds[23] = 0x07;
2515 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"));
2516 pSupportedCmds[24] = 0x1c;
2518 PPacketIrpEvent->Length = len;
2520 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2525 static enum hci_status bthci_CmdReadLocalSupportedFeatures(struct rtw_adapter *padapter)
2527 enum hci_status status = HCI_STATUS_SUCCESS;
2528 u8 localBuf[TmpLocalBufSize] = "";
2531 struct packet_irp_hcievent_data *PPacketIrpEvent;
2533 /* send command complete event here when all data are received. */
2534 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2535 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2537 len += bthci_CommandCompleteHeader(&localBuf[0],
2538 OGF_INFORMATIONAL_PARAMETERS,
2539 HCI_READ_LOCAL_SUPPORTED_FEATURES,
2542 /* Return parameters starts from here */
2543 pRetPar = &PPacketIrpEvent->Data[len];
2544 pRetPar[0] = status; /* status */
2546 PPacketIrpEvent->Length = len;
2548 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2552 static enum hci_status bthci_CmdReadLocalAMPAssoc(struct rtw_adapter *padapter,
2553 struct packet_irp_hcicmd_data *pHciCmd)
2555 enum hci_status status = HCI_STATUS_SUCCESS;
2556 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2557 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
2558 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2559 u8 PhyLinkHandle, EntryNum;
2561 pBtDbg->dbgHciInfo.hciCmdCntReadLocalAmpAssoc++;
2562 PhyLinkHandle = *((u8 *)pHciCmd->Data);
2563 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2565 if ((EntryNum == 0xff) && PhyLinkHandle != 0) {
2566 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x\n",
2567 EntryNum, PhyLinkHandle));
2568 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2569 } else if (pBtMgnt->bPhyLinkInProgressStartLL) {
2570 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2571 pBtMgnt->bPhyLinkInProgressStartLL = false;
2573 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
2574 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
2575 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen = *((u16 *)((u8 *)pHciCmd->Data+3));
2576 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ReadLocalAMPAssoc, LenSoFar =%d, MaxRemoteASSOCLen =%d\n",
2577 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar,
2578 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen));
2581 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x, LengthSoFar = %x \n",
2582 EntryNum, PhyLinkHandle, pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar));
2584 /* send command complete event here when all data are received. */
2586 struct packet_irp_hcievent_data *PPacketIrpEvent;
2588 /* PVOID buffer = padapter->IrpHCILocalbuf.Ptr; */
2589 u8 localBuf[TmpLocalBufSize] = "";
2592 u16 typeLen = 0, remainLen = 0, ret_index = 0;
2595 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2596 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2597 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2599 totalLen += bthci_CommandCompleteHeader(&localBuf[0],
2600 OGF_STATUS_PARAMETERS,
2601 HCI_READ_LOCAL_AMP_ASSOC,
2603 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2604 /* Return parameters starts from here */
2605 pRetPar = &PPacketIrpEvent->Data[totalLen];
2606 pRetPar[0] = status; /* status */
2607 pRetPar[1] = *((u8 *)pHciCmd->Data);
2608 pRemainLen = (u16 *)&pRetPar[2]; /* AMP_ASSOC_Remaining_Length */
2609 totalLen += 4; /* 0]~[3] */
2612 typeLen = bthci_AssocMACAddr(padapter, &pRetPar[ret_index]);
2613 totalLen += typeLen;
2614 remainLen += typeLen;
2615 ret_index += typeLen;
2616 typeLen = bthci_AssocPreferredChannelList(padapter, &pRetPar[ret_index], EntryNum);
2617 totalLen += typeLen;
2618 remainLen += typeLen;
2619 ret_index += typeLen;
2620 typeLen = bthci_PALCapabilities(padapter, &pRetPar[ret_index]);
2621 totalLen += typeLen;
2622 remainLen += typeLen;
2623 ret_index += typeLen;
2624 typeLen = bthci_AssocPALVer(padapter, &pRetPar[ret_index]);
2625 totalLen += typeLen;
2626 remainLen += typeLen;
2627 PPacketIrpEvent->Length = (u8)totalLen;
2628 *pRemainLen = remainLen; /* AMP_ASSOC_Remaining_Length */
2629 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2630 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("AMP_ASSOC_fragment : \n"), PPacketIrpEvent->Data, totalLen);
2632 bthci_IndicateEvent(padapter, PPacketIrpEvent, totalLen+2);
2638 static enum hci_status bthci_CmdReadFailedContactCounter(struct rtw_adapter *padapter,
2639 struct packet_irp_hcicmd_data *pHciCmd)
2642 enum hci_status status = HCI_STATUS_SUCCESS;
2643 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2644 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2645 u8 localBuf[TmpLocalBufSize] = "";
2648 struct packet_irp_hcievent_data *PPacketIrpEvent;
2651 handle = *((u16 *)pHciCmd->Data);
2652 /* send command complete event here when all data are received. */
2653 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2654 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2656 len += bthci_CommandCompleteHeader(&localBuf[0],
2657 OGF_STATUS_PARAMETERS,
2658 HCI_READ_FAILED_CONTACT_COUNTER,
2661 /* Return parameters starts from here */
2662 pRetPar = &PPacketIrpEvent->Data[len];
2663 pRetPar[0] = status; /* status */
2664 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2665 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2666 pRetPar[3] = TWOBYTE_LOWBYTE(pBtHciInfo->FailContactCount);
2667 pRetPar[4] = TWOBYTE_HIGHTBYTE(pBtHciInfo->FailContactCount);
2669 PPacketIrpEvent->Length = len;
2671 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2676 static enum hci_status
2677 bthci_CmdResetFailedContactCounter(
2678 struct rtw_adapter *padapter,
2679 struct packet_irp_hcicmd_data *pHciCmd
2682 enum hci_status status = HCI_STATUS_SUCCESS;
2683 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2684 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2685 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2687 u8 localBuf[TmpLocalBufSize] = "";
2690 struct packet_irp_hcievent_data *PPacketIrpEvent;
2692 handle = *((u16 *)pHciCmd->Data);
2693 pBtHciInfo->FailContactCount = 0;
2695 /* send command complete event here when all data are received. */
2696 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2697 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2698 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2700 len += bthci_CommandCompleteHeader(&localBuf[0],
2701 OGF_STATUS_PARAMETERS,
2702 HCI_RESET_FAILED_CONTACT_COUNTER,
2705 /* Return parameters starts from here */
2706 pRetPar = &PPacketIrpEvent->Data[len];
2707 pRetPar[0] = status; /* status */
2708 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2709 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2711 PPacketIrpEvent->Length = len;
2713 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2718 /* BT 3.0+HS [Vol 2] 7.4.1 */
2720 static enum hci_status
2721 bthci_CmdReadLocalVersionInformation(
2722 struct rtw_adapter *padapter
2725 enum hci_status status = HCI_STATUS_SUCCESS;
2726 /* send command complete event here when all data are received. */
2727 u8 localBuf[TmpLocalBufSize] = "";
2730 struct packet_irp_hcievent_data *PPacketIrpEvent;
2733 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2734 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2736 len += bthci_CommandCompleteHeader(&localBuf[0],
2737 OGF_INFORMATIONAL_PARAMETERS,
2738 HCI_READ_LOCAL_VERSION_INFORMATION,
2741 /* Return parameters starts from here */
2742 pRetPar = &PPacketIrpEvent->Data[len];
2743 pRetPar[0] = status; /* status */
2744 pRetPar[1] = 0x05; /* HCI_Version */
2745 pu2Temp = (u16 *)&pRetPar[2]; /* HCI_Revision */
2747 pRetPar[4] = 0x05; /* LMP/PAL_Version */
2748 pu2Temp = (u16 *)&pRetPar[5]; /* Manufacturer_Name */
2750 pu2Temp = (u16 *)&pRetPar[7]; /* LMP/PAL_Subversion */
2753 PPacketIrpEvent->Length = len;
2755 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LOCAL_VERSION_INFORMATION\n"));
2756 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Status %x\n", status));
2757 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Version = 0x05\n"));
2758 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Revision = 0x0001\n"));
2759 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Version = 0x05\n"));
2760 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Manufacturer_Name = 0x0001\n"));
2761 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Subversion = 0x0001\n"));
2763 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2769 static enum hci_status bthci_CmdReadDataBlockSize(struct rtw_adapter *padapter)
2771 enum hci_status status = HCI_STATUS_SUCCESS;
2772 u8 localBuf[TmpLocalBufSize] = "";
2775 struct packet_irp_hcievent_data *PPacketIrpEvent;
2778 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2779 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2781 len += bthci_CommandCompleteHeader(&localBuf[0],
2782 OGF_INFORMATIONAL_PARAMETERS,
2783 HCI_READ_DATA_BLOCK_SIZE,
2786 /* Return parameters starts from here */
2787 pRetPar = &PPacketIrpEvent->Data[len];
2788 pRetPar[0] = HCI_STATUS_SUCCESS; /* status */
2789 pu2Temp = (u16 *)&pRetPar[1]; /* Max_ACL_Data_Packet_Length */
2790 *pu2Temp = Max80211PALPDUSize;
2792 pu2Temp = (u16 *)&pRetPar[3]; /* Data_Block_Length */
2793 *pu2Temp = Max80211PALPDUSize;
2794 pu2Temp = (u16 *)&pRetPar[5]; /* Total_Num_Data_Blocks */
2795 *pu2Temp = BTTotalDataBlockNum;
2797 PPacketIrpEvent->Length = len;
2799 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2805 static enum hci_status bthci_CmdReadBufferSize(struct rtw_adapter *padapter)
2807 enum hci_status status = HCI_STATUS_SUCCESS;
2808 u8 localBuf[TmpLocalBufSize] = "";
2811 struct packet_irp_hcievent_data *PPacketIrpEvent;
2814 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2815 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2816 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2818 len += bthci_CommandCompleteHeader(&localBuf[0],
2819 OGF_INFORMATIONAL_PARAMETERS,
2820 HCI_READ_BUFFER_SIZE,
2822 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Synchronous_Data_Packet_Length = 0x%x\n", BTSynDataPacketLength));
2823 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_ACL_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2824 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_Synchronous_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2825 /* Return parameters starts from here */
2826 pRetPar = &PPacketIrpEvent->Data[len];
2827 pRetPar[0] = status; /* status */
2828 pu2Temp = (u16 *)&pRetPar[1]; /* HC_ACL_Data_Packet_Length */
2829 *pu2Temp = Max80211PALPDUSize;
2831 pRetPar[3] = BTSynDataPacketLength; /* HC_Synchronous_Data_Packet_Length */
2832 pu2Temp = (u16 *)&pRetPar[4]; /* HC_Total_Num_ACL_Data_Packets */
2833 *pu2Temp = BTTotalDataBlockNum;
2834 pu2Temp = (u16 *)&pRetPar[6]; /* HC_Total_Num_Synchronous_Data_Packets */
2835 *pu2Temp = BTTotalDataBlockNum;
2837 PPacketIrpEvent->Length = len;
2839 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2844 static enum hci_status bthci_CmdReadLocalAMPInfo(struct rtw_adapter *padapter)
2846 enum hci_status status = HCI_STATUS_SUCCESS;
2847 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
2848 u8 localBuf[TmpLocalBufSize] = "";
2851 struct packet_irp_hcievent_data *PPacketIrpEvent;
2854 u32 TotalBandwidth = BTTOTALBANDWIDTH, MaxBandGUBandwidth = BTMAXBANDGUBANDWIDTH;
2855 u8 ControlType = 0x01, AmpStatus = 0x01;
2856 u32 MaxFlushTimeout = 10000, BestEffortFlushTimeout = 5000;
2857 u16 MaxPDUSize = Max80211PALPDUSize, PalCap = 0x1, AmpAssocLen = Max80211AMPASSOCLen, MinLatency = 20;
2859 if ((ppwrctrl->rfoff_reason & RF_CHANGE_BY_HW) ||
2860 (ppwrctrl->rfoff_reason & RF_CHANGE_BY_SW)) {
2861 AmpStatus = AMP_STATUS_NO_CAPACITY_FOR_BT;
2864 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2865 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2866 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2868 len += bthci_CommandCompleteHeader(&localBuf[0],
2869 OGF_STATUS_PARAMETERS,
2870 HCI_READ_LOCAL_AMP_INFO,
2873 /* Return parameters starts from here */
2874 pRetPar = &PPacketIrpEvent->Data[len];
2875 pRetPar[0] = status; /* status */
2876 pRetPar[1] = AmpStatus; /* AMP_Status */
2877 pu4Temp = (u32 *)&pRetPar[2]; /* Total_Bandwidth */
2878 *pu4Temp = TotalBandwidth; /* 0x19bfcc00;0x7530; */
2879 pu4Temp = (u32 *)&pRetPar[6]; /* Max_Guaranteed_Bandwidth */
2880 *pu4Temp = MaxBandGUBandwidth; /* 0x19bfcc00;0x4e20; */
2881 pu4Temp = (u32 *)&pRetPar[10]; /* Min_Latency */
2882 *pu4Temp = MinLatency; /* 150; */
2883 pu4Temp = (u32 *)&pRetPar[14]; /* Max_PDU_Size */
2884 *pu4Temp = MaxPDUSize;
2885 pRetPar[18] = ControlType; /* Controller_Type */
2886 pu2Temp = (u16 *)&pRetPar[19]; /* PAL_Capabilities */
2888 pu2Temp = (u16 *)&pRetPar[21]; /* AMP_ASSOC_Length */
2889 *pu2Temp = AmpAssocLen;
2890 pu4Temp = (u32 *)&pRetPar[23]; /* Max_Flush_Timeout */
2891 *pu4Temp = MaxFlushTimeout;
2892 pu4Temp = (u32 *)&pRetPar[27]; /* Best_Effort_Flush_Timeout */
2893 *pu4Temp = BestEffortFlushTimeout;
2895 PPacketIrpEvent->Length = len;
2896 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("AmpStatus = 0x%x\n",
2898 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TotalBandwidth = 0x%x, MaxBandGUBandwidth = 0x%x, MinLatency = 0x%x, \n MaxPDUSize = 0x%x, ControlType = 0x%x\n",
2899 TotalBandwidth, MaxBandGUBandwidth, MinLatency, MaxPDUSize, ControlType));
2900 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PalCap = 0x%x, AmpAssocLen = 0x%x, MaxFlushTimeout = 0x%x, BestEffortFlushTimeout = 0x%x\n",
2901 PalCap, AmpAssocLen, MaxFlushTimeout, BestEffortFlushTimeout));
2902 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2906 static enum hci_status
2907 bthci_CmdCreatePhysicalLink(
2908 struct rtw_adapter *padapter,
2909 struct packet_irp_hcicmd_data *pHciCmd
2912 enum hci_status status;
2913 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2914 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2916 pBtDbg->dbgHciInfo.hciCmdCntCreatePhyLink++;
2918 status = bthci_BuildPhysicalLink(padapter,
2919 pHciCmd, HCI_CREATE_PHYSICAL_LINK);
2924 static enum hci_status
2925 bthci_CmdReadLinkQuality(
2926 struct rtw_adapter *padapter,
2927 struct packet_irp_hcicmd_data *pHciCmd
2930 enum hci_status status = HCI_STATUS_SUCCESS;
2931 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2933 u8 EntryNum, LinkQuality = 0x55;
2935 PLH = *((u16 *)&pHciCmd->Data[0]);
2936 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x\n", PLH));
2938 EntryNum = bthci_GetCurrentEntryNum(padapter, (u8)PLH);
2939 if (EntryNum == 0xff) {
2940 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PLH));
2941 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2945 u8 localBuf[11] = "";
2948 struct packet_irp_hcievent_data *PPacketIrpEvent;
2950 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2952 len += bthci_CommandCompleteHeader(&localBuf[0],
2953 OGF_STATUS_PARAMETERS,
2954 HCI_READ_LINK_QUALITY,
2957 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" PLH = 0x%x\n Link Quality = 0x%x\n", PLH, LinkQuality));
2959 /* Return parameters starts from here */
2960 pRetPar = &PPacketIrpEvent->Data[len];
2961 pRetPar[0] = status; /* status */
2962 *((u16 *)&pRetPar[1]) = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle; /* Handle */
2963 pRetPar[3] = 0x55; /* Link Quailty */
2965 PPacketIrpEvent->Length = len;
2967 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2973 static enum hci_status
2974 bthci_CmdCreateLogicalLink(
2975 struct rtw_adapter *padapter,
2976 struct packet_irp_hcicmd_data *pHciCmd
2979 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2980 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2982 pBtDbg->dbgHciInfo.hciCmdCntCreateLogLink++;
2984 bthci_BuildLogicalLink(padapter, pHciCmd,
2985 HCI_CREATE_LOGICAL_LINK);
2987 return HCI_STATUS_SUCCESS;
2990 static enum hci_status
2991 bthci_CmdAcceptLogicalLink(
2992 struct rtw_adapter *padapter,
2993 struct packet_irp_hcicmd_data *pHciCmd
2996 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2997 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2999 pBtDbg->dbgHciInfo.hciCmdCntAcceptLogLink++;
3001 bthci_BuildLogicalLink(padapter, pHciCmd,
3002 HCI_ACCEPT_LOGICAL_LINK);
3004 return HCI_STATUS_SUCCESS;
3007 static enum hci_status
3008 bthci_CmdDisconnectLogicalLink(
3009 struct rtw_adapter *padapter,
3010 struct packet_irp_hcicmd_data *pHciCmd
3013 enum hci_status status = HCI_STATUS_SUCCESS;
3014 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3015 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3016 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3017 struct bt_dgb *pBtDbg = &pBTinfo->BtDbg;
3019 u8 i, j, find = 0, LogLinkCount = 0;
3021 pBtDbg->dbgHciInfo.hciCmdCntDisconnectLogLink++;
3023 logicHandle = *((u16 *)pHciCmd->Data);
3024 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle = 0x%x\n", logicHandle));
3026 /* find an created logical link index and clear the data */
3027 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3028 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3029 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3030 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle is matched 0x%x\n", logicHandle));
3031 bthci_ResetFlowSpec(padapter, j, i);
3033 pBtMgnt->DisconnectEntryNum = j;
3040 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3043 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3044 if (pBTinfo->BtAsocEntry[pBtMgnt->DisconnectEntryNum].LogLinkCmdData[i].BtLogLinkhandle != 0)
3048 /* When we receive Create logical link command, we should send command status event first. */
3049 bthci_EventCommandStatus(padapter,
3050 LINK_CONTROL_COMMANDS,
3051 HCI_DISCONNECT_LOGICAL_LINK,
3054 /* When we determines the logical link is established, we should send command complete event. */
3056 if (status == HCI_STATUS_SUCCESS) {
3057 bthci_EventDisconnectLogicalLinkComplete(padapter, status,
3058 logicHandle, HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST);
3061 if (LogLinkCount == 0)
3062 mod_timer(&pBTinfo->BTDisconnectPhyLinkTimer,
3063 jiffies + msecs_to_jiffies(100));
3068 static enum hci_status
3069 bthci_CmdLogicalLinkCancel(struct rtw_adapter *padapter,
3070 struct packet_irp_hcicmd_data *pHciCmd)
3072 enum hci_status status = HCI_STATUS_SUCCESS;
3073 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3074 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3075 u8 CurrentEntryNum, CurrentLogEntryNum;
3077 u8 physicalLinkHandle, TxFlowSpecID, i;
3078 u16 CurrentLogicalHandle;
3080 physicalLinkHandle = *((u8 *)pHciCmd->Data);
3081 TxFlowSpecID = *(((u8 *)pHciCmd->Data)+1);
3083 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, physicalLinkHandle = 0x%x, TxFlowSpecID = 0x%x\n",
3084 physicalLinkHandle, TxFlowSpecID));
3086 CurrentEntryNum = pBtMgnt->CurrentConnectEntryNum;
3087 CurrentLogicalHandle = pBtMgnt->BtCurrentLogLinkhandle;
3089 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("CurrentEntryNum = 0x%x, CurrentLogicalHandle = 0x%x\n",
3090 CurrentEntryNum, CurrentLogicalHandle));
3092 CurrentLogEntryNum = 0xff;
3093 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3094 if ((CurrentLogicalHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtLogLinkhandle) &&
3095 (physicalLinkHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtPhyLinkhandle)) {
3096 CurrentLogEntryNum = i;
3101 if (CurrentLogEntryNum == 0xff) {
3102 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, CurrentLogEntryNum == 0xff !!!!\n"));
3103 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3106 if (pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCompleteEventIsSet) {
3107 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, LLCompleteEventIsSet!!!!\n"));
3108 status = HCI_STATUS_ACL_CONNECT_EXISTS;
3113 u8 localBuf[8] = "";
3116 struct packet_irp_hcievent_data *PPacketIrpEvent;
3118 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3120 len += bthci_CommandCompleteHeader(&localBuf[0],
3121 LINK_CONTROL_COMMANDS,
3122 HCI_LOGICAL_LINK_CANCEL,
3125 /* Return parameters starts from here */
3126 pRetPar = &PPacketIrpEvent->Data[len];
3127 pRetPar[0] = status; /* status */
3128 pRetPar[1] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtPhyLinkhandle;
3129 pRetPar[2] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtTxFlowSpecID;
3131 PPacketIrpEvent->Length = len;
3133 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3136 pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCancelCMDIsSetandComplete = true;
3141 static enum hci_status
3142 bthci_CmdFlowSpecModify(struct rtw_adapter *padapter,
3143 struct packet_irp_hcicmd_data *pHciCmd)
3145 enum hci_status status = HCI_STATUS_SUCCESS;
3146 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3147 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3151 logicHandle = *((u16 *)pHciCmd->Data);
3152 /* find an matched logical link index and copy the data */
3153 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3154 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3155 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3156 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec,
3157 &pHciCmd->Data[2], sizeof(struct hci_flow_spec));
3158 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Rx_Flow_Spec,
3159 &pHciCmd->Data[18], sizeof(struct hci_flow_spec));
3161 bthci_CheckLogLinkBehavior(padapter, pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec);
3167 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("FlowSpecModify, LLH = 0x%x, \n", logicHandle));
3169 /* When we receive Flow Spec Modify command, we should send command status event first. */
3170 bthci_EventCommandStatus(padapter,
3171 LINK_CONTROL_COMMANDS,
3172 HCI_FLOW_SPEC_MODIFY,
3173 HCI_STATUS_SUCCESS);
3176 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3178 bthci_EventSendFlowSpecModifyComplete(padapter, status, logicHandle);
3183 static enum hci_status
3184 bthci_CmdAcceptPhysicalLink(struct rtw_adapter *padapter,
3185 struct packet_irp_hcicmd_data *pHciCmd)
3187 enum hci_status status;
3188 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3189 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3191 pBtDbg->dbgHciInfo.hciCmdCntAcceptPhyLink++;
3193 status = bthci_BuildPhysicalLink(padapter,
3194 pHciCmd, HCI_ACCEPT_PHYSICAL_LINK);
3199 static enum hci_status
3200 bthci_CmdDisconnectPhysicalLink(struct rtw_adapter *padapter,
3201 struct packet_irp_hcicmd_data *pHciCmd)
3203 enum hci_status status = HCI_STATUS_SUCCESS;
3204 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3205 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3206 u8 PLH, CurrentEntryNum, PhysLinkDisconnectReason;
3208 pBtDbg->dbgHciInfo.hciCmdCntDisconnectPhyLink++;
3210 PLH = *((u8 *)pHciCmd->Data);
3211 PhysLinkDisconnectReason = (*((u8 *)pHciCmd->Data+1));
3212 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK PhyHandle = 0x%x, Reason = 0x%x\n",
3213 PLH, PhysLinkDisconnectReason));
3215 CurrentEntryNum = bthci_GetCurrentEntryNum(padapter, PLH);
3217 if (CurrentEntryNum == 0xff) {
3218 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
3219 ("DisconnectPhysicalLink, No such Handle in the Entry\n"));
3220 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3222 pBTInfo->BtAsocEntry[CurrentEntryNum].PhyLinkDisconnectReason =
3223 (enum hci_status)PhysLinkDisconnectReason;
3225 /* Send HCI Command status event to AMP. */
3226 bthci_EventCommandStatus(padapter, LINK_CONTROL_COMMANDS,
3227 HCI_DISCONNECT_PHYSICAL_LINK, status);
3229 if (status != HCI_STATUS_SUCCESS)
3232 /* The macros below require { and } in the if statement */
3233 if (pBTInfo->BtAsocEntry[CurrentEntryNum].BtCurrentState == HCI_STATE_DISCONNECTED) {
3234 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3236 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3241 static enum hci_status
3242 bthci_CmdSetACLLinkDataFlowMode(struct rtw_adapter *padapter,
3243 struct packet_irp_hcicmd_data *pHciCmd)
3245 enum hci_status status = HCI_STATUS_SUCCESS;
3246 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3247 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3248 u8 localBuf[8] = "";
3251 struct packet_irp_hcievent_data *PPacketIrpEvent;
3254 pBtMgnt->ExtConfig.CurrentConnectHandle = *((u16 *)pHciCmd->Data);
3255 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = *((u8 *)pHciCmd->Data)+2;
3256 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = *((u8 *)pHciCmd->Data)+3;
3257 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Connection Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic mode = 0x%x",
3258 pBtMgnt->ExtConfig.CurrentConnectHandle,
3259 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode,
3260 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode));
3263 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3265 len += bthci_CommandCompleteHeader(&localBuf[0],
3267 HCI_SET_ACL_LINK_DATA_FLOW_MODE,
3270 /* Return parameters starts from here */
3271 pRetPar = &PPacketIrpEvent->Data[len];
3272 pRetPar[0] = status; /* status */
3274 pu2Temp = (u16 *)&pRetPar[1];
3275 *pu2Temp = pBtMgnt->ExtConfig.CurrentConnectHandle;
3277 PPacketIrpEvent->Length = len;
3279 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3283 static enum hci_status
3284 bthci_CmdSetACLLinkStatus(struct rtw_adapter *padapter,
3285 struct packet_irp_hcicmd_data *pHciCmd)
3287 enum hci_status status = HCI_STATUS_SUCCESS;
3288 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3289 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3290 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3294 pBtDbg->dbgHciInfo.hciCmdCntSetAclLinkStatus++;
3295 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "SetACLLinkStatus, Hex Data :\n",
3296 &pHciCmd->Data[0], pHciCmd->Length);
3298 /* Only Core Stack v251 and later version support this command. */
3299 pBtMgnt->bSupportProfile = true;
3301 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3302 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3304 pTriple = &pHciCmd->Data[1];
3305 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3306 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3307 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = pTriple[2];
3308 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = pTriple[3];
3309 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3310 ("Connection_Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic Mode = 0x%x\n",
3311 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3312 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode,
3313 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode));
3318 u8 localBuf[6] = "";
3321 struct packet_irp_hcievent_data *PPacketIrpEvent;
3323 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3325 len += bthci_CommandCompleteHeader(&localBuf[0],
3327 HCI_SET_ACL_LINK_STATUS,
3330 /* Return parameters starts from here */
3331 pRetPar = &PPacketIrpEvent->Data[len];
3332 pRetPar[0] = status; /* status */
3335 PPacketIrpEvent->Length = len;
3337 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3343 static enum hci_status
3344 bthci_CmdSetSCOLinkStatus(
3345 struct rtw_adapter *padapter,
3346 struct packet_irp_hcicmd_data *pHciCmd
3349 enum hci_status status = HCI_STATUS_SUCCESS;
3350 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3351 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3352 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3354 pBtDbg->dbgHciInfo.hciCmdCntSetScoLinkStatus++;
3355 pBtMgnt->ExtConfig.NumberOfSCO = *((u8 *)pHciCmd->Data);
3356 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfSCO = 0x%x\n",
3357 pBtMgnt->ExtConfig.NumberOfSCO));
3360 u8 localBuf[6] = "";
3363 struct packet_irp_hcievent_data *PPacketIrpEvent;
3365 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3367 len += bthci_CommandCompleteHeader(&localBuf[0],
3369 HCI_SET_SCO_LINK_STATUS,
3372 /* Return parameters starts from here */
3373 pRetPar = &PPacketIrpEvent->Data[len];
3374 pRetPar[0] = status; /* status */
3377 PPacketIrpEvent->Length = len;
3379 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3385 static enum hci_status
3386 bthci_CmdSetRSSIValue(
3387 struct rtw_adapter *padapter,
3388 struct packet_irp_hcicmd_data *pHciCmd
3391 enum hci_status status = HCI_STATUS_SUCCESS;
3392 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3393 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3396 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3397 if (pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle == *((u16 *)&pHciCmd->Data[0])) {
3398 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = (s8)(pHciCmd->Data[2]);
3399 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL,
3400 ("Connection_Handle = 0x%x, RSSI = %d \n",
3401 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3402 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI));
3404 /* get the minimum bt rssi value */
3405 if (pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI <= min_bt_rssi)
3406 min_bt_rssi = pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI;
3409 pBtMgnt->ExtConfig.MIN_BT_RSSI = min_bt_rssi;
3410 RTPRINT(FBT, BT_TRACE, ("[bt rssi], the min rssi is %d\n", min_bt_rssi));
3413 u8 localBuf[6] = "";
3416 struct packet_irp_hcievent_data *PPacketIrpEvent;
3418 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3420 len += bthci_CommandCompleteHeader(&localBuf[0],
3425 /* Return parameters starts from here */
3426 pRetPar = &PPacketIrpEvent->Data[len];
3427 pRetPar[0] = status; /* status */
3430 PPacketIrpEvent->Length = len;
3432 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3438 static enum hci_status
3439 bthci_CmdSetCurrentBluetoothStatus(
3440 struct rtw_adapter *padapter,
3441 struct packet_irp_hcicmd_data *pHciCmd
3444 enum hci_status status = HCI_STATUS_SUCCESS;
3445 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3446 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3447 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3449 pBtMgnt->ExtConfig.CurrentBTStatus = *((u8 *)&pHciCmd->Data[0]);
3450 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("SetCurrentBluetoothStatus, CurrentBTStatus = 0x%x\n",
3451 pBtMgnt->ExtConfig.CurrentBTStatus));
3454 u8 localBuf[6] = "";
3457 struct packet_irp_hcievent_data *PPacketIrpEvent;
3459 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3461 len += bthci_CommandCompleteHeader(&localBuf[0],
3463 HCI_SET_CURRENT_BLUETOOTH_STATUS,
3466 /* Return parameters starts from here */
3467 pRetPar = &PPacketIrpEvent->Data[len];
3468 pRetPar[0] = status; /* status */
3471 PPacketIrpEvent->Length = len;
3473 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3479 static enum hci_status
3480 bthci_CmdExtensionVersionNotify(
3481 struct rtw_adapter *padapter,
3482 struct packet_irp_hcicmd_data *pHciCmd
3485 enum hci_status status = HCI_STATUS_SUCCESS;
3486 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3487 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3488 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3490 pBtDbg->dbgHciInfo.hciCmdCntExtensionVersionNotify++;
3491 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "ExtensionVersionNotify, Hex Data :\n",
3492 &pHciCmd->Data[0], pHciCmd->Length);
3494 pBtMgnt->ExtConfig.HCIExtensionVer = *((u16 *)&pHciCmd->Data[0]);
3495 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = 0x%x\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3498 u8 localBuf[6] = "";
3501 struct packet_irp_hcievent_data *PPacketIrpEvent;
3503 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3505 len += bthci_CommandCompleteHeader(&localBuf[0],
3507 HCI_EXTENSION_VERSION_NOTIFY,
3510 /* Return parameters starts from here */
3511 pRetPar = &PPacketIrpEvent->Data[len];
3512 pRetPar[0] = status; /* status */
3515 PPacketIrpEvent->Length = len;
3517 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3523 static enum hci_status
3524 bthci_CmdLinkStatusNotify(
3525 struct rtw_adapter *padapter,
3526 struct packet_irp_hcicmd_data *pHciCmd
3529 enum hci_status status = HCI_STATUS_SUCCESS;
3530 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3531 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3532 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3536 pBtDbg->dbgHciInfo.hciCmdCntLinkStatusNotify++;
3537 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "LinkStatusNotify, Hex Data :\n",
3538 &pHciCmd->Data[0], pHciCmd->Length);
3540 /* Current only RTL8723 support this command. */
3541 pBtMgnt->bSupportProfile = true;
3543 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3544 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3545 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = %d\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3547 pTriple = &pHciCmd->Data[1];
3548 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3549 if (pBtMgnt->ExtConfig.HCIExtensionVer < 1) {
3550 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3551 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3552 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3553 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3554 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d\n",
3555 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3556 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3557 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec));
3559 } else if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
3560 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3561 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3562 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3563 pBtMgnt->ExtConfig.linkInfo[i].linkRole = pTriple[4];
3564 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3565 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d, LinkRole =%d\n",
3566 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3567 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3568 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec,
3569 pBtMgnt->ExtConfig.linkInfo[i].linkRole));
3574 BTHCI_UpdateBTProfileRTKToMoto(padapter);
3576 u8 localBuf[6] = "";
3579 struct packet_irp_hcievent_data *PPacketIrpEvent;
3581 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3583 len += bthci_CommandCompleteHeader(&localBuf[0],
3585 HCI_LINK_STATUS_NOTIFY,
3588 /* Return parameters starts from here */
3589 pRetPar = &PPacketIrpEvent->Data[len];
3590 pRetPar[0] = status; /* status */
3593 PPacketIrpEvent->Length = len;
3595 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3601 static enum hci_status
3602 bthci_CmdBtOperationNotify(
3603 struct rtw_adapter *padapter,
3604 struct packet_irp_hcicmd_data *pHciCmd
3607 enum hci_status status = HCI_STATUS_SUCCESS;
3608 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3609 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3611 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Bt Operation notify, Hex Data :\n",
3612 &pHciCmd->Data[0], pHciCmd->Length);
3614 pBtMgnt->ExtConfig.btOperationCode = *((u8 *)pHciCmd->Data);
3615 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("btOperationCode = 0x%x\n", pBtMgnt->ExtConfig.btOperationCode));
3616 switch (pBtMgnt->ExtConfig.btOperationCode) {
3617 case HCI_BT_OP_NONE:
3618 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Operation None!!\n"));
3620 case HCI_BT_OP_INQUIRY_START:
3621 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire start!!\n"));
3623 case HCI_BT_OP_INQUIRY_FINISH:
3624 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire finished!!\n"));
3626 case HCI_BT_OP_PAGING_START:
3627 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging is started!!\n"));
3629 case HCI_BT_OP_PAGING_SUCCESS:
3630 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete successfully!!\n"));
3632 case HCI_BT_OP_PAGING_UNSUCCESS:
3633 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete unsuccessfully!!\n"));
3635 case HCI_BT_OP_PAIRING_START:
3636 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing start!!\n"));
3638 case HCI_BT_OP_PAIRING_FINISH:
3639 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing finished!!\n"));
3641 case HCI_BT_OP_BT_DEV_ENABLE:
3642 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is enabled!!\n"));
3644 case HCI_BT_OP_BT_DEV_DISABLE:
3645 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is disabled!!\n"));
3648 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Unknown, error!!\n"));
3651 BTDM_AdjustForBtOperation(padapter);
3653 u8 localBuf[6] = "";
3656 struct packet_irp_hcievent_data *PPacketIrpEvent;
3658 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3660 len += bthci_CommandCompleteHeader(&localBuf[0],
3662 HCI_BT_OPERATION_NOTIFY,
3665 /* Return parameters starts from here */
3666 pRetPar = &PPacketIrpEvent->Data[len];
3667 pRetPar[0] = status; /* status */
3670 PPacketIrpEvent->Length = len;
3672 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3678 static enum hci_status
3679 bthci_CmdEnableWifiScanNotify(struct rtw_adapter *padapter,
3680 struct packet_irp_hcicmd_data *pHciCmd)
3682 enum hci_status status = HCI_STATUS_SUCCESS;
3683 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3684 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3686 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Enable Wifi scan notify, Hex Data :\n",
3687 &pHciCmd->Data[0], pHciCmd->Length);
3689 pBtMgnt->ExtConfig.bEnableWifiScanNotify = *((u8 *)pHciCmd->Data);
3690 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("bEnableWifiScanNotify = %d\n", pBtMgnt->ExtConfig.bEnableWifiScanNotify));
3693 u8 localBuf[6] = "";
3696 struct packet_irp_hcievent_data *PPacketIrpEvent;
3698 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3700 len += bthci_CommandCompleteHeader(&localBuf[0],
3702 HCI_ENABLE_WIFI_SCAN_NOTIFY,
3705 /* Return parameters starts from here */
3706 pRetPar = &PPacketIrpEvent->Data[len];
3707 pRetPar[0] = status; /* status */
3710 PPacketIrpEvent->Length = len;
3712 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3718 static enum hci_status
3719 bthci_CmdWIFICurrentChannel(struct rtw_adapter *padapter,
3720 struct packet_irp_hcicmd_data *pHciCmd)
3722 enum hci_status status = HCI_STATUS_SUCCESS;
3723 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3724 u8 chnl = pmlmeext->cur_channel;
3726 if (pmlmeext->cur_bwmode == HT_CHANNEL_WIDTH_40) {
3727 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
3729 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
3733 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current Channel = 0x%x\n", chnl));
3736 u8 localBuf[8] = "";
3739 struct packet_irp_hcievent_data *PPacketIrpEvent;
3741 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3743 len += bthci_CommandCompleteHeader(&localBuf[0],
3745 HCI_WIFI_CURRENT_CHANNEL,
3748 /* Return parameters starts from here */
3749 pRetPar = &PPacketIrpEvent->Data[len];
3750 pRetPar[0] = status; /* status */
3751 pRetPar[1] = chnl; /* current channel */
3753 PPacketIrpEvent->Length = len;
3755 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3761 static enum hci_status
3762 bthci_CmdWIFICurrentBandwidth(struct rtw_adapter *padapter,
3763 struct packet_irp_hcicmd_data *pHciCmd)
3765 enum hci_status status = HCI_STATUS_SUCCESS;
3766 enum ht_channel_width bw;
3769 bw = padapter->mlmeextpriv.cur_bwmode;
3771 if (bw == HT_CHANNEL_WIDTH_20)
3773 else if (bw == HT_CHANNEL_WIDTH_40)
3776 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current BW = 0x%x\n",
3780 u8 localBuf[8] = "";
3783 struct packet_irp_hcievent_data *PPacketIrpEvent;
3785 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3787 len += bthci_CommandCompleteHeader(&localBuf[0],
3789 HCI_WIFI_CURRENT_BANDWIDTH,
3792 /* Return parameters starts from here */
3793 pRetPar = &PPacketIrpEvent->Data[len];
3794 pRetPar[0] = status; /* status */
3795 pRetPar[1] = CurrentBW; /* current BW */
3797 PPacketIrpEvent->Length = len;
3799 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3805 static enum hci_status
3806 bthci_CmdWIFIConnectionStatus(
3807 struct rtw_adapter *padapter,
3808 struct packet_irp_hcicmd_data *pHciCmd
3811 enum hci_status status = HCI_STATUS_SUCCESS;
3812 u8 connectStatus = HCI_WIFI_NOT_CONNECTED;
3814 if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) {
3815 if (padapter->stapriv.asoc_sta_count >= 3)
3816 connectStatus = HCI_WIFI_CONNECTED;
3818 connectStatus = HCI_WIFI_NOT_CONNECTED;
3819 } else if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE|WIFI_ASOC_STATE)) {
3820 connectStatus = HCI_WIFI_CONNECTED;
3821 } else if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING)) {
3822 connectStatus = HCI_WIFI_CONNECT_IN_PROGRESS;
3824 connectStatus = HCI_WIFI_NOT_CONNECTED;
3828 u8 localBuf[8] = "";
3831 struct packet_irp_hcievent_data *PPacketIrpEvent;
3833 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3835 len += bthci_CommandCompleteHeader(&localBuf[0],
3837 HCI_WIFI_CONNECTION_STATUS,
3840 /* Return parameters starts from here */
3841 pRetPar = &PPacketIrpEvent->Data[len];
3842 pRetPar[0] = status; /* status */
3843 pRetPar[1] = connectStatus; /* connect status */
3845 PPacketIrpEvent->Length = len;
3847 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3853 static enum hci_status
3854 bthci_CmdEnableDeviceUnderTestMode(
3855 struct rtw_adapter *padapter,
3856 struct packet_irp_hcicmd_data *pHciCmd
3859 enum hci_status status = HCI_STATUS_SUCCESS;
3860 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3861 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3863 pBtHciInfo->bInTestMode = true;
3864 pBtHciInfo->bTestIsEnd = false;
3866 /* send command complete event here when all data are received. */
3868 u8 localBuf[6] = "";
3871 struct packet_irp_hcievent_data *PPacketIrpEvent;
3873 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3875 len += bthci_CommandCompleteHeader(&localBuf[0],
3876 OGF_TESTING_COMMANDS,
3877 HCI_ENABLE_DEVICE_UNDER_TEST_MODE,
3880 /* Return parameters starts from here */
3881 pRetPar = &PPacketIrpEvent->Data[len];
3882 pRetPar[0] = status; /* status */
3884 PPacketIrpEvent->Length = len;
3886 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3892 static enum hci_status
3893 bthci_CmdAMPTestEnd(struct rtw_adapter *padapter,
3894 struct packet_irp_hcicmd_data *pHciCmd)
3896 enum hci_status status = HCI_STATUS_SUCCESS;
3897 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3898 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3900 if (!pBtHciInfo->bInTestMode) {
3901 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3902 status = HCI_STATUS_CMD_DISALLOW;
3906 pBtHciInfo->bTestIsEnd = true;
3908 del_timer_sync(&pBTInfo->BTTestSendPacketTimer);
3910 rtl8723a_check_bssid(padapter, true);
3912 /* send command complete event here when all data are received. */
3914 u8 localBuf[4] = "";
3915 struct packet_irp_hcievent_data *PPacketIrpEvent;
3917 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3918 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3919 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3920 PPacketIrpEvent->Length = 2;
3922 PPacketIrpEvent->Data[0] = status;
3923 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario;
3925 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3928 bthci_EventAMPReceiverReport(padapter, 0x01);
3933 static enum hci_status
3934 bthci_CmdAMPTestCommand(struct rtw_adapter *padapter,
3935 struct packet_irp_hcicmd_data *pHciCmd)
3937 enum hci_status status = HCI_STATUS_SUCCESS;
3938 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3939 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3941 if (!pBtHciInfo->bInTestMode) {
3942 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3943 status = HCI_STATUS_CMD_DISALLOW;
3947 pBtHciInfo->TestScenario = *((u8 *)pHciCmd->Data);
3949 if (pBtHciInfo->TestScenario == 0x01)
3950 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
3951 else if (pBtHciInfo->TestScenario == 0x02)
3952 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
3954 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("No Such Test !!!!!!!!!!!!!!!!!! \n"));
3956 if (pBtHciInfo->bTestIsEnd) {
3957 u8 localBuf[5] = "";
3958 struct packet_irp_hcievent_data *PPacketIrpEvent;
3960 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3961 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3962 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3963 PPacketIrpEvent->Length = 2;
3965 PPacketIrpEvent->Data[0] = status;
3966 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
3968 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3970 /* Return to Idel state with RX and TX off. */
3975 /* should send command status event */
3976 bthci_EventCommandStatus(padapter,
3977 OGF_TESTING_COMMANDS,
3978 HCI_AMP_TEST_COMMAND,
3981 /* The HCI_AMP_Start Test Event shall be generated when the */
3982 /* HCI_AMP_Test_Command has completed and the first data is ready to be sent */
3986 u8 localBuf[5] = "";
3987 struct packet_irp_hcievent_data *PPacketIrpEvent;
3989 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_AMP_Start Test Event \n"));
3990 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3991 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_START_TEST;
3992 PPacketIrpEvent->Length = 2;
3994 PPacketIrpEvent->Data[0] = status;
3995 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
3997 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3999 /* Return to Idel state with RX and TX off. */
4002 if (pBtHciInfo->TestScenario == 0x01) {
4004 When in a transmitter test scenario and the frames/bursts count have been
4005 transmitted the HCI_AMP_Test_End event shall be sent.
4007 mod_timer(&pBTInfo->BTTestSendPacketTimer,
4008 jiffies + msecs_to_jiffies(50));
4009 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
4010 } else if (pBtHciInfo->TestScenario == 0x02) {
4011 rtl8723a_check_bssid(padapter, false);
4012 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
4018 static enum hci_status
4019 bthci_CmdEnableAMPReceiverReports(struct rtw_adapter *padapter,
4020 struct packet_irp_hcicmd_data *pHciCmd)
4022 enum hci_status status = HCI_STATUS_SUCCESS;
4023 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4024 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4026 if (!pBtHciInfo->bInTestMode) {
4027 status = HCI_STATUS_CMD_DISALLOW;
4028 /* send command complete event here when all data are received. */
4030 u8 localBuf[6] = "";
4033 struct packet_irp_hcievent_data *PPacketIrpEvent;
4035 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4037 len += bthci_CommandCompleteHeader(&localBuf[0],
4038 OGF_TESTING_COMMANDS,
4039 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4042 /* Return parameters starts from here */
4043 pRetPar = &PPacketIrpEvent->Data[len];
4044 pRetPar[0] = status; /* status */
4046 PPacketIrpEvent->Length = len;
4048 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4053 pBtHciInfo->bTestNeedReport = *((u8 *)pHciCmd->Data);
4054 pBtHciInfo->TestReportInterval = (*((u8 *)pHciCmd->Data+2));
4056 bthci_EventAMPReceiverReport(padapter, 0x00);
4058 /* send command complete event here when all data are received. */
4060 u8 localBuf[6] = "";
4063 struct packet_irp_hcievent_data *PPacketIrpEvent;
4065 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4067 len += bthci_CommandCompleteHeader(&localBuf[0],
4068 OGF_TESTING_COMMANDS,
4069 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4072 /* Return parameters starts from here */
4073 pRetPar = &PPacketIrpEvent->Data[len];
4074 pRetPar[0] = status; /* status */
4076 PPacketIrpEvent->Length = len;
4078 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4084 static enum hci_status
4085 bthci_CmdHostBufferSize(struct rtw_adapter *padapter,
4086 struct packet_irp_hcicmd_data *pHciCmd)
4088 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4089 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4090 struct packet_irp_hcievent_data *PPacketIrpEvent;
4091 enum hci_status status = HCI_STATUS_SUCCESS;
4092 u8 localBuf[6] = "";
4096 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].ACLPacketsData.ACLDataPacketLen = *((u16 *)pHciCmd->Data);
4097 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].SyncDataPacketLen = *((u8 *)(pHciCmd->Data+2));
4098 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalNumACLDataPackets = *((u16 *)(pHciCmd->Data+3));
4099 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalSyncNumDataPackets = *((u16 *)(pHciCmd->Data+5));
4101 /* send command complete event here when all data are received. */
4102 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4104 len += bthci_CommandCompleteHeader(&localBuf[0],
4105 OGF_SET_EVENT_MASK_COMMAND,
4106 HCI_HOST_BUFFER_SIZE,
4109 /* Return parameters starts from here */
4110 pRetPar = &PPacketIrpEvent->Data[len];
4111 pRetPar[0] = status; /* status */
4113 PPacketIrpEvent->Length = len;
4115 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4120 static enum hci_status
4121 bthci_UnknownCMD(struct rtw_adapter *padapter, struct packet_irp_hcicmd_data *pHciCmd)
4123 enum hci_status status = HCI_STATUS_UNKNOW_HCI_CMD;
4124 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4125 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
4127 pBtDbg->dbgHciInfo.hciCmdCntUnknown++;
4128 bthci_EventCommandStatus(padapter,
4136 static enum hci_status
4137 bthci_HandleOGFInformationalParameters(struct rtw_adapter *padapter,
4138 struct packet_irp_hcicmd_data *pHciCmd)
4140 enum hci_status status = HCI_STATUS_SUCCESS;
4142 switch (pHciCmd->OCF) {
4143 case HCI_READ_LOCAL_VERSION_INFORMATION:
4144 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_VERSION_INFORMATION\n"));
4145 status = bthci_CmdReadLocalVersionInformation(padapter);
4147 case HCI_READ_LOCAL_SUPPORTED_COMMANDS:
4148 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_COMMANDS\n"));
4149 status = bthci_CmdReadLocalSupportedCommands(padapter);
4151 case HCI_READ_LOCAL_SUPPORTED_FEATURES:
4152 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_FEATURES\n"));
4153 status = bthci_CmdReadLocalSupportedFeatures(padapter);
4155 case HCI_READ_BUFFER_SIZE:
4156 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BUFFER_SIZE\n"));
4157 status = bthci_CmdReadBufferSize(padapter);
4159 case HCI_READ_DATA_BLOCK_SIZE:
4160 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_DATA_BLOCK_SIZE\n"));
4161 status = bthci_CmdReadDataBlockSize(padapter);
4164 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFInformationalParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4165 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4166 status = bthci_UnknownCMD(padapter, pHciCmd);
4172 static enum hci_status
4173 bthci_HandleOGFSetEventMaskCMD(struct rtw_adapter *padapter,
4174 struct packet_irp_hcicmd_data *pHciCmd)
4176 enum hci_status status = HCI_STATUS_SUCCESS;
4178 switch (pHciCmd->OCF) {
4179 case HCI_SET_EVENT_MASK:
4180 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK\n"));
4181 status = bthci_CmdSetEventMask(padapter, pHciCmd);
4184 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET\n"));
4185 status = bthci_CmdReset(padapter, true);
4187 case HCI_READ_CONNECTION_ACCEPT_TIMEOUT:
4188 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_CONNECTION_ACCEPT_TIMEOUT\n"));
4189 status = bthci_CmdReadConnectionAcceptTimeout(padapter);
4191 case HCI_SET_EVENT_FILTER:
4192 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_FILTER\n"));
4194 case HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT:
4195 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT\n"));
4196 status = bthci_CmdWriteConnectionAcceptTimeout(padapter, pHciCmd);
4198 case HCI_READ_PAGE_TIMEOUT:
4199 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_PAGE_TIMEOUT\n"));
4200 status = bthci_CmdReadPageTimeout(padapter, pHciCmd);
4202 case HCI_WRITE_PAGE_TIMEOUT:
4203 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_PAGE_TIMEOUT\n"));
4204 status = bthci_CmdWritePageTimeout(padapter, pHciCmd);
4206 case HCI_HOST_NUMBER_OF_COMPLETED_PACKETS:
4207 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_NUMBER_OF_COMPLETED_PACKETS\n"));
4209 case HCI_READ_LINK_SUPERVISION_TIMEOUT:
4210 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_SUPERVISION_TIMEOUT\n"));
4211 status = bthci_CmdReadLinkSupervisionTimeout(padapter, pHciCmd);
4213 case HCI_WRITE_LINK_SUPERVISION_TIMEOUT:
4214 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LINK_SUPERVISION_TIMEOUT\n"));
4215 status = bthci_CmdWriteLinkSupervisionTimeout(padapter, pHciCmd);
4217 case HCI_ENHANCED_FLUSH:
4218 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENHANCED_FLUSH\n"));
4219 status = bthci_CmdEnhancedFlush(padapter, pHciCmd);
4221 case HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT:
4222 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4223 status = bthci_CmdReadLogicalLinkAcceptTimeout(padapter, pHciCmd);
4225 case HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT:
4226 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4227 status = bthci_CmdWriteLogicalLinkAcceptTimeout(padapter, pHciCmd);
4229 case HCI_SET_EVENT_MASK_PAGE_2:
4230 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK_PAGE_2\n"));
4231 status = bthci_CmdSetEventMaskPage2(padapter, pHciCmd);
4233 case HCI_READ_LOCATION_DATA:
4234 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCATION_DATA\n"));
4235 status = bthci_CmdReadLocationData(padapter, pHciCmd);
4237 case HCI_WRITE_LOCATION_DATA:
4238 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOCATION_DATA\n"));
4239 status = bthci_CmdWriteLocationData(padapter, pHciCmd);
4241 case HCI_READ_FLOW_CONTROL_MODE:
4242 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FLOW_CONTROL_MODE\n"));
4243 status = bthci_CmdReadFlowControlMode(padapter, pHciCmd);
4245 case HCI_WRITE_FLOW_CONTROL_MODE:
4246 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_FLOW_CONTROL_MODE\n"));
4247 status = bthci_CmdWriteFlowControlMode(padapter, pHciCmd);
4249 case HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT:
4250 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4251 status = bthci_CmdReadBestEffortFlushTimeout(padapter, pHciCmd);
4253 case HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT:
4254 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4255 status = bthci_CmdWriteBestEffortFlushTimeout(padapter, pHciCmd);
4257 case HCI_SHORT_RANGE_MODE:
4258 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SHORT_RANGE_MODE\n"));
4259 status = bthci_CmdShortRangeMode(padapter, pHciCmd);
4261 case HCI_HOST_BUFFER_SIZE:
4262 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_BUFFER_SIZE\n"));
4263 status = bthci_CmdHostBufferSize(padapter, pHciCmd);
4266 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFSetEventMaskCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4267 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4268 status = bthci_UnknownCMD(padapter, pHciCmd);
4274 static enum hci_status
4275 bthci_HandleOGFStatusParameters(struct rtw_adapter *padapter,
4276 struct packet_irp_hcicmd_data *pHciCmd)
4278 enum hci_status status = HCI_STATUS_SUCCESS;
4280 switch (pHciCmd->OCF) {
4281 case HCI_READ_FAILED_CONTACT_COUNTER:
4282 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FAILED_CONTACT_COUNTER\n"));
4283 status = bthci_CmdReadFailedContactCounter(padapter, pHciCmd);
4285 case HCI_RESET_FAILED_CONTACT_COUNTER:
4286 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET_FAILED_CONTACT_COUNTER\n"));
4287 status = bthci_CmdResetFailedContactCounter(padapter, pHciCmd);
4289 case HCI_READ_LINK_QUALITY:
4290 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_QUALITY\n"));
4291 status = bthci_CmdReadLinkQuality(padapter, pHciCmd);
4294 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_RSSI\n"));
4296 case HCI_READ_LOCAL_AMP_INFO:
4297 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_INFO\n"));
4298 status = bthci_CmdReadLocalAMPInfo(padapter);
4300 case HCI_READ_LOCAL_AMP_ASSOC:
4301 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_ASSOC\n"));
4302 status = bthci_CmdReadLocalAMPAssoc(padapter, pHciCmd);
4304 case HCI_WRITE_REMOTE_AMP_ASSOC:
4305 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_REMOTE_AMP_ASSOC\n"));
4306 status = bthci_CmdWriteRemoteAMPAssoc(padapter, pHciCmd);
4309 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFStatusParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4310 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4311 status = bthci_UnknownCMD(padapter, pHciCmd);
4317 static enum hci_status
4318 bthci_HandleOGFLinkControlCMD(struct rtw_adapter *padapter,
4319 struct packet_irp_hcicmd_data *pHciCmd)
4321 enum hci_status status = HCI_STATUS_SUCCESS;
4323 switch (pHciCmd->OCF) {
4324 case HCI_CREATE_PHYSICAL_LINK:
4325 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_PHYSICAL_LINK\n"));
4326 status = bthci_CmdCreatePhysicalLink(padapter, pHciCmd);
4328 case HCI_ACCEPT_PHYSICAL_LINK:
4329 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_PHYSICAL_LINK\n"));
4330 status = bthci_CmdAcceptPhysicalLink(padapter, pHciCmd);
4332 case HCI_DISCONNECT_PHYSICAL_LINK:
4333 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK\n"));
4334 status = bthci_CmdDisconnectPhysicalLink(padapter, pHciCmd);
4336 case HCI_CREATE_LOGICAL_LINK:
4337 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_LOGICAL_LINK\n"));
4338 status = bthci_CmdCreateLogicalLink(padapter, pHciCmd);
4340 case HCI_ACCEPT_LOGICAL_LINK:
4341 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_LOGICAL_LINK\n"));
4342 status = bthci_CmdAcceptLogicalLink(padapter, pHciCmd);
4344 case HCI_DISCONNECT_LOGICAL_LINK:
4345 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_LOGICAL_LINK\n"));
4346 status = bthci_CmdDisconnectLogicalLink(padapter, pHciCmd);
4348 case HCI_LOGICAL_LINK_CANCEL:
4349 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_LOGICAL_LINK_CANCEL\n"));
4350 status = bthci_CmdLogicalLinkCancel(padapter, pHciCmd);
4352 case HCI_FLOW_SPEC_MODIFY:
4353 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_FLOW_SPEC_MODIFY\n"));
4354 status = bthci_CmdFlowSpecModify(padapter, pHciCmd);
4357 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFLinkControlCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4358 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4359 status = bthci_UnknownCMD(padapter, pHciCmd);
4365 static enum hci_status
4366 bthci_HandleOGFTestingCMD(struct rtw_adapter *padapter,
4367 struct packet_irp_hcicmd_data *pHciCmd)
4369 enum hci_status status = HCI_STATUS_SUCCESS;
4370 switch (pHciCmd->OCF) {
4371 case HCI_ENABLE_DEVICE_UNDER_TEST_MODE:
4372 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_DEVICE_UNDER_TEST_MODE\n"));
4373 bthci_CmdEnableDeviceUnderTestMode(padapter, pHciCmd);
4375 case HCI_AMP_TEST_END:
4376 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_END\n"));
4377 bthci_CmdAMPTestEnd(padapter, pHciCmd);
4379 case HCI_AMP_TEST_COMMAND:
4380 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_COMMAND\n"));
4381 bthci_CmdAMPTestCommand(padapter, pHciCmd);
4383 case HCI_ENABLE_AMP_RECEIVER_REPORTS:
4384 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_AMP_RECEIVER_REPORTS\n"));
4385 bthci_CmdEnableAMPReceiverReports(padapter, pHciCmd);
4388 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4389 status = bthci_UnknownCMD(padapter, pHciCmd);
4395 static enum hci_status
4396 bthci_HandleOGFExtension(struct rtw_adapter *padapter,
4397 struct packet_irp_hcicmd_data *pHciCmd)
4399 enum hci_status status = HCI_STATUS_SUCCESS;
4400 switch (pHciCmd->OCF) {
4401 case HCI_SET_ACL_LINK_DATA_FLOW_MODE:
4402 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_DATA_FLOW_MODE\n"));
4403 status = bthci_CmdSetACLLinkDataFlowMode(padapter, pHciCmd);
4405 case HCI_SET_ACL_LINK_STATUS:
4406 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_STATUS\n"));
4407 status = bthci_CmdSetACLLinkStatus(padapter, pHciCmd);
4409 case HCI_SET_SCO_LINK_STATUS:
4410 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_SCO_LINK_STATUS\n"));
4411 status = bthci_CmdSetSCOLinkStatus(padapter, pHciCmd);
4413 case HCI_SET_RSSI_VALUE:
4414 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("HCI_SET_RSSI_VALUE\n"));
4415 status = bthci_CmdSetRSSIValue(padapter, pHciCmd);
4417 case HCI_SET_CURRENT_BLUETOOTH_STATUS:
4418 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_CURRENT_BLUETOOTH_STATUS\n"));
4419 status = bthci_CmdSetCurrentBluetoothStatus(padapter, pHciCmd);
4421 /* The following is for RTK8723 */
4423 case HCI_EXTENSION_VERSION_NOTIFY:
4424 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_EXTENSION_VERSION_NOTIFY\n"));
4425 status = bthci_CmdExtensionVersionNotify(padapter, pHciCmd);
4427 case HCI_LINK_STATUS_NOTIFY:
4428 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_LINK_STATUS_NOTIFY\n"));
4429 status = bthci_CmdLinkStatusNotify(padapter, pHciCmd);
4431 case HCI_BT_OPERATION_NOTIFY:
4432 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_BT_OPERATION_NOTIFY\n"));
4433 status = bthci_CmdBtOperationNotify(padapter, pHciCmd);
4435 case HCI_ENABLE_WIFI_SCAN_NOTIFY:
4436 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_ENABLE_WIFI_SCAN_NOTIFY\n"));
4437 status = bthci_CmdEnableWifiScanNotify(padapter, pHciCmd);
4440 /* The following is for IVT */
4441 case HCI_WIFI_CURRENT_CHANNEL:
4442 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_CHANNEL\n"));
4443 status = bthci_CmdWIFICurrentChannel(padapter, pHciCmd);
4445 case HCI_WIFI_CURRENT_BANDWIDTH:
4446 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_BANDWIDTH\n"));
4447 status = bthci_CmdWIFICurrentBandwidth(padapter, pHciCmd);
4449 case HCI_WIFI_CONNECTION_STATUS:
4450 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CONNECTION_STATUS\n"));
4451 status = bthci_CmdWIFIConnectionStatus(padapter, pHciCmd);
4455 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_UNKNOWN_COMMAND\n"));
4456 status = bthci_UnknownCMD(padapter, pHciCmd);
4463 bthci_StateStarting(struct rtw_adapter *padapter,
4464 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4466 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4467 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4469 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Starting], "));
4471 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4472 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4473 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4474 pBtMgnt->bNeedNotifyAMPNoCap = true;
4475 BTHCI_DisconnectPeer(padapter, EntryNum);
4477 case STATE_CMD_DISCONNECT_PHY_LINK:
4478 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4480 bthci_EventDisconnectPhyLinkComplete(padapter,
4482 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4485 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4487 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4489 BTHCI_DisconnectPeer(padapter, EntryNum);
4491 case STATE_CMD_MAC_START_COMPLETE:
4492 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_START_COMPLETE\n"));
4493 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR)
4494 bthci_EventChannelSelected(padapter, EntryNum);
4497 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4503 bthci_StateConnecting(struct rtw_adapter *padapter,
4504 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4506 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4507 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4509 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connecting], "));
4511 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4512 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4513 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4514 pBtMgnt->bNeedNotifyAMPNoCap = true;
4515 BTHCI_DisconnectPeer(padapter, EntryNum);
4517 case STATE_CMD_MAC_CONNECT_COMPLETE:
4518 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_COMPLETE\n"));
4520 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_JOINER) {
4521 RT_TRACE(_module_rtl871x_security_c_,
4522 _drv_info_, ("StateConnecting \n"));
4525 case STATE_CMD_DISCONNECT_PHY_LINK:
4526 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4528 bthci_EventDisconnectPhyLinkComplete(padapter,
4530 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4533 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4535 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4537 BTHCI_DisconnectPeer(padapter, EntryNum);
4540 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4541 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4542 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONTROLLER_BUSY;
4543 /* Because this state cmd is caused by the BTHCI_EventAMPStatusChange(), */
4544 /* we don't need to send event in the following BTHCI_DisconnectPeer() again. */
4545 pBtMgnt->bNeedNotifyAMPNoCap = false;
4546 BTHCI_DisconnectPeer(padapter, EntryNum);
4549 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4555 bthci_StateConnected(struct rtw_adapter *padapter,
4556 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4558 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4559 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4560 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4562 u16 logicHandle = 0;
4564 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connected], "));
4566 case STATE_CMD_DISCONNECT_PHY_LINK:
4567 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4569 /* When we are trying to disconnect the phy link, we should disconnect log link first, */
4570 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
4571 if (pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle != 0) {
4572 logicHandle = pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle;
4574 bthci_EventDisconnectLogicalLinkComplete(padapter, HCI_STATUS_SUCCESS,
4575 logicHandle, pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason);
4577 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle = 0;
4581 bthci_EventDisconnectPhyLinkComplete(padapter,
4583 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4586 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4588 BTHCI_DisconnectPeer(padapter, EntryNum);
4591 case STATE_CMD_MAC_DISCONNECT_INDICATE:
4592 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_DISCONNECT_INDICATE\n"));
4594 bthci_EventDisconnectPhyLinkComplete(padapter,
4596 /* TODO: Remote Host not local host */
4597 HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST,
4599 BTHCI_DisconnectPeer(padapter, EntryNum);
4602 case STATE_CMD_ENTER_STATE:
4603 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4605 if (pBtMgnt->bBTConnectInProgress) {
4606 pBtMgnt->bBTConnectInProgress = false;
4607 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4609 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_CONNECTED;
4610 pBTInfo->BtAsocEntry[EntryNum].b4waySuccess = true;
4611 pBtMgnt->bStartSendSupervisionPkt = true;
4613 /* for rate adaptive */
4615 rtl8723a_update_ramask(padapter,
4616 MAX_FW_SUPPORT_MACID_NUM-1-EntryNum, 0);
4618 HalSetBrateCfg23a(padapter, padapter->mlmepriv.cur_network.network.SupportedRates);
4619 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
4622 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4628 bthci_StateAuth(struct rtw_adapter *padapter, enum hci_state_with_cmd StateCmd,
4631 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4632 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4634 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Authenticating], "));
4636 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4637 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4638 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4639 pBtMgnt->bNeedNotifyAMPNoCap = true;
4640 BTHCI_DisconnectPeer(padapter, EntryNum);
4642 case STATE_CMD_DISCONNECT_PHY_LINK:
4643 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4644 bthci_EventDisconnectPhyLinkComplete(padapter,
4646 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4649 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4651 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4653 BTHCI_DisconnectPeer(padapter, EntryNum);
4655 case STATE_CMD_4WAY_FAILED:
4656 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_FAILED\n"));
4658 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_AUTH_FAIL;
4659 pBtMgnt->bNeedNotifyAMPNoCap = true;
4661 BTHCI_DisconnectPeer(padapter, EntryNum);
4663 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4665 case STATE_CMD_4WAY_SUCCESSED:
4666 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_SUCCESSED\n"));
4668 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_SUCCESS, EntryNum, INVALID_PL_HANDLE);
4670 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4672 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4675 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4681 bthci_StateDisconnecting(struct rtw_adapter *padapter,
4682 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4684 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4685 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4687 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnecting], "));
4689 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4690 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4691 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4692 bthci_EventPhysicalLinkComplete(padapter,
4693 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus,
4694 EntryNum, INVALID_PL_HANDLE);
4697 if (pBtMgnt->bBTConnectInProgress) {
4698 pBtMgnt->bBTConnectInProgress = false;
4699 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4702 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4704 case STATE_CMD_DISCONNECT_PHY_LINK:
4705 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4707 bthci_EventDisconnectPhyLinkComplete(padapter,
4709 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4712 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4714 BTHCI_DisconnectPeer(padapter, EntryNum);
4717 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4723 bthci_StateDisconnected(struct rtw_adapter *padapter,
4724 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4726 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4727 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4728 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4729 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4731 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnected], "));
4733 case STATE_CMD_CREATE_PHY_LINK:
4734 case STATE_CMD_ACCEPT_PHY_LINK:
4735 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4736 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CREATE_PHY_LINK\n"));
4738 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ACCEPT_PHY_LINK\n"));
4740 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], Disable IPS and LPS\n"));
4741 ips_leave23a(padapter);
4742 LPS_Leave23a(padapter);
4744 pBtMgnt->bPhyLinkInProgress = true;
4745 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
4746 pBtMgnt->CurrentBTConnectionCnt++;
4747 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d\n",
4748 pBtMgnt->CurrentBTConnectionCnt));
4749 pBtMgnt->BtOperationOn = true;
4750 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation ON!! CurrentConnectEntryNum = %d\n",
4751 pBtMgnt->CurrentConnectEntryNum));
4753 if (pBtMgnt->bBTConnectInProgress) {
4754 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONTROLLER_BUSY, INVALID_ENTRY_NUM, pBtMgnt->BtCurrentPhyLinkhandle);
4755 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4759 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4760 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_CREATOR;
4762 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_JOINER;
4764 /* 1. MAC not yet in selected channel */
4765 while (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)) {
4766 RTPRINT(FIOCTL, IOCTL_STATE, ("Scan/Roaming/Wifi Link is in Progress, wait 200 ms\n"));
4769 /* 2. MAC already in selected channel */
4770 RTPRINT(FIOCTL, IOCTL_STATE, ("Channel is Ready\n"));
4771 mod_timer(&pBTInfo->BTHCIJoinTimeoutTimer,
4772 jiffies + msecs_to_jiffies(pBtHciInfo->ConnAcceptTimeout));
4774 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = true;
4776 case STATE_CMD_DISCONNECT_PHY_LINK:
4777 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4779 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4781 bthci_EventDisconnectPhyLinkComplete(padapter,
4783 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4786 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4787 bthci_EventPhysicalLinkComplete(padapter,
4788 HCI_STATUS_UNKNOW_CONNECT_ID,
4789 EntryNum, INVALID_PL_HANDLE);
4792 if (pBtMgnt->bBTConnectInProgress) {
4793 pBtMgnt->bBTConnectInProgress = false;
4794 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4796 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4797 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4799 case STATE_CMD_ENTER_STATE:
4800 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4803 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4808 void BTHCI_EventParse(struct rtw_adapter *padapter, void *pEvntData, u32 dataLen)
4812 u8 BTHCI_HsConnectionEstablished(struct rtw_adapter *padapter)
4814 u8 bBtConnectionExist = false;
4815 struct bt_30info *pBtinfo = GET_BT_INFO(padapter);
4818 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
4819 if (pBtinfo->BtAsocEntry[i].b4waySuccess) {
4820 bBtConnectionExist = true;
4825 /*RTPRINT(FIOCTL, IOCTL_STATE, (" BTHCI_HsConnectionEstablished(), connection exist = %d\n", bBtConnectionExist)); */
4827 return bBtConnectionExist;
4831 BTHCI_CheckProfileExist(struct rtw_adapter *padapter,
4832 enum bt_traffic_mode_profile Profile)
4834 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4835 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4836 u8 IsPRofile = false;
4839 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4840 if (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile == Profile) {
4849 void BTHCI_UpdateBTProfileRTKToMoto(struct rtw_adapter *padapter)
4851 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4852 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4855 pBtMgnt->ExtConfig.NumberOfSCO = 0;
4857 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4858 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
4860 if (pBtMgnt->ExtConfig.linkInfo[i].BTProfile == BT_PROFILE_SCO)
4861 pBtMgnt->ExtConfig.NumberOfSCO++;
4863 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = pBtMgnt->ExtConfig.linkInfo[i].BTProfile;
4864 switch (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile) {
4865 case BT_PROFILE_SCO:
4867 case BT_PROFILE_PAN:
4868 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_BE;
4869 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4871 case BT_PROFILE_A2DP:
4872 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GULB;
4873 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_GULB;
4875 case BT_PROFILE_HID:
4876 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GUL;
4877 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4884 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RTK, NumberOfHandle = %d, NumberOfSCO = %d\n",
4885 pBtMgnt->ExtConfig.NumberOfHandle, pBtMgnt->ExtConfig.NumberOfSCO));
4888 void BTHCI_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
4890 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4891 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4893 if (pBtMgnt->ExtConfig.bEnableWifiScanNotify)
4894 bthci_EventExtWifiScanNotify(padapter, scanType);
4899 struct rtw_adapter *padapter,
4901 enum hci_state_with_cmd StateCmd,
4905 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4906 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4908 if (EntryNum == 0xff) {
4909 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, error EntryNum = 0x%x \n", EntryNum));
4912 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, EntryNum = 0x%x, CurrentState = 0x%x, BtNextState = 0x%x, StateCmd = 0x%x , StateToEnter = 0x%x\n",
4913 EntryNum, pBTInfo->BtAsocEntry[EntryNum].BtCurrentState, pBTInfo->BtAsocEntry[EntryNum].BtNextState, StateCmd, StateToEnter));
4915 if (pBTInfo->BtAsocEntry[EntryNum].BtNextState & StateToEnter) {
4916 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = StateToEnter;
4918 switch (StateToEnter) {
4919 case HCI_STATE_STARTING:
4920 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTING;
4921 bthci_StateStarting(padapter, StateCmd, EntryNum);
4923 case HCI_STATE_CONNECTING:
4924 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTING | HCI_STATE_DISCONNECTING | HCI_STATE_AUTHENTICATING;
4925 bthci_StateConnecting(padapter, StateCmd, EntryNum);
4927 case HCI_STATE_AUTHENTICATING:
4928 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTED;
4929 bthci_StateAuth(padapter, StateCmd, EntryNum);
4931 case HCI_STATE_CONNECTED:
4932 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTED | HCI_STATE_DISCONNECTING;
4933 bthci_StateConnected(padapter, StateCmd, EntryNum);
4935 case HCI_STATE_DISCONNECTING:
4936 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_DISCONNECTING;
4937 bthci_StateDisconnecting(padapter, StateCmd, EntryNum);
4939 case HCI_STATE_DISCONNECTED:
4940 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_STARTING | HCI_STATE_CONNECTING;
4941 bthci_StateDisconnected(padapter, StateCmd, EntryNum);
4944 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Unknown state to enter!!!\n"));
4948 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Wrong state to enter\n"));
4951 /* 20100325 Joseph: Disable/Enable IPS/LPS according to BT status. */
4952 if (!pBtMgnt->bBTConnectInProgress && !pBtMgnt->BtOperationOn) {
4953 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], ips_enter23a()\n"));
4954 ips_enter23a(padapter);
4958 void BTHCI_DisconnectPeer(struct rtw_adapter *padapter, u8 EntryNum)
4960 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4961 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4963 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" BTHCI_DisconnectPeer()\n"));
4965 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, EntryNum);
4967 if (pBTInfo->BtAsocEntry[EntryNum].bUsed) {
4968 /*BTPKT_SendDeauthentication(padapter, pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, unspec_reason); not porting yet */
4971 if (pBtMgnt->bBTConnectInProgress) {
4972 pBtMgnt->bBTConnectInProgress = false;
4973 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4976 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4978 if (pBtMgnt->bNeedNotifyAMPNoCap) {
4979 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT AMPStatus], set to invalid in BTHCI_DisconnectPeer()\n"));
4980 BTHCI_EventAMPStatusChange(padapter, AMP_STATUS_NO_CAPACITY_FOR_BT);
4984 void BTHCI_EventNumOfCompletedDataBlocks(struct rtw_adapter *padapter)
4986 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4987 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4988 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4989 u8 localBuf[TmpLocalBufSize] = "";
4990 u8 *pRetPar, *pTriple;
4991 u8 len = 0, i, j, handleNum = 0;
4992 struct packet_irp_hcievent_data *PPacketIrpEvent;
4993 u16 *pu2Temp, *pPackets, *pHandle, *pDblocks;
4996 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4998 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS)) {
4999 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Num Of Completed DataBlocks, Ignore to send NumOfCompletedDataBlocksEvent due to event mask page 2\n"));
5003 /* Return parameters starts from here */
5004 pRetPar = &PPacketIrpEvent->Data[0];
5005 pTriple = &pRetPar[3];
5006 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
5008 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
5009 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle) {
5011 pHandle = (u16 *)&pTriple[0]; /* Handle[i] */
5012 pPackets = (u16 *)&pTriple[2]; /* Num_Of_Completed_Packets[i] */
5013 pDblocks = (u16 *)&pTriple[4]; /* Num_Of_Completed_Blocks[i] */
5014 *pHandle = pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle;
5015 *pPackets = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5016 *pDblocks = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5017 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount) {
5019 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL,
5020 ("[BT event], Num Of Completed DataBlocks, Handle = 0x%x, Num_Of_Completed_Packets = 0x%x, Num_Of_Completed_Blocks = 0x%x\n",
5021 *pHandle, *pPackets, *pDblocks));
5023 pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount = 0;
5030 pRetPar[2] = handleNum; /* Number_of_Handles */
5032 pu2Temp = (u16 *)&pRetPar[0];
5033 *pu2Temp = BTTotalDataBlockNum;
5036 PPacketIrpEvent->EventCode = HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS;
5037 PPacketIrpEvent->Length = len;
5038 if (handleNum && sent)
5039 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
5042 void BTHCI_EventAMPStatusChange(struct rtw_adapter *padapter, u8 AMP_Status)
5044 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5045 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
5046 struct packet_irp_hcievent_data *PPacketIrpEvent;
5048 u8 localBuf[7] = "";
5051 if (AMP_Status == AMP_STATUS_NO_CAPACITY_FOR_BT) {
5052 pBtMgnt->BTNeedAMPStatusChg = true;
5053 pBtMgnt->bNeedNotifyAMPNoCap = false;
5055 BTHCI_DisconnectAll(padapter);
5056 } else if (AMP_Status == AMP_STATUS_FULL_CAPACITY_FOR_BT) {
5057 pBtMgnt->BTNeedAMPStatusChg = false;
5060 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5061 /* Return parameters starts from here */
5062 pRetPar = &PPacketIrpEvent->Data[0];
5064 pRetPar[0] = 0; /* Status */
5066 pRetPar[1] = AMP_Status; /* AMP_Status */
5069 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_STATUS_CHANGE;
5070 PPacketIrpEvent->Length = len;
5071 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS)
5072 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_STATE), ("[BT event], AMP Status Change, AMP_Status = %d\n", AMP_Status));
5075 void BTHCI_DisconnectAll(struct rtw_adapter *padapter)
5077 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5080 RTPRINT(FIOCTL, IOCTL_STATE, (" DisconnectALL()\n"));
5082 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
5083 if (pBTInfo->BtAsocEntry[i].b4waySuccess) {
5084 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, i);
5085 } else if (pBTInfo->BtAsocEntry[i].bUsed) {
5086 if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_CONNECTING) {
5087 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5088 } else if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_DISCONNECTING) {
5089 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5097 struct rtw_adapter *padapter,
5098 struct packet_irp_hcicmd_data *pHciCmd
5101 enum hci_status status = HCI_STATUS_SUCCESS;
5102 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5103 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
5105 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("\n"));
5106 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI Command start, OGF = 0x%x, OCF = 0x%x, Length = 0x%x\n",
5107 pHciCmd->OGF, pHciCmd->OCF, pHciCmd->Length));
5108 if (pHciCmd->Length) {
5109 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "HCI Command, Hex Data :\n",
5110 &pHciCmd->Data[0], pHciCmd->Length);
5112 if (pHciCmd->OGF == OGF_EXTENSION) {
5113 if (pHciCmd->OCF == HCI_SET_RSSI_VALUE)
5114 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("[BT cmd], "));
5116 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[BT cmd], "));
5118 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("[BT cmd], "));
5121 pBtDbg->dbgHciInfo.hciCmdCnt++;
5123 switch (pHciCmd->OGF) {
5124 case LINK_CONTROL_COMMANDS:
5125 status = bthci_HandleOGFLinkControlCMD(padapter, pHciCmd);
5127 case HOLD_MODE_COMMAND:
5129 case OGF_SET_EVENT_MASK_COMMAND:
5130 status = bthci_HandleOGFSetEventMaskCMD(padapter, pHciCmd);
5132 case OGF_INFORMATIONAL_PARAMETERS:
5133 status = bthci_HandleOGFInformationalParameters(padapter, pHciCmd);
5135 case OGF_STATUS_PARAMETERS:
5136 status = bthci_HandleOGFStatusParameters(padapter, pHciCmd);
5138 case OGF_TESTING_COMMANDS:
5139 status = bthci_HandleOGFTestingCMD(padapter, pHciCmd);
5142 status = bthci_HandleOGFExtension(padapter, pHciCmd);
5145 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI Command(), Unknown OGF = 0x%x\n", pHciCmd->OGF));
5146 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
5147 status = bthci_UnknownCMD(padapter, pHciCmd);
5150 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("HCI Command execution end!!\n"));
5155 /* ===== End of sync from SD7 driver COMMOM/bt_hci.c ===== */
5157 static const char *const BtStateString[] = {
5165 "BT_ACL_INQ_OR_PAG",
5166 "BT_STATE_NOT_DEFINED"
5169 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
5171 static void btdm_SetFwIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
5173 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5174 u8 H2C_Parameter[1] = {0};
5177 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Ignore Wlan_Act !!\n"));
5178 H2C_Parameter[0] |= BIT(0); /* function enable */
5179 pHalData->bt_coexist.bFWCoexistAllOff = false;
5181 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT don't ignore Wlan_Act !!\n"));
5184 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, write 0x25 = 0x%02x\n",
5187 FillH2CCmd(padapter, BT_IGNORE_WLAN_ACT_EID, 1, H2C_Parameter);
5190 static void btdm_NotifyFwScan(struct rtw_adapter *padapter, u8 scanType)
5192 u8 H2C_Parameter[1] = {0};
5194 if (scanType == true)
5195 H2C_Parameter[0] = 0x1;
5197 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Notify FW for wifi scan, write 0x3b = 0x%02x\n",
5200 FillH2CCmd(padapter, 0x3b, 1, H2C_Parameter);
5203 static void btdm_1AntSetPSMode(struct rtw_adapter *padapter,
5204 u8 enable, u8 smartps, u8 mode)
5206 struct pwrctrl_priv *pwrctrl;
5208 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current LPS(%s, %d), smartps =%d\n", enable == true?"ON":"OFF", mode, smartps));
5210 pwrctrl = &padapter->pwrctrlpriv;
5212 if (enable == true) {
5213 rtw_set_ps_mode23a(padapter, PS_MODE_MIN, smartps, mode);
5215 rtw_set_ps_mode23a(padapter, PS_MODE_ACTIVE, 0, 0);
5216 LPS_RF_ON_check23a(padapter, 100);
5220 static void btdm_1AntTSFSwitch(struct rtw_adapter *padapter, u8 enable)
5224 oldVal = rtl8723au_read8(padapter, 0x550);
5227 newVal = oldVal | EN_BCN_FUNCTION;
5229 newVal = oldVal & ~EN_BCN_FUNCTION;
5231 if (oldVal != newVal)
5232 rtl8723au_write8(padapter, 0x550, newVal);
5235 static u8 btdm_Is1AntPsTdmaStateChange(struct rtw_adapter *padapter)
5237 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5238 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5240 if ((pBtdm8723->bPrePsTdmaOn != pBtdm8723->bCurPsTdmaOn) ||
5241 (pBtdm8723->prePsTdma != pBtdm8723->curPsTdma))
5247 /* Before enter TDMA, make sure Power Saving is enable! */
5250 struct rtw_adapter *padapter,
5255 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5256 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5258 pBtdm8723->bCurPsTdmaOn = bTurnOn;
5259 pBtdm8723->curPsTdma = type;
5262 case 1: /* A2DP Level-1 or FTP/OPP */
5264 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5265 /* wide duration for WiFi */
5266 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x0, 0x58);
5269 case 2: /* A2DP Level-2 */
5270 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5271 /* normal duration for WiFi */
5272 BTDM_SetFw3a(padapter, 0xd3, 0x12, 0x12, 0x0, 0x58);
5275 case 3: /* BT FTP/OPP */
5276 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5277 /* normal duration for WiFi */
5278 BTDM_SetFw3a(padapter, 0xd3, 0x30, 0x03, 0x10, 0x58);
5282 case 4: /* for wifi scan & BT is connected */
5283 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5284 /* protect 3 beacons in 3-beacon period & no Tx pause at BT slot */
5285 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x0);
5288 case 5: /* for WiFi connected-busy & BT is Non-Connected-Idle */
5289 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5290 /* SCO mode, Ant fixed at WiFi, WLAN_Act toggle */
5291 BTDM_SetFw3a(padapter, 0x61, 0x15, 0x03, 0x31, 0x00);
5294 case 9: /* ACL high-retry type - 2 */
5295 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5296 /* narrow duration for WiFi */
5297 BTDM_SetFw3a(padapter, 0xd3, 0xa, 0xa, 0x0, 0x58); /* narrow duration for WiFi */
5300 case 10: /* for WiFi connect idle & BT ACL busy or WiFi Connected-Busy & BT is Inquiry */
5301 if (btdm_Is1AntPsTdmaStateChange(padapter))
5302 BTDM_SetFw3a(padapter, 0x13, 0xa, 0xa, 0x0, 0x40);
5304 case 11: /* ACL high-retry type - 3 */
5305 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5306 /* narrow duration for WiFi */
5307 BTDM_SetFw3a(padapter, 0xd3, 0x05, 0x05, 0x00, 0x58);
5310 case 12: /* for WiFi Connected-Busy & BT is Connected-Idle */
5311 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5312 /* Allow High-Pri BT */
5313 BTDM_SetFw3a(padapter, 0xeb, 0x0a, 0x03, 0x31, 0x18);
5316 case 20: /* WiFi only busy , TDMA mode for power saving */
5317 if (btdm_Is1AntPsTdmaStateChange(padapter))
5318 BTDM_SetFw3a(padapter, 0x13, 0x25, 0x25, 0x00, 0x00);
5320 case 27: /* WiFi DHCP/Site Survey & BT SCO busy */
5321 if (btdm_Is1AntPsTdmaStateChange(padapter))
5322 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x31, 0x98);
5324 case 28: /* WiFi DHCP/Site Survey & BT idle */
5325 if (btdm_Is1AntPsTdmaStateChange(padapter))
5326 BTDM_SetFw3a(padapter, 0x69, 0x25, 0x03, 0x31, 0x00);
5328 case 29: /* WiFi DHCP/Site Survey & BT ACL busy */
5329 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5330 BTDM_SetFw3a(padapter, 0xeb, 0x1a, 0x1a, 0x01, 0x18);
5331 rtl8723au_write32(padapter, 0x6c0, 0x5afa5afa);
5332 rtl8723au_write32(padapter, 0x6c4, 0x5afa5afa);
5335 case 30: /* WiFi idle & BT Inquiry */
5336 if (btdm_Is1AntPsTdmaStateChange(padapter))
5337 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x00);
5339 case 31: /* BT HID */
5340 if (btdm_Is1AntPsTdmaStateChange(padapter))
5341 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x58);
5343 case 32: /* BT SCO & Inquiry */
5344 if (btdm_Is1AntPsTdmaStateChange(padapter))
5345 BTDM_SetFw3a(padapter, 0xab, 0x0a, 0x03, 0x11, 0x98);
5347 case 33: /* BT SCO & WiFi site survey */
5348 if (btdm_Is1AntPsTdmaStateChange(padapter))
5349 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x30, 0x98);
5351 case 34: /* BT HID & WiFi site survey */
5352 if (btdm_Is1AntPsTdmaStateChange(padapter))
5353 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x18);
5355 case 35: /* BT HID & WiFi Connecting */
5356 if (btdm_Is1AntPsTdmaStateChange(padapter))
5357 BTDM_SetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x00, 0x18);
5361 /* disable PS-TDMA */
5364 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5365 /* Antenna control by PTA, 0x870 = 0x310 */
5366 BTDM_SetFw3a(padapter, 0x8, 0x0, 0x0, 0x0, 0x0);
5371 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5372 /* Antenna control by PTA, 0x870 = 0x310 */
5373 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5375 /* Switch Antenna to BT */
5376 rtl8723au_write16(padapter, 0x860, 0x210);
5377 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x210, Switch Antenna to BT\n"));
5380 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5381 /* Antenna control by PTA, 0x870 = 0x310 */
5382 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5384 /* Switch Antenna to WiFi */
5385 rtl8723au_write16(padapter, 0x860, 0x110);
5386 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x110, Switch Antenna to WiFi\n"));
5391 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current TDMA(%s, %d)\n",
5392 pBtdm8723->bCurPsTdmaOn?"ON":"OFF", pBtdm8723->curPsTdma));
5394 /* update pre state */
5395 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
5396 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
5400 _btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn, u8 smartps,
5401 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5403 struct pwrctrl_priv *pwrctrl;
5404 struct hal_data_8723a *pHalData;
5405 struct btdm_8723a_1ant *pBtdm8723;
5409 if (!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) &&
5410 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
5411 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5414 psOption &= ~BIT(0);
5416 RTPRINT(FBT, BT_TRACE,
5417 ("[BTCoex], Set LPS(%s, %d) TDMA(%s, %d)\n",
5418 bPSEn == true?"ON":"OFF", psOption,
5419 bTDMAOn == true?"ON":"OFF", tdmaType));
5421 pwrctrl = &padapter->pwrctrlpriv;
5422 pHalData = GET_HAL_DATA(padapter);
5423 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5426 if (pBtdm8723->bWiFiHalt) {
5427 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Halt!!\n"));
5431 if (pwrctrl->bInSuspend) {
5432 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Suspend!!\n"));
5436 if (padapter->bDriverStopped) {
5437 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi driver stopped!!\n"));
5441 if (padapter->bSurpriseRemoved) {
5442 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi Surprise Removed!!\n"));
5446 psMode = PS_MODE_MIN;
5448 psMode = PS_MODE_ACTIVE;
5452 if (psMode != pwrctrl->pwr_mode) {
5454 } else if (psMode != PS_MODE_ACTIVE) {
5455 if (psOption != pwrctrl->bcn_ant_mode)
5457 else if (smartps != pwrctrl->smart_ps)
5467 if (pBtdm8723->bCurPsTdmaOn) {
5469 btdm_1AntPsTdma(padapter, false, tdmaType);
5471 if (!rtl8723a_BT_enabled(padapter) ||
5472 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_NO_CONNECTION) ||
5473 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_CONNECT_IDLE) ||
5475 btdm_1AntPsTdma(padapter, false, 9);
5477 btdm_1AntPsTdma(padapter, false, 0);
5481 /* change Power Save State */
5482 btdm_1AntSetPSMode(padapter, bPSEn, smartps, psOption);
5485 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5489 btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn,
5490 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5492 _btdm_1AntSetPSTDMA(padapter, bPSEn, 0, psOption, bTDMAOn, tdmaType);
5495 static void btdm_1AntWifiParaAdjust(struct rtw_adapter *padapter, u8 bEnable)
5497 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5498 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5501 pBtdm8723->curWifiPara = 1;
5502 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5503 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_LOW_PENALTY);
5505 pBtdm8723->curWifiPara = 2;
5506 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5507 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_NORMAL);
5512 static void btdm_1AntPtaParaReload(struct rtw_adapter *padapter)
5515 rtl8723au_write8(padapter, 0x6cc, 0x0); /* 1-Ant coex */
5516 rtl8723au_write32(padapter, 0x6c8, 0xffff); /* wifi break table */
5517 rtl8723au_write32(padapter, 0x6c4, 0x55555555); /* coex table */
5519 /* Antenna switch control parameter */
5520 rtl8723au_write32(padapter, 0x858, 0xaaaaaaaa);
5521 if (IS_8723A_A_CUT(GET_HAL_DATA(padapter)->VersionID)) {
5522 /* SPDT(connected with TRSW) control by hardware PTA */
5523 rtl8723au_write32(padapter, 0x870, 0x0);
5524 rtl8723au_write8(padapter, 0x40, 0x24);
5526 rtl8723au_write8(padapter, 0x40, 0x20);
5527 /* set antenna at bt side if ANTSW is software control */
5528 rtl8723au_write16(padapter, 0x860, 0x210);
5529 /* SPDT(connected with TRSW) control by hardware PTA */
5530 rtl8723au_write32(padapter, 0x870, 0x300);
5531 /* ANTSW keep by GNT_BT */
5532 rtl8723au_write32(padapter, 0x874, 0x22804000);
5535 /* coexistence parameters */
5536 rtl8723au_write8(padapter, 0x778, 0x1); /* enable RTK mode PTA */
5538 /* BT don't ignore WLAN_Act */
5539 btdm_SetFwIgnoreWlanAct(padapter, false);
5544 *1: upgrade (add WiFi duration time)
5546 *-1: downgrade (add BT duration time)
5548 static s8 btdm_1AntTdmaJudgement(struct rtw_adapter *padapter, u8 retry)
5550 struct hal_data_8723a *pHalData;
5551 struct btdm_8723a_1ant *pBtdm8723;
5552 static s8 up, dn, m = 1, n = 3, WaitCount;
5555 pHalData = GET_HAL_DATA(padapter);
5556 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5559 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5570 /* no retry in the last 2-second duration */
5576 /* retry = 0 in consecutive 3m*(2s), add WiFi duration */
5584 } else if (retry <= 3) {
5585 /* retry<= 3 in the last 2-second duration */
5592 /* retry<= 3 in consecutive 2*(2s), minus WiFi duration (add BT duration) */
5595 /* record how many time downgrad WiFi duration */
5600 /* the max number of m is 20 */
5601 /* the longest time of upgrade WiFi duration is 20*3*2s = 120s */
5609 /* retry count > 3 */
5610 /* retry>3, minus WiFi duration (add BT duration) */
5613 /* record how many time downgrad WiFi duration */
5628 static void btdm_1AntTdmaDurationAdjustForACL(struct rtw_adapter *padapter)
5630 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5631 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5633 if (pBtdm8723->psTdmaGlobalCnt != pBtdm8723->psTdmaMonitorCnt) {
5634 pBtdm8723->psTdmaMonitorCnt = 0;
5635 pBtdm8723->psTdmaGlobalCnt = 0;
5637 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5638 btdm_1AntSetPSTDMA(padapter, true, 0, true, 2);
5639 pBtdm8723->psTdmaDuAdjType = 2;
5641 /* Now we only have 4 level Ps Tdma, */
5642 /* if that's not the following 4 level(will changed by wifi scan, dhcp...), */
5643 /* then we have to adjust it back to the previous record one. */
5644 if ((pBtdm8723->curPsTdma != 1) &&
5645 (pBtdm8723->curPsTdma != 2) &&
5646 (pBtdm8723->curPsTdma != 9) &&
5647 (pBtdm8723->curPsTdma != 11)) {
5648 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5652 judge = btdm_1AntTdmaJudgement(padapter, pHalData->bt_coexist.halCoex8723.btRetryCnt);
5654 if (pBtdm8723->curPsTdma == 1) {
5655 /* Decrease WiFi duration for high BT retry */
5656 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5657 pBtdm8723->psTdmaDuAdjType = 9;
5659 pBtdm8723->psTdmaDuAdjType = 2;
5660 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5661 } else if (pBtdm8723->curPsTdma == 2) {
5662 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5663 pBtdm8723->psTdmaDuAdjType = 9;
5664 } else if (pBtdm8723->curPsTdma == 9) {
5665 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5666 pBtdm8723->psTdmaDuAdjType = 11;
5668 } else if (judge == 1) {
5669 if (pBtdm8723->curPsTdma == 11) {
5670 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5671 pBtdm8723->psTdmaDuAdjType = 9;
5672 } else if (pBtdm8723->curPsTdma == 9) {
5673 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5674 pBtdm8723->psTdmaDuAdjType = 9;
5676 pBtdm8723->psTdmaDuAdjType = 2;
5677 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5678 } else if (pBtdm8723->curPsTdma == 2) {
5679 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5680 pBtdm8723->psTdmaDuAdjType = 9;
5682 pBtdm8723->psTdmaDuAdjType = 1;
5683 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5687 RTPRINT(FBT, BT_TRACE,
5688 ("[BTCoex], ACL current TDMA(%s, %d)\n",
5689 (pBtdm8723->bCurPsTdmaOn ? "ON" : "OFF"), pBtdm8723->curPsTdma));
5691 pBtdm8723->psTdmaMonitorCnt++;
5694 static void btdm_1AntCoexProcessForWifiConnect(struct rtw_adapter *padapter)
5696 struct mlme_priv *pmlmepriv;
5697 struct hal_data_8723a *pHalData;
5698 struct bt_coexist_8723a *pBtCoex;
5699 struct btdm_8723a_1ant *pBtdm8723;
5702 pmlmepriv = &padapter->mlmepriv;
5703 pHalData = GET_HAL_DATA(padapter);
5704 pBtCoex = &pHalData->bt_coexist.halCoex8723;
5705 pBtdm8723 = &pBtCoex->btdm1Ant;
5706 BtState = pBtCoex->c2hBtInfo;
5708 RTPRINT(FBT, BT_TRACE, ("[BTCoex], WiFi is %s\n",
5709 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
5710 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is %s\n",
5711 BtStateString[BtState]));
5713 padapter->pwrctrlpriv.btcoex_rfon = false;
5715 if (!BTDM_IsWifiBusy(padapter) &&
5716 !check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) &&
5717 (BtState == BT_INFO_STATE_NO_CONNECTION ||
5718 BtState == BT_INFO_STATE_CONNECT_IDLE)) {
5720 case BT_INFO_STATE_NO_CONNECTION:
5721 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 9);
5723 case BT_INFO_STATE_CONNECT_IDLE:
5724 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 0);
5729 case BT_INFO_STATE_NO_CONNECTION:
5730 case BT_INFO_STATE_CONNECT_IDLE:
5732 btdm_1AntSetPSTDMA(padapter, false, 0, true, 5);
5733 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5734 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5736 case BT_INFO_STATE_ACL_INQ_OR_PAG:
5737 RTPRINT(FBT, BT_TRACE,
5738 ("[BTCoex], BT PROFILE is "
5739 "BT_INFO_STATE_ACL_INQ_OR_PAG\n"));
5740 case BT_INFO_STATE_INQ_OR_PAG:
5741 padapter->pwrctrlpriv.btcoex_rfon = true;
5742 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
5744 case BT_INFO_STATE_SCO_ONLY_BUSY:
5745 case BT_INFO_STATE_ACL_SCO_BUSY:
5746 if (true == pBtCoex->bC2hBtInquiryPage)
5747 btdm_1AntSetPSTDMA(padapter, false, 0,
5750 #ifdef BTCOEX_CMCC_TEST
5751 btdm_1AntSetPSTDMA(padapter, false, 0,
5753 #else /* !BTCOEX_CMCC_TEST */
5754 btdm_1AntSetPSTDMA(padapter, false, 0,
5756 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5757 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5758 #endif /* !BTCOEX_CMCC_TEST */
5761 case BT_INFO_STATE_ACL_ONLY_BUSY:
5762 padapter->pwrctrlpriv.btcoex_rfon = true;
5763 if (pBtCoex->c2hBtProfile == BT_INFO_HID) {
5764 RTPRINT(FBT, BT_TRACE,
5765 ("[BTCoex], BT PROFILE is HID\n"));
5766 btdm_1AntSetPSTDMA(padapter, true, 0, true, 31);
5767 } else if (pBtCoex->c2hBtProfile == BT_INFO_FTP) {
5768 RTPRINT(FBT, BT_TRACE,
5769 ("[BTCoex], BT PROFILE is FTP/OPP\n"));
5770 btdm_1AntSetPSTDMA(padapter, true, 0, true, 3);
5771 } else if (pBtCoex->c2hBtProfile == (BT_INFO_A2DP|BT_INFO_FTP)) {
5772 RTPRINT(FBT, BT_TRACE,
5773 ("[BTCoex], BT PROFILE is A2DP_FTP\n"));
5774 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5776 if (pBtCoex->c2hBtProfile == BT_INFO_A2DP)
5777 RTPRINT(FBT, BT_TRACE,
5778 ("[BTCoex], BT PROFILE is "
5781 RTPRINT(FBT, BT_TRACE,
5782 ("[BTCoex], BT PROFILE is "
5783 "UNKNOWN(0x%02X)! Use A2DP "
5785 pBtCoex->c2hBtProfile));
5786 btdm_1AntTdmaDurationAdjustForACL(padapter);
5792 pBtdm8723->psTdmaGlobalCnt++;
5796 btdm_1AntUpdateHalRAMask(struct rtw_adapter *padapter, u32 mac_id, u32 filter)
5801 u8 shortGIrate = false;
5802 int supportRateNum = 0;
5803 struct sta_info *psta;
5804 struct hal_data_8723a *pHalData;
5805 struct dm_priv *pdmpriv;
5806 struct mlme_ext_priv *pmlmeext;
5807 struct mlme_ext_info *pmlmeinfo;
5808 struct wlan_bssid_ex *cur_network;
5810 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d, filter = 0x%08x!!\n",
5811 __func__, mac_id, filter));
5813 pHalData = GET_HAL_DATA(padapter);
5814 pdmpriv = &pHalData->dmpriv;
5815 pmlmeext = &padapter->mlmeextpriv;
5816 pmlmeinfo = &pmlmeext->mlmext_info;
5817 cur_network = &pmlmeinfo->network;
5819 if (mac_id >= NUM_STA) { /* CAM_SIZE */
5820 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d illegal!!\n",
5825 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
5827 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, Can't find station!!\n",
5835 case 0:/* for infra mode */
5837 rtw_get_rateset_len23a(cur_network->SupportedRates);
5838 mask = update_supported_rate23a(cur_network->SupportedRates,
5840 mask |= (pmlmeinfo->HT_enable) ?
5841 update_MSC_rate23a(&pmlmeinfo->ht_cap):0;
5842 if (support_short_GI23a(padapter, &pmlmeinfo->ht_cap))
5845 case 1:/* for broadcast/multicast */
5846 supportRateNum = rtw_get_rateset_len23a(
5847 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5848 mask = update_basic_rate23a(cur_network->SupportedRates,
5851 default: /* for each sta in IBSS */
5852 supportRateNum = rtw_get_rateset_len23a(
5853 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5854 mask = update_supported_rate23a(cur_network->SupportedRates,
5858 mask |= ((raid<<28)&0xf0000000);
5861 init_rate = get_highest_rate_idx23a(mask)&0x3f;
5863 if (pHalData->fw_ractrl) {
5866 arg = mac_id&0x1f;/* MACID */
5868 if (true == shortGIrate)
5871 RTPRINT(FBT, BT_TRACE,
5872 ("[BTCoex], Update FW RAID entry, MASK = 0x%08x, "
5873 "arg = 0x%02x\n", mask, arg));
5875 rtl8723a_set_raid_cmd(padapter, mask, arg);
5878 init_rate |= BIT(6);
5880 rtl8723au_write8(padapter, REG_INIDATA_RATE_SEL + mac_id,
5884 psta->init_rate = init_rate;
5885 pdmpriv->INIDATA_RATE[mac_id] = init_rate;
5889 btdm_1AntUpdateHalRAMaskForSCO(struct rtw_adapter *padapter, u8 forceUpdate)
5891 struct btdm_8723a_1ant *pBtdm8723;
5892 struct sta_priv *pstapriv;
5893 struct wlan_bssid_ex *cur_network;
5894 struct sta_info *psta;
5898 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5900 if (pBtdm8723->bRAChanged == true && forceUpdate == false)
5903 pstapriv = &padapter->stapriv;
5904 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5905 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5906 macid = psta->mac_id;
5908 filter |= BIT(_1M_RATE_);
5909 filter |= BIT(_2M_RATE_);
5910 filter |= BIT(_5M_RATE_);
5911 filter |= BIT(_11M_RATE_);
5912 filter |= BIT(_6M_RATE_);
5913 filter |= BIT(_9M_RATE_);
5915 btdm_1AntUpdateHalRAMask(padapter, macid, filter);
5917 pBtdm8723->bRAChanged = true;
5920 static void btdm_1AntRecoverHalRAMask(struct rtw_adapter *padapter)
5922 struct btdm_8723a_1ant *pBtdm8723;
5923 struct sta_priv *pstapriv;
5924 struct wlan_bssid_ex *cur_network;
5925 struct sta_info *psta;
5927 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5929 if (pBtdm8723->bRAChanged == false)
5932 pstapriv = &padapter->stapriv;
5933 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5934 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5936 Update_RA_Entry23a(padapter, psta);
5938 pBtdm8723->bRAChanged = false;
5942 btdm_1AntBTStateChangeHandler(struct rtw_adapter *padapter,
5943 enum bt_state_1ant oldState,
5944 enum bt_state_1ant newState)
5946 struct hal_data_8723a *phaldata;
5947 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT state change, %s => %s\n",
5948 BtStateString[oldState],
5949 BtStateString[newState]));
5951 /* BT default ignore wlan active, */
5952 /* WiFi MUST disable this when BT is enable */
5953 if (newState > BT_INFO_STATE_DISABLED)
5954 btdm_SetFwIgnoreWlanAct(padapter, false);
5956 if ((check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
5957 (BTDM_IsWifiConnectionExist(padapter))) {
5958 if ((newState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
5959 (newState == BT_INFO_STATE_ACL_SCO_BUSY)) {
5960 btdm_1AntUpdateHalRAMaskForSCO(padapter, false);
5962 /* Recover original RA setting */
5963 btdm_1AntRecoverHalRAMask(padapter);
5966 phaldata = GET_HAL_DATA(padapter);
5967 phaldata->bt_coexist.halCoex8723.btdm1Ant.bRAChanged = false;
5970 if (oldState == newState)
5973 if (oldState == BT_INFO_STATE_ACL_ONLY_BUSY) {
5974 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
5975 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCnt = 0;
5976 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
5979 if ((oldState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
5980 (oldState == BT_INFO_STATE_ACL_SCO_BUSY)) {
5981 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
5982 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
5985 /* Active 2Ant mechanism when BT Connected */
5986 if ((oldState == BT_INFO_STATE_DISABLED) ||
5987 (oldState == BT_INFO_STATE_NO_CONNECTION)) {
5988 if ((newState != BT_INFO_STATE_DISABLED) &&
5989 (newState != BT_INFO_STATE_NO_CONNECTION)) {
5990 BTDM_SetSwRfRxLpfCorner(padapter,
5991 BT_RF_RX_LPF_CORNER_SHRINK);
5992 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
5993 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
5996 if ((newState == BT_INFO_STATE_DISABLED) ||
5997 (newState == BT_INFO_STATE_NO_CONNECTION)) {
5998 BTDM_SetSwRfRxLpfCorner(padapter,
5999 BT_RF_RX_LPF_CORNER_RESUME);
6000 BTDM_AGCTable(padapter, BT_AGCTABLE_OFF);
6001 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_OFF);
6006 static void btdm_1AntBtCoexistHandler(struct rtw_adapter *padapter)
6008 struct hal_data_8723a *pHalData;
6009 struct bt_coexist_8723a *pBtCoex8723;
6010 struct btdm_8723a_1ant *pBtdm8723;
6012 pHalData = GET_HAL_DATA(padapter);
6013 pBtCoex8723 = &pHalData->bt_coexist.halCoex8723;
6014 pBtdm8723 = &pBtCoex8723->btdm1Ant;
6015 padapter->pwrctrlpriv.btcoex_rfon = false;
6016 if (!rtl8723a_BT_enabled(padapter)) {
6017 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is disabled\n"));
6019 if (BTDM_IsWifiConnectionExist(padapter)) {
6020 RTPRINT(FBT, BT_TRACE,
6021 ("[BTCoex], wifi is connected\n"));
6023 if (BTDM_IsWifiBusy(padapter)) {
6024 RTPRINT(FBT, BT_TRACE,
6025 ("[BTCoex], Wifi is busy\n"));
6026 btdm_1AntSetPSTDMA(padapter, false, 0,
6029 RTPRINT(FBT, BT_TRACE,
6030 ("[BTCoex], Wifi is idle\n"));
6031 _btdm_1AntSetPSTDMA(padapter, true, 2, 1,
6035 RTPRINT(FBT, BT_TRACE,
6036 ("[BTCoex], wifi is disconnected\n"));
6038 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6041 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is enabled\n"));
6043 if (BTDM_IsWifiConnectionExist(padapter)) {
6044 RTPRINT(FBT, BT_TRACE,
6045 ("[BTCoex], wifi is connected\n"));
6047 btdm_1AntWifiParaAdjust(padapter, true);
6048 btdm_1AntCoexProcessForWifiConnect(padapter);
6050 RTPRINT(FBT, BT_TRACE,
6051 ("[BTCoex], wifi is disconnected\n"));
6053 /* Antenna switch at BT side(0x870 = 0x300,
6054 0x860 = 0x210) after PSTDMA off */
6055 btdm_1AntWifiParaAdjust(padapter, false);
6056 btdm_1AntSetPSTDMA(padapter, false, 0, false, 0);
6060 btdm_1AntBTStateChangeHandler(padapter, pBtCoex8723->prec2hBtInfo,
6061 pBtCoex8723->c2hBtInfo);
6062 pBtCoex8723->prec2hBtInfo = pBtCoex8723->c2hBtInfo;
6065 void BTDM_1AntSignalCompensation(struct rtw_adapter *padapter,
6066 u8 *rssi_wifi, u8 *rssi_bt)
6068 struct hal_data_8723a *pHalData;
6069 struct btdm_8723a_1ant *pBtdm8723;
6070 u8 RSSI_WiFi_Cmpnstn, RSSI_BT_Cmpnstn;
6072 pHalData = GET_HAL_DATA(padapter);
6073 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
6074 RSSI_WiFi_Cmpnstn = 0;
6075 RSSI_BT_Cmpnstn = 0;
6077 switch (pBtdm8723->curPsTdma) {
6078 case 1: /* WiFi 52ms */
6079 RSSI_WiFi_Cmpnstn = 11; /* 22*0.48 */
6081 case 2: /* WiFi 36ms */
6082 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6084 case 9: /* WiFi 20ms */
6085 RSSI_WiFi_Cmpnstn = 18; /* 22*0.80 */
6087 case 11: /* WiFi 10ms */
6088 RSSI_WiFi_Cmpnstn = 20; /* 22*0.90 */
6090 case 4: /* WiFi 21ms */
6091 RSSI_WiFi_Cmpnstn = 17; /* 22*0.79 */
6093 case 16: /* WiFi 24ms */
6094 RSSI_WiFi_Cmpnstn = 18; /* 22*0.76 */
6096 case 18: /* WiFi 37ms */
6097 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6099 case 23: /* Level-1, Antenna switch to BT at all time */
6100 case 24: /* Level-2, Antenna switch to BT at all time */
6101 case 25: /* Level-3a, Antenna switch to BT at all time */
6102 case 26: /* Level-3b, Antenna switch to BT at all time */
6103 case 27: /* Level-3b, Antenna switch to BT at all time */
6104 case 33: /* BT SCO & WiFi site survey */
6105 RSSI_WiFi_Cmpnstn = 22;
6111 if (rssi_wifi && RSSI_WiFi_Cmpnstn) {
6112 RTPRINT(FBT, BT_TRACE,
6113 ("[BTCoex], 1AntSgnlCmpnstn, case %d, WiFiCmpnstn "
6114 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6115 RSSI_WiFi_Cmpnstn, *rssi_wifi,
6116 *rssi_wifi+RSSI_WiFi_Cmpnstn));
6117 *rssi_wifi += RSSI_WiFi_Cmpnstn;
6120 if (rssi_bt && RSSI_BT_Cmpnstn) {
6121 RTPRINT(FBT, BT_TRACE,
6122 ("[BTCoex], 1AntSgnlCmpnstn, case %d, BTCmpnstn "
6123 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6124 RSSI_BT_Cmpnstn, *rssi_bt, *rssi_bt+RSSI_BT_Cmpnstn));
6125 *rssi_bt += RSSI_BT_Cmpnstn;
6129 static void BTDM_1AntParaInit(struct rtw_adapter *padapter)
6131 struct hal_data_8723a *pHalData;
6132 struct bt_coexist_8723a *pBtCoex;
6133 struct btdm_8723a_1ant *pBtdm8723;
6135 pHalData = GET_HAL_DATA(padapter);
6136 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6137 pBtdm8723 = &pBtCoex->btdm1Ant;
6139 /* Enable counter statistics */
6140 rtl8723au_write8(padapter, 0x76e, 0x4);
6141 btdm_1AntPtaParaReload(padapter);
6143 pBtdm8723->wifiRssiThresh = 48;
6145 pBtdm8723->bWiFiHalt = false;
6146 pBtdm8723->bRAChanged = false;
6148 if ((pBtCoex->c2hBtInfo != BT_INFO_STATE_DISABLED) &&
6149 (pBtCoex->c2hBtInfo != BT_INFO_STATE_NO_CONNECTION)) {
6150 BTDM_SetSwRfRxLpfCorner(padapter, BT_RF_RX_LPF_CORNER_SHRINK);
6151 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6152 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6156 static void BTDM_1AntForHalt(struct rtw_adapter *padapter)
6158 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for halt\n"));
6160 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6163 btdm_1AntWifiParaAdjust(padapter, false);
6165 /* don't use btdm_1AntSetPSTDMA() here */
6166 /* it will call rtw_set_ps_mode23a() and request pwrpriv->lock. */
6167 /* This will lead to deadlock, if this function is called in IPS */
6168 /* Lucas@20130205 */
6169 btdm_1AntPsTdma(padapter, false, 0);
6171 btdm_SetFwIgnoreWlanAct(padapter, true);
6174 static void BTDM_1AntLpsLeave(struct rtw_adapter *padapter)
6176 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for LPS Leave\n"));
6178 /* Prevent from entering LPS again */
6179 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6182 btdm_1AntSetPSTDMA(padapter, false, 0, false, 8);
6183 /*btdm_1AntPsTdma(padapter, false, 8); */
6186 static void BTDM_1AntWifiAssociateNotify(struct rtw_adapter *padapter, u8 type)
6188 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6190 RTPRINT(FBT, BT_TRACE,
6191 ("\n[BTCoex], 1Ant for associate, type =%d\n", type));
6194 rtl8723a_CheckAntenna_Selection(padapter);
6195 if (!rtl8723a_BT_enabled(padapter))
6196 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6198 struct bt_coexist_8723a *pBtCoex;
6201 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6202 BtState = pBtCoex->c2hBtInfo;
6204 btdm_1AntTSFSwitch(padapter, true);
6206 if (BtState == BT_INFO_STATE_NO_CONNECTION ||
6207 BtState == BT_INFO_STATE_CONNECT_IDLE) {
6208 btdm_1AntSetPSTDMA(padapter, false, 0,
6210 } else if (BtState == BT_INFO_STATE_SCO_ONLY_BUSY ||
6211 BtState == BT_INFO_STATE_ACL_SCO_BUSY) {
6212 btdm_1AntSetPSTDMA(padapter, false, 0,
6214 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
6215 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
6216 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY ||
6217 BtState == BT_INFO_STATE_ACL_INQ_OR_PAG) {
6218 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6219 btdm_1AntSetPSTDMA(padapter, false, 0,
6222 btdm_1AntSetPSTDMA(padapter, false, 0,
6227 if (!rtl8723a_BT_enabled(padapter)) {
6228 if (!BTDM_IsWifiConnectionExist(padapter)) {
6229 btdm_1AntPsTdma(padapter, false, 0);
6230 btdm_1AntTSFSwitch(padapter, false);
6234 btdm_1AntBtCoexistHandler(padapter);
6239 BTDM_1AntMediaStatusNotify(struct rtw_adapter *padapter,
6240 enum rt_media_status mstatus)
6242 struct bt_coexist_8723a *pBtCoex;
6244 pBtCoex = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723;
6246 RTPRINT(FBT, BT_TRACE,
6247 ("\n\n[BTCoex]******************************\n"));
6248 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatus, WiFi %s !!\n",
6249 mstatus == RT_MEDIA_CONNECT?"CONNECT":"DISCONNECT"));
6250 RTPRINT(FBT, BT_TRACE, ("[BTCoex]******************************\n"));
6252 if (RT_MEDIA_CONNECT == mstatus) {
6253 if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) {
6254 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_SCO_ONLY_BUSY ||
6255 pBtCoex->c2hBtInfo == BT_INFO_STATE_ACL_SCO_BUSY)
6256 btdm_1AntUpdateHalRAMaskForSCO(padapter, true);
6259 padapter->pwrctrlpriv.DelayLPSLastTimeStamp = jiffies;
6260 BTDM_1AntForDhcp(padapter);
6262 /* DBG_8723A("%s rtl8723a_DeinitAntenna_Selection\n",
6264 rtl8723a_DeinitAntenna_Selection(padapter);
6265 btdm_1AntBtCoexistHandler(padapter);
6266 pBtCoex->btdm1Ant.bRAChanged = false;
6270 void BTDM_1AntForDhcp(struct rtw_adapter *padapter)
6272 struct hal_data_8723a *pHalData;
6274 struct bt_coexist_8723a *pBtCoex;
6275 struct btdm_8723a_1ant *pBtdm8723;
6277 pHalData = GET_HAL_DATA(padapter);
6278 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6279 BtState = pBtCoex->c2hBtInfo;
6280 pBtdm8723 = &pBtCoex->btdm1Ant;
6282 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for DHCP\n"));
6283 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, WiFi is %s\n",
6284 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6285 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, %s\n",
6286 BtStateString[BtState]));
6288 BTDM_1AntWifiAssociateNotify(padapter, true);
6291 static void BTDM_1AntWifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
6293 struct hal_data_8723a *pHalData;
6295 struct bt_coexist_8723a *pBtCoex;
6296 struct btdm_8723a_1ant *pBtdm8723;
6298 pHalData = GET_HAL_DATA(padapter);
6299 BtState = pHalData->bt_coexist.halCoex8723.c2hBtInfo;
6300 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6301 pBtdm8723 = &pBtCoex->btdm1Ant;
6303 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for wifi scan =%d!!\n",
6305 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, WiFi is %s\n",
6306 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6307 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, %s\n",
6308 BtStateString[BtState]));
6311 rtl8723a_CheckAntenna_Selection(padapter);
6312 if (!rtl8723a_BT_enabled(padapter)) {
6313 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6314 } else if (BTDM_IsWifiConnectionExist(padapter) == false) {
6315 BTDM_1AntWifiAssociateNotify(padapter, true);
6317 if ((BtState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6318 (BtState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6319 if (pBtCoex->bC2hBtInquiryPage) {
6320 btdm_1AntSetPSTDMA(padapter, false, 0,
6323 padapter->pwrctrlpriv.btcoex_rfon =
6325 btdm_1AntSetPSTDMA(padapter, true, 0,
6328 } else if (true == pBtCoex->bC2hBtInquiryPage) {
6329 padapter->pwrctrlpriv.btcoex_rfon = true;
6330 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
6331 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY) {
6332 padapter->pwrctrlpriv.btcoex_rfon = true;
6333 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6334 btdm_1AntSetPSTDMA(padapter, true, 0,
6337 btdm_1AntSetPSTDMA(padapter, true, 0,
6340 padapter->pwrctrlpriv.btcoex_rfon = true;
6341 btdm_1AntSetPSTDMA(padapter, true, 0, true, 5);
6345 btdm_NotifyFwScan(padapter, 1);
6347 /* WiFi_Finish_Scan */
6348 btdm_NotifyFwScan(padapter, 0);
6349 btdm_1AntBtCoexistHandler(padapter);
6353 static void BTDM_1AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
6355 struct hal_data_8723a *pHalData;
6356 struct bt_30info *pBTInfo;
6357 struct bt_mgnt *pBtMgnt;
6358 struct bt_coexist_8723a *pBtCoex;
6361 pHalData = GET_HAL_DATA(padapter);
6362 pBTInfo = GET_BT_INFO(padapter);
6363 pBtMgnt = &pBTInfo->BtMgnt;
6364 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6366 u1tmp = pBtCoex->c2hBtInfoOriginal;
6367 /* sco BUSY bit is not used on voice over PCM platform */
6368 btState = u1tmp & 0xF;
6369 pBtCoex->c2hBtProfile = u1tmp & 0xE0;
6371 /* default set bt to idle state. */
6372 pBtMgnt->ExtConfig.bBTBusy = false;
6373 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
6375 /* check BIT2 first ==> check if bt is under inquiry or page scan */
6376 if (btState & BIT(2))
6377 pBtCoex->bC2hBtInquiryPage = true;
6379 pBtCoex->bC2hBtInquiryPage = false;
6382 if (!(btState & BIT(0)))
6383 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
6386 pBtCoex->c2hBtInfo = BT_INFO_STATE_CONNECT_IDLE;
6387 else if (btState == 0x9) {
6388 if (pBtCoex->bC2hBtInquiryPage == true)
6389 pBtCoex->c2hBtInfo =
6390 BT_INFO_STATE_ACL_INQ_OR_PAG;
6392 pBtCoex->c2hBtInfo =
6393 BT_INFO_STATE_ACL_ONLY_BUSY;
6394 pBtMgnt->ExtConfig.bBTBusy = true;
6395 } else if (btState == 0x3) {
6396 pBtCoex->c2hBtInfo = BT_INFO_STATE_SCO_ONLY_BUSY;
6397 pBtMgnt->ExtConfig.bBTBusy = true;
6398 } else if (btState == 0xb) {
6399 pBtCoex->c2hBtInfo = BT_INFO_STATE_ACL_SCO_BUSY;
6400 pBtMgnt->ExtConfig.bBTBusy = true;
6402 pBtCoex->c2hBtInfo = BT_INFO_STATE_MAX;
6403 if (pBtMgnt->ExtConfig.bBTBusy)
6404 pHalData->bt_coexist.CurrentState &=
6405 ~BT_COEX_STATE_BT_IDLE;
6408 if (BT_INFO_STATE_NO_CONNECTION == pBtCoex->c2hBtInfo ||
6409 BT_INFO_STATE_CONNECT_IDLE == pBtCoex->c2hBtInfo) {
6410 if (pBtCoex->bC2hBtInquiryPage)
6411 pBtCoex->c2hBtInfo = BT_INFO_STATE_INQ_OR_PAG;
6414 RTPRINT(FBT, BT_TRACE, ("[BTC2H], %s(%d)\n",
6415 BtStateString[pBtCoex->c2hBtInfo], pBtCoex->c2hBtInfo));
6417 if (pBtCoex->c2hBtProfile != BT_INFO_HID)
6418 pBtCoex->c2hBtProfile &= ~BT_INFO_HID;
6421 void BTDM_1AntBtCoexist8723A(struct rtw_adapter *padapter)
6423 struct mlme_priv *pmlmepriv;
6424 struct hal_data_8723a *pHalData;
6425 unsigned long delta_time;
6427 pmlmepriv = &padapter->mlmepriv;
6428 pHalData = GET_HAL_DATA(padapter);
6430 if (check_fwstate(pmlmepriv, WIFI_SITE_MONITOR)) {
6431 /* already done in BTDM_1AntForScan() */
6432 RTPRINT(FBT, BT_TRACE,
6433 ("[BTCoex], wifi is under scan progress!!\n"));
6437 if (check_fwstate(pmlmepriv, WIFI_UNDER_LINKING)) {
6438 RTPRINT(FBT, BT_TRACE,
6439 ("[BTCoex], wifi is under link progress!!\n"));
6443 /* under DHCP(Special packet) */
6444 delta_time = jiffies - padapter->pwrctrlpriv.DelayLPSLastTimeStamp;
6445 delta_time = jiffies_to_msecs(delta_time);
6446 if (delta_time < 500) {
6447 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is under DHCP "
6448 "progress(%li ms)!!\n", delta_time));
6452 BTDM_CheckWiFiState(padapter);
6454 btdm_1AntBtCoexistHandler(padapter);
6457 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
6459 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
6461 /* local function start with btdm_ */
6462 static u8 btdm_ActionAlgorithm(struct rtw_adapter *padapter)
6464 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
6465 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
6466 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6467 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6468 u8 bScoExist = false, bBtLinkExist = false, bBtHsModeExist = false;
6469 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
6471 if (pBtMgnt->ExtConfig.NumberOfHandle)
6472 bBtLinkExist = true;
6473 if (pBtMgnt->ExtConfig.NumberOfSCO)
6475 if (BT_HsConnectionEstablished(padapter))
6476 bBtHsModeExist = true;
6478 /* here we get BT status first */
6480 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
6482 if ((bScoExist) || (bBtHsModeExist) ||
6483 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID))) {
6484 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO or HID or HS exists, set BT non-idle !!!\n"));
6485 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6488 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6489 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP))) {
6490 if (BTDM_BtTxRxCounterL(padapter) < 100) {
6491 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx < 100, set BT connected-idle!!!\n"));
6492 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6494 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx >= 100, set BT non-idle!!!\n"));
6495 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6499 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6500 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6501 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6502 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6503 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6505 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6506 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6507 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6508 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6509 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6513 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6514 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, set BT non-idle!!!\n"));
6515 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6518 /* Pan+A2dp profile */
6519 if ((pBtMgnt->ExtConfig.NumberOfHandle == 2) &&
6520 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) &&
6521 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6522 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6523 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6524 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6526 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6527 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6528 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6529 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6530 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6534 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6535 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, set BT non-idle!!!\n"));
6536 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6540 if (BT_2ANT_BT_STATUS_IDLE != pBtdm8723->btStatus)
6541 pBtMgnt->ExtConfig.bBTBusy = true;
6543 pBtMgnt->ExtConfig.bBTBusy = false;
6545 if (!bBtLinkExist) {
6546 RTPRINT(FBT, BT_TRACE, ("[BTCoex], No profile exists!!!\n"));
6550 if (pBtMgnt->ExtConfig.NumberOfHandle == 1) {
6552 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
6553 algorithm = BT_2ANT_COEX_ALGO_SCO;
6555 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6556 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID only\n"));
6557 algorithm = BT_2ANT_COEX_ALGO_HID;
6558 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6559 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP only\n"));
6560 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6561 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6562 if (bBtHsModeExist) {
6563 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(HS) only\n"));
6564 algorithm = BT_2ANT_COEX_ALGO_PANHS;
6566 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR) only\n"));
6567 algorithm = BT_2ANT_COEX_ALGO_PANEDR;
6570 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d \n",
6571 pBtMgnt->ExtConfig.NumberOfHandle));
6574 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 2) {
6576 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6577 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
6578 algorithm = BT_2ANT_COEX_ALGO_HID;
6579 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6580 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
6581 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6582 if (bBtHsModeExist) {
6583 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
6584 algorithm = BT_2ANT_COEX_ALGO_SCO;
6586 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
6587 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6590 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched ACL profile for NumberOfHandle =%d\n",
6591 pBtMgnt->ExtConfig.NumberOfHandle));
6594 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6595 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6596 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
6597 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6598 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6599 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6600 if (bBtHsModeExist) {
6601 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
6602 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6604 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
6605 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6607 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6608 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6609 if (bBtHsModeExist) {
6610 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
6611 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6613 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
6614 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
6617 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6618 pBtMgnt->ExtConfig.NumberOfHandle));
6621 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 3) {
6623 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6624 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6625 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP\n"));
6626 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6627 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6628 if (bBtHsModeExist) {
6629 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));
6630 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6632 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));
6633 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6635 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6636 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6637 if (bBtHsModeExist) {
6638 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(HS)\n"));
6639 algorithm = BT_2ANT_COEX_ALGO_SCO;
6641 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(EDR)\n"));
6644 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6645 pBtMgnt->ExtConfig.NumberOfHandle));
6648 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6649 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6650 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6651 if (bBtHsModeExist) {
6652 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
6653 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANHS;
6655 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
6656 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
6659 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6660 pBtMgnt->ExtConfig.NumberOfHandle));
6663 } else if (pBtMgnt->ExtConfig.NumberOfHandle >= 3) {
6665 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6666 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6667 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6669 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
6671 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(EDR)\n"));
6673 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6674 pBtMgnt->ExtConfig.NumberOfHandle));
6677 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6678 pBtMgnt->ExtConfig.NumberOfHandle));
6684 static u8 btdm_NeedToDecBtPwr(struct rtw_adapter *padapter)
6686 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6689 if (BT_Operation(padapter)) {
6690 if (pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB > 47) {
6691 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for HS mode!!\n"));
6694 RTPRINT(FBT, BT_TRACE, ("NO Need to decrease bt power for HS mode!!\n"));
6697 if (BTDM_IsWifiConnectionExist(padapter)) {
6698 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for Wifi is connected!!\n"));
6706 btdm_SetCoexTable(struct rtw_adapter *padapter, u32 val0x6c0,
6707 u32 val0x6c8, u8 val0x6cc)
6709 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c0 = 0x%x\n", val0x6c0));
6710 rtl8723au_write32(padapter, 0x6c0, val0x6c0);
6712 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c8 = 0x%x\n", val0x6c8));
6713 rtl8723au_write32(padapter, 0x6c8, val0x6c8);
6715 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6cc = 0x%x\n", val0x6cc));
6716 rtl8723au_write8(padapter, 0x6cc, val0x6cc);
6720 btdm_SetSwFullTimeDacSwing(struct rtw_adapter *padapter, u8 bSwDacSwingOn,
6723 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6725 if (bSwDacSwingOn) {
6726 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing = 0x%x\n", swDacSwingLvl));
6727 PHY_SetBBReg(padapter, 0x880, 0xff000000, swDacSwingLvl);
6728 pHalData->bt_coexist.bSWCoexistAllOff = false;
6730 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing Off!\n"));
6731 PHY_SetBBReg(padapter, 0x880, 0xff000000, 0xc0);
6736 btdm_SetFwDacSwingLevel(struct rtw_adapter *padapter, u8 dacSwingLvl)
6738 u8 H2C_Parameter[1] = {0};
6740 H2C_Parameter[0] = dacSwingLvl;
6742 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Set Dac Swing Level = 0x%x\n", dacSwingLvl));
6743 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write 0x29 = 0x%x\n", H2C_Parameter[0]));
6745 FillH2CCmd(padapter, 0x29, 1, H2C_Parameter);
6748 static void btdm_2AntDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
6750 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6751 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6753 RTPRINT(FBT, BT_TRACE,
6754 ("[BTCoex], Dec BT power = %s\n",
6755 ((bDecBtPwr) ? "ON" : "OFF")));
6756 pBtdm8723->bCurDecBtPwr = bDecBtPwr;
6758 if (pBtdm8723->bPreDecBtPwr == pBtdm8723->bCurDecBtPwr)
6761 BTDM_SetFwDecBtPwr(padapter, pBtdm8723->bCurDecBtPwr);
6763 pBtdm8723->bPreDecBtPwr = pBtdm8723->bCurDecBtPwr;
6767 btdm_2AntFwDacSwingLvl(struct rtw_adapter *padapter, u8 fwDacSwingLvl)
6769 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6770 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6772 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW Dac Swing level = %d\n", fwDacSwingLvl));
6773 pBtdm8723->curFwDacSwingLvl = fwDacSwingLvl;
6775 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preFwDacSwingLvl =%d, curFwDacSwingLvl =%d\n", */
6776 /*pBtdm8723->preFwDacSwingLvl, pBtdm8723->curFwDacSwingLvl)); */
6778 if (pBtdm8723->preFwDacSwingLvl == pBtdm8723->curFwDacSwingLvl)
6781 btdm_SetFwDacSwingLevel(padapter, pBtdm8723->curFwDacSwingLvl);
6783 pBtdm8723->preFwDacSwingLvl = pBtdm8723->curFwDacSwingLvl;
6787 btdm_2AntRfShrink(struct rtw_adapter *padapter, u8 bRxRfShrinkOn)
6789 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6790 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6792 RTPRINT(FBT, BT_TRACE,
6793 ("[BTCoex], turn Rx RF Shrink = %s\n",
6794 ((bRxRfShrinkOn) ? "ON" : "OFF")));
6795 pBtdm8723->bCurRfRxLpfShrink = bRxRfShrinkOn;
6797 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreRfRxLpfShrink =%d, bCurRfRxLpfShrink =%d\n", */
6798 /*pBtdm8723->bPreRfRxLpfShrink, pBtdm8723->bCurRfRxLpfShrink)); */
6800 if (pBtdm8723->bPreRfRxLpfShrink == pBtdm8723->bCurRfRxLpfShrink)
6803 BTDM_SetSwRfRxLpfCorner(padapter, (u8)pBtdm8723->bCurRfRxLpfShrink);
6805 pBtdm8723->bPreRfRxLpfShrink = pBtdm8723->bCurRfRxLpfShrink;
6809 btdm_2AntLowPenaltyRa(struct rtw_adapter *padapter, u8 bLowPenaltyRa)
6811 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6812 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6814 RTPRINT(FBT, BT_TRACE,
6815 ("[BTCoex], turn LowPenaltyRA = %s\n",
6816 ((bLowPenaltyRa) ? "ON" : "OFF")));
6817 pBtdm8723->bCurLowPenaltyRa = bLowPenaltyRa;
6819 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreLowPenaltyRa =%d, bCurLowPenaltyRa =%d\n", */
6820 /*pBtdm8723->bPreLowPenaltyRa, pBtdm8723->bCurLowPenaltyRa)); */
6822 if (pBtdm8723->bPreLowPenaltyRa == pBtdm8723->bCurLowPenaltyRa)
6825 BTDM_SetSwPenaltyTxRateAdaptive(padapter, (u8)pBtdm8723->bCurLowPenaltyRa);
6827 pBtdm8723->bPreLowPenaltyRa = pBtdm8723->bCurLowPenaltyRa;
6831 btdm_2AntDacSwing(struct rtw_adapter *padapter,
6832 u8 bDacSwingOn, u32 dacSwingLvl)
6834 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6835 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6837 RTPRINT(FBT, BT_TRACE,
6838 ("[BTCoex], turn DacSwing =%s, dacSwingLvl = 0x%x\n",
6839 (bDacSwingOn ? "ON" : "OFF"), dacSwingLvl));
6840 pBtdm8723->bCurDacSwingOn = bDacSwingOn;
6841 pBtdm8723->curDacSwingLvl = dacSwingLvl;
6843 if ((pBtdm8723->bPreDacSwingOn == pBtdm8723->bCurDacSwingOn) &&
6844 (pBtdm8723->preDacSwingLvl == pBtdm8723->curDacSwingLvl))
6848 btdm_SetSwFullTimeDacSwing(padapter, bDacSwingOn, dacSwingLvl);
6850 pBtdm8723->bPreDacSwingOn = pBtdm8723->bCurDacSwingOn;
6851 pBtdm8723->preDacSwingLvl = pBtdm8723->curDacSwingLvl;
6854 static void btdm_2AntAdcBackOff(struct rtw_adapter *padapter, u8 bAdcBackOff)
6856 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6857 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6859 RTPRINT(FBT, BT_TRACE,
6860 ("[BTCoex], turn AdcBackOff = %s\n",
6861 ((bAdcBackOff) ? "ON" : "OFF")));
6862 pBtdm8723->bCurAdcBackOff = bAdcBackOff;
6864 if (pBtdm8723->bPreAdcBackOff == pBtdm8723->bCurAdcBackOff)
6867 BTDM_BBBackOffLevel(padapter, (u8)pBtdm8723->bCurAdcBackOff);
6869 pBtdm8723->bPreAdcBackOff = pBtdm8723->bCurAdcBackOff;
6872 static void btdm_2AntAgcTable(struct rtw_adapter *padapter, u8 bAgcTableEn)
6874 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6875 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6877 RTPRINT(FBT, BT_TRACE,
6878 ("[BTCoex], %s Agc Table\n", ((bAgcTableEn) ? "Enable" : "Disable")));
6879 pBtdm8723->bCurAgcTableEn = bAgcTableEn;
6881 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreAgcTableEn =%d, bCurAgcTableEn =%d\n", */
6882 /*pBtdm8723->bPreAgcTableEn, pBtdm8723->bCurAgcTableEn)); */
6884 if (pBtdm8723->bPreAgcTableEn == pBtdm8723->bCurAgcTableEn)
6887 BTDM_AGCTable(padapter, (u8)bAgcTableEn);
6889 pBtdm8723->bPreAgcTableEn = pBtdm8723->bCurAgcTableEn;
6893 btdm_2AntCoexTable(struct rtw_adapter *padapter,
6894 u32 val0x6c0, u32 val0x6c8, u8 val0x6cc)
6896 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6897 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6899 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write Coex Table 0x6c0 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
6900 val0x6c0, val0x6c8, val0x6cc));
6901 pBtdm8723->curVal0x6c0 = val0x6c0;
6902 pBtdm8723->curVal0x6c8 = val0x6c8;
6903 pBtdm8723->curVal0x6cc = val0x6cc;
6905 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n", */
6906 /*pBtdm8723->preVal0x6c0, pBtdm8723->preVal0x6c8, pBtdm8723->preVal0x6cc)); */
6907 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n", */
6908 /*pBtdm8723->curVal0x6c0, pBtdm8723->curVal0x6c8, pBtdm8723->curVal0x6cc)); */
6910 if ((pBtdm8723->preVal0x6c0 == pBtdm8723->curVal0x6c0) &&
6911 (pBtdm8723->preVal0x6c8 == pBtdm8723->curVal0x6c8) &&
6912 (pBtdm8723->preVal0x6cc == pBtdm8723->curVal0x6cc))
6915 btdm_SetCoexTable(padapter, val0x6c0, val0x6c8, val0x6cc);
6917 pBtdm8723->preVal0x6c0 = pBtdm8723->curVal0x6c0;
6918 pBtdm8723->preVal0x6c8 = pBtdm8723->curVal0x6c8;
6919 pBtdm8723->preVal0x6cc = pBtdm8723->curVal0x6cc;
6922 static void btdm_2AntIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
6924 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6925 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6927 RTPRINT(FBT, BT_TRACE,
6928 ("[BTCoex], turn Ignore WlanAct %s\n", (bEnable ? "ON" : "OFF")));
6929 pBtdm8723->bCurIgnoreWlanAct = bEnable;
6932 if (pBtdm8723->bPreIgnoreWlanAct == pBtdm8723->bCurIgnoreWlanAct)
6935 btdm_SetFwIgnoreWlanAct(padapter, bEnable);
6936 pBtdm8723->bPreIgnoreWlanAct = pBtdm8723->bCurIgnoreWlanAct;
6940 btdm_2AntSetFw3a(struct rtw_adapter *padapter, u8 byte1, u8 byte2,
6941 u8 byte3, u8 byte4, u8 byte5)
6943 u8 H2C_Parameter[5] = {0};
6945 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6947 /* byte1[1:0] != 0 means enable pstdma */
6948 /* for 2Ant bt coexist, if byte1 != 0 means enable pstdma */
6950 pHalData->bt_coexist.bFWCoexistAllOff = false;
6951 H2C_Parameter[0] = byte1;
6952 H2C_Parameter[1] = byte2;
6953 H2C_Parameter[2] = byte3;
6954 H2C_Parameter[3] = byte4;
6955 H2C_Parameter[4] = byte5;
6957 pHalData->bt_coexist.fw3aVal[0] = byte1;
6958 pHalData->bt_coexist.fw3aVal[1] = byte2;
6959 pHalData->bt_coexist.fw3aVal[2] = byte3;
6960 pHalData->bt_coexist.fw3aVal[3] = byte4;
6961 pHalData->bt_coexist.fw3aVal[4] = byte5;
6963 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%x%08x\n",
6965 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
6967 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
6970 static void btdm_2AntPsTdma(struct rtw_adapter *padapter, u8 bTurnOn, u8 type)
6972 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6973 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6975 u8 bTurnOnByCnt = false;
6976 u8 psTdmaTypeByCnt = 0;
6978 btTxRxCnt = BTDM_BtTxRxCounterH(padapter)+BTDM_BtTxRxCounterL(padapter);
6979 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT TxRx Counters = %d\n", btTxRxCnt));
6980 if (btTxRxCnt > 3000) {
6981 bTurnOnByCnt = true;
6982 psTdmaTypeByCnt = 8;
6984 RTPRINT(FBT, BT_TRACE,
6985 ("[BTCoex], For BTTxRxCounters, turn %s PS TDMA, type =%d\n",
6986 (bTurnOnByCnt ? "ON" : "OFF"), psTdmaTypeByCnt));
6987 pBtdm8723->bCurPsTdmaOn = bTurnOnByCnt;
6988 pBtdm8723->curPsTdma = psTdmaTypeByCnt;
6990 RTPRINT(FBT, BT_TRACE,
6991 ("[BTCoex], turn %s PS TDMA, type =%d\n",
6992 (bTurnOn ? "ON" : "OFF"), type));
6993 pBtdm8723->bCurPsTdmaOn = bTurnOn;
6994 pBtdm8723->curPsTdma = type;
6997 if ((pBtdm8723->bPrePsTdmaOn == pBtdm8723->bCurPsTdmaOn) &&
6998 (pBtdm8723->prePsTdma == pBtdm8723->curPsTdma))
7005 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
7008 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
7011 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
7014 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0xa1, 0x80);
7017 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7020 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7023 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7026 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0x20, 0x80);
7029 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
7032 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
7035 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
7038 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7041 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7044 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7047 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7050 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0x20, 0x98);
7053 btdm_2AntSetFw3a(padapter, 0xa3, 0x2f, 0x2f, 0x20, 0x80);
7056 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7059 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0xa1, 0x98);
7062 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0x20, 0x98);
7066 /* disable PS tdma */
7069 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7072 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x0, 0x0);
7075 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7080 /* update pre state */
7081 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
7082 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
7085 static void btdm_2AntBtInquiryPage(struct rtw_adapter *padapter)
7087 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7088 btdm_2AntIgnoreWlanAct(padapter, false);
7089 btdm_2AntPsTdma(padapter, true, 8);
7092 static u8 btdm_HoldForBtInqPage(struct rtw_adapter *padapter)
7094 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7095 u32 curTime = jiffies;
7097 if (pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
7098 /* bt inquiry or page is started. */
7099 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime == 0) {
7100 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = curTime;
7101 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page is started at time : 0x%lx \n",
7102 pHalData->bt_coexist.halCoex8723.btInqPageStartTime));
7105 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page started time : 0x%lx, curTime : 0x%x \n",
7106 pHalData->bt_coexist.halCoex8723.btInqPageStartTime, curTime));
7108 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7109 if (((curTime - pHalData->bt_coexist.halCoex8723.btInqPageStartTime)/1000000) >= 10) {
7110 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page >= 10sec!!!"));
7111 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = 0;
7115 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7116 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7117 btdm_2AntIgnoreWlanAct(padapter, false);
7118 btdm_2AntPsTdma(padapter, true, 8);
7125 static u8 btdm_Is2Ant8723ACommonAction(struct rtw_adapter *padapter)
7127 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7128 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7131 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));
7133 if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7134 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7135 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7136 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt idle!!\n"));
7138 btdm_2AntLowPenaltyRa(padapter, false);
7139 btdm_2AntRfShrink(padapter, false);
7140 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7142 btdm_2AntIgnoreWlanAct(padapter, false);
7143 btdm_2AntPsTdma(padapter, false, 0);
7144 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7145 btdm_2AntDecBtPwr(padapter, false);
7147 btdm_2AntAgcTable(padapter, false);
7148 btdm_2AntAdcBackOff(padapter, false);
7149 btdm_2AntDacSwing(padapter, false, 0xc0);
7152 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7153 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7154 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7155 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT idle!!\n"));
7157 btdm_2AntLowPenaltyRa(padapter, true);
7158 btdm_2AntRfShrink(padapter, false);
7159 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7161 btdm_2AntIgnoreWlanAct(padapter, false);
7162 btdm_2AntPsTdma(padapter, false, 0);
7163 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7164 btdm_2AntDecBtPwr(padapter, true);
7166 btdm_2AntAgcTable(padapter, false);
7167 btdm_2AntAdcBackOff(padapter, false);
7168 btdm_2AntDacSwing(padapter, false, 0xc0);
7171 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7172 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7173 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7174 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt connected idle!!\n"));
7176 btdm_2AntLowPenaltyRa(padapter, true);
7177 btdm_2AntRfShrink(padapter, true);
7178 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7180 btdm_2AntIgnoreWlanAct(padapter, false);
7181 btdm_2AntPsTdma(padapter, false, 0);
7182 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7183 btdm_2AntDecBtPwr(padapter, false);
7185 btdm_2AntAgcTable(padapter, false);
7186 btdm_2AntAdcBackOff(padapter, false);
7187 btdm_2AntDacSwing(padapter, false, 0xc0);
7190 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7191 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7192 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7193 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + Bt connected idle!!\n"));
7195 btdm_2AntLowPenaltyRa(padapter, true);
7196 btdm_2AntRfShrink(padapter, true);
7197 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7199 btdm_2AntIgnoreWlanAct(padapter, false);
7200 btdm_2AntPsTdma(padapter, false, 0);
7201 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7202 btdm_2AntDecBtPwr(padapter, true);
7204 btdm_2AntAgcTable(padapter, false);
7205 btdm_2AntAdcBackOff(padapter, false);
7206 btdm_2AntDacSwing(padapter, false, 0xc0);
7209 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7210 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7211 (BT_2ANT_BT_STATUS_NON_IDLE == pBtdm8723->btStatus)) {
7212 RTPRINT(FBT, BT_TRACE, ("Wifi idle + BT non-idle!!\n"));
7214 btdm_2AntLowPenaltyRa(padapter, true);
7215 btdm_2AntRfShrink(padapter, true);
7216 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7218 btdm_2AntIgnoreWlanAct(padapter, false);
7219 btdm_2AntPsTdma(padapter, false, 0);
7220 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7221 btdm_2AntDecBtPwr(padapter, false);
7223 btdm_2AntAgcTable(padapter, false);
7224 btdm_2AntAdcBackOff(padapter, false);
7225 btdm_2AntDacSwing(padapter, false, 0xc0);
7229 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT non-idle!!\n"));
7230 btdm_2AntLowPenaltyRa(padapter, true);
7231 btdm_2AntRfShrink(padapter, true);
7232 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7233 btdm_2AntIgnoreWlanAct(padapter, false);
7234 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7242 btdm_2AntTdmaDurationAdjust(struct rtw_adapter *padapter, u8 bScoHid,
7243 u8 bTxPause, u8 maxInterval)
7245 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7246 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7247 static s32 up, dn, m, n, WaitCount;
7248 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
7251 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));
7253 if (pBtdm8723->bResetTdmaAdjust) {
7254 pBtdm8723->bResetTdmaAdjust = false;
7255 RTPRINT(FBT, BT_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
7258 if (maxInterval == 1) {
7259 btdm_2AntPsTdma(padapter, true, 15);
7260 pBtdm8723->psTdmaDuAdjType = 15;
7261 } else if (maxInterval == 2) {
7262 btdm_2AntPsTdma(padapter, true, 15);
7263 pBtdm8723->psTdmaDuAdjType = 15;
7264 } else if (maxInterval == 3) {
7265 btdm_2AntPsTdma(padapter, true, 15);
7266 pBtdm8723->psTdmaDuAdjType = 15;
7268 btdm_2AntPsTdma(padapter, true, 15);
7269 pBtdm8723->psTdmaDuAdjType = 15;
7272 if (maxInterval == 1) {
7273 btdm_2AntPsTdma(padapter, true, 11);
7274 pBtdm8723->psTdmaDuAdjType = 11;
7275 } else if (maxInterval == 2) {
7276 btdm_2AntPsTdma(padapter, true, 11);
7277 pBtdm8723->psTdmaDuAdjType = 11;
7278 } else if (maxInterval == 3) {
7279 btdm_2AntPsTdma(padapter, true, 11);
7280 pBtdm8723->psTdmaDuAdjType = 11;
7282 btdm_2AntPsTdma(padapter, true, 11);
7283 pBtdm8723->psTdmaDuAdjType = 11;
7288 if (maxInterval == 1) {
7289 btdm_2AntPsTdma(padapter, true, 7);
7290 pBtdm8723->psTdmaDuAdjType = 7;
7291 } else if (maxInterval == 2) {
7292 btdm_2AntPsTdma(padapter, true, 7);
7293 pBtdm8723->psTdmaDuAdjType = 7;
7294 } else if (maxInterval == 3) {
7295 btdm_2AntPsTdma(padapter, true, 7);
7296 pBtdm8723->psTdmaDuAdjType = 7;
7298 btdm_2AntPsTdma(padapter, true, 7);
7299 pBtdm8723->psTdmaDuAdjType = 7;
7302 if (maxInterval == 1) {
7303 btdm_2AntPsTdma(padapter, true, 3);
7304 pBtdm8723->psTdmaDuAdjType = 3;
7305 } else if (maxInterval == 2) {
7306 btdm_2AntPsTdma(padapter, true, 3);
7307 pBtdm8723->psTdmaDuAdjType = 3;
7308 } else if (maxInterval == 3) {
7309 btdm_2AntPsTdma(padapter, true, 3);
7310 pBtdm8723->psTdmaDuAdjType = 3;
7312 btdm_2AntPsTdma(padapter, true, 3);
7313 pBtdm8723->psTdmaDuAdjType = 3;
7324 /* accquire the BT TRx retry count from BT_Info byte2 */
7325 retryCount = pHalData->bt_coexist.halCoex8723.btRetryCnt;
7326 RTPRINT(FBT, BT_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));
7330 if (retryCount == 0) { /* no retry in the last 2-second duration */
7337 if (up >= n) { /* if ³sÄò n Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */
7343 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
7345 } else if (retryCount <= 3) { /* <= 3 retry in the last 2-second duration */
7352 if (dn == 2) { /* if ³sÄò 2 Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */
7354 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7358 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7366 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
7368 } else { /* retry count > 3, ¥un1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */
7370 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7374 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7381 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
7384 RTPRINT(FBT, BT_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));
7385 if (maxInterval == 1) {
7387 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7388 if (pBtdm8723->curPsTdma == 1) {
7389 btdm_2AntPsTdma(padapter, true, 5);
7390 pBtdm8723->psTdmaDuAdjType = 5;
7391 } else if (pBtdm8723->curPsTdma == 2) {
7392 btdm_2AntPsTdma(padapter, true, 6);
7393 pBtdm8723->psTdmaDuAdjType = 6;
7394 } else if (pBtdm8723->curPsTdma == 3) {
7395 btdm_2AntPsTdma(padapter, true, 7);
7396 pBtdm8723->psTdmaDuAdjType = 7;
7397 } else if (pBtdm8723->curPsTdma == 4) {
7398 btdm_2AntPsTdma(padapter, true, 8);
7399 pBtdm8723->psTdmaDuAdjType = 8;
7401 if (pBtdm8723->curPsTdma == 9) {
7402 btdm_2AntPsTdma(padapter, true, 13);
7403 pBtdm8723->psTdmaDuAdjType = 13;
7404 } else if (pBtdm8723->curPsTdma == 10) {
7405 btdm_2AntPsTdma(padapter, true, 14);
7406 pBtdm8723->psTdmaDuAdjType = 14;
7407 } else if (pBtdm8723->curPsTdma == 11) {
7408 btdm_2AntPsTdma(padapter, true, 15);
7409 pBtdm8723->psTdmaDuAdjType = 15;
7410 } else if (pBtdm8723->curPsTdma == 12) {
7411 btdm_2AntPsTdma(padapter, true, 16);
7412 pBtdm8723->psTdmaDuAdjType = 16;
7416 if (pBtdm8723->curPsTdma == 5) {
7417 btdm_2AntPsTdma(padapter, true, 6);
7418 pBtdm8723->psTdmaDuAdjType = 6;
7419 } else if (pBtdm8723->curPsTdma == 6) {
7420 btdm_2AntPsTdma(padapter, true, 7);
7421 pBtdm8723->psTdmaDuAdjType = 7;
7422 } else if (pBtdm8723->curPsTdma == 7) {
7423 btdm_2AntPsTdma(padapter, true, 8);
7424 pBtdm8723->psTdmaDuAdjType = 8;
7425 } else if (pBtdm8723->curPsTdma == 13) {
7426 btdm_2AntPsTdma(padapter, true, 14);
7427 pBtdm8723->psTdmaDuAdjType = 14;
7428 } else if (pBtdm8723->curPsTdma == 14) {
7429 btdm_2AntPsTdma(padapter, true, 15);
7430 pBtdm8723->psTdmaDuAdjType = 15;
7431 } else if (pBtdm8723->curPsTdma == 15) {
7432 btdm_2AntPsTdma(padapter, true, 16);
7433 pBtdm8723->psTdmaDuAdjType = 16;
7435 } else if (result == 1) {
7436 if (pBtdm8723->curPsTdma == 8) {
7437 btdm_2AntPsTdma(padapter, true, 7);
7438 pBtdm8723->psTdmaDuAdjType = 7;
7439 } else if (pBtdm8723->curPsTdma == 7) {
7440 btdm_2AntPsTdma(padapter, true, 6);
7441 pBtdm8723->psTdmaDuAdjType = 6;
7442 } else if (pBtdm8723->curPsTdma == 6) {
7443 btdm_2AntPsTdma(padapter, true, 5);
7444 pBtdm8723->psTdmaDuAdjType = 5;
7445 } else if (pBtdm8723->curPsTdma == 16) {
7446 btdm_2AntPsTdma(padapter, true, 15);
7447 pBtdm8723->psTdmaDuAdjType = 15;
7448 } else if (pBtdm8723->curPsTdma == 15) {
7449 btdm_2AntPsTdma(padapter, true, 14);
7450 pBtdm8723->psTdmaDuAdjType = 14;
7451 } else if (pBtdm8723->curPsTdma == 14) {
7452 btdm_2AntPsTdma(padapter, true, 13);
7453 pBtdm8723->psTdmaDuAdjType = 13;
7457 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7458 if (pBtdm8723->curPsTdma == 5) {
7459 btdm_2AntPsTdma(padapter, true, 1);
7460 pBtdm8723->psTdmaDuAdjType = 1;
7461 } else if (pBtdm8723->curPsTdma == 6) {
7462 btdm_2AntPsTdma(padapter, true, 2);
7463 pBtdm8723->psTdmaDuAdjType = 2;
7464 } else if (pBtdm8723->curPsTdma == 7) {
7465 btdm_2AntPsTdma(padapter, true, 3);
7466 pBtdm8723->psTdmaDuAdjType = 3;
7467 } else if (pBtdm8723->curPsTdma == 8) {
7468 btdm_2AntPsTdma(padapter, true, 4);
7469 pBtdm8723->psTdmaDuAdjType = 4;
7471 if (pBtdm8723->curPsTdma == 13) {
7472 btdm_2AntPsTdma(padapter, true, 9);
7473 pBtdm8723->psTdmaDuAdjType = 9;
7474 } else if (pBtdm8723->curPsTdma == 14) {
7475 btdm_2AntPsTdma(padapter, true, 10);
7476 pBtdm8723->psTdmaDuAdjType = 10;
7477 } else if (pBtdm8723->curPsTdma == 15) {
7478 btdm_2AntPsTdma(padapter, true, 11);
7479 pBtdm8723->psTdmaDuAdjType = 11;
7480 } else if (pBtdm8723->curPsTdma == 16) {
7481 btdm_2AntPsTdma(padapter, true, 12);
7482 pBtdm8723->psTdmaDuAdjType = 12;
7486 if (pBtdm8723->curPsTdma == 1) {
7487 btdm_2AntPsTdma(padapter, true, 2);
7488 pBtdm8723->psTdmaDuAdjType = 2;
7489 } else if (pBtdm8723->curPsTdma == 2) {
7490 btdm_2AntPsTdma(padapter, true, 3);
7491 pBtdm8723->psTdmaDuAdjType = 3;
7492 } else if (pBtdm8723->curPsTdma == 3) {
7493 btdm_2AntPsTdma(padapter, true, 4);
7494 pBtdm8723->psTdmaDuAdjType = 4;
7495 } else if (pBtdm8723->curPsTdma == 9) {
7496 btdm_2AntPsTdma(padapter, true, 10);
7497 pBtdm8723->psTdmaDuAdjType = 10;
7498 } else if (pBtdm8723->curPsTdma == 10) {
7499 btdm_2AntPsTdma(padapter, true, 11);
7500 pBtdm8723->psTdmaDuAdjType = 11;
7501 } else if (pBtdm8723->curPsTdma == 11) {
7502 btdm_2AntPsTdma(padapter, true, 12);
7503 pBtdm8723->psTdmaDuAdjType = 12;
7505 } else if (result == 1) {
7506 if (pBtdm8723->curPsTdma == 4) {
7507 btdm_2AntPsTdma(padapter, true, 3);
7508 pBtdm8723->psTdmaDuAdjType = 3;
7509 } else if (pBtdm8723->curPsTdma == 3) {
7510 btdm_2AntPsTdma(padapter, true, 2);
7511 pBtdm8723->psTdmaDuAdjType = 2;
7512 } else if (pBtdm8723->curPsTdma == 2) {
7513 btdm_2AntPsTdma(padapter, true, 1);
7514 pBtdm8723->psTdmaDuAdjType = 1;
7515 } else if (pBtdm8723->curPsTdma == 12) {
7516 btdm_2AntPsTdma(padapter, true, 11);
7517 pBtdm8723->psTdmaDuAdjType = 11;
7518 } else if (pBtdm8723->curPsTdma == 11) {
7519 btdm_2AntPsTdma(padapter, true, 10);
7520 pBtdm8723->psTdmaDuAdjType = 10;
7521 } else if (pBtdm8723->curPsTdma == 10) {
7522 btdm_2AntPsTdma(padapter, true, 9);
7523 pBtdm8723->psTdmaDuAdjType = 9;
7527 } else if (maxInterval == 2) {
7529 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7530 if (pBtdm8723->curPsTdma == 1) {
7531 btdm_2AntPsTdma(padapter, true, 6);
7532 pBtdm8723->psTdmaDuAdjType = 6;
7533 } else if (pBtdm8723->curPsTdma == 2) {
7534 btdm_2AntPsTdma(padapter, true, 6);
7535 pBtdm8723->psTdmaDuAdjType = 6;
7536 } else if (pBtdm8723->curPsTdma == 3) {
7537 btdm_2AntPsTdma(padapter, true, 7);
7538 pBtdm8723->psTdmaDuAdjType = 7;
7539 } else if (pBtdm8723->curPsTdma == 4) {
7540 btdm_2AntPsTdma(padapter, true, 8);
7541 pBtdm8723->psTdmaDuAdjType = 8;
7543 if (pBtdm8723->curPsTdma == 9) {
7544 btdm_2AntPsTdma(padapter, true, 14);
7545 pBtdm8723->psTdmaDuAdjType = 14;
7546 } else if (pBtdm8723->curPsTdma == 10) {
7547 btdm_2AntPsTdma(padapter, true, 14);
7548 pBtdm8723->psTdmaDuAdjType = 14;
7549 } else if (pBtdm8723->curPsTdma == 11) {
7550 btdm_2AntPsTdma(padapter, true, 15);
7551 pBtdm8723->psTdmaDuAdjType = 15;
7552 } else if (pBtdm8723->curPsTdma == 12) {
7553 btdm_2AntPsTdma(padapter, true, 16);
7554 pBtdm8723->psTdmaDuAdjType = 16;
7557 if (pBtdm8723->curPsTdma == 5) {
7558 btdm_2AntPsTdma(padapter, true, 6);
7559 pBtdm8723->psTdmaDuAdjType = 6;
7560 } else if (pBtdm8723->curPsTdma == 6) {
7561 btdm_2AntPsTdma(padapter, true, 7);
7562 pBtdm8723->psTdmaDuAdjType = 7;
7563 } else if (pBtdm8723->curPsTdma == 7) {
7564 btdm_2AntPsTdma(padapter, true, 8);
7565 pBtdm8723->psTdmaDuAdjType = 8;
7566 } else if (pBtdm8723->curPsTdma == 13) {
7567 btdm_2AntPsTdma(padapter, true, 14);
7568 pBtdm8723->psTdmaDuAdjType = 14;
7569 } else if (pBtdm8723->curPsTdma == 14) {
7570 btdm_2AntPsTdma(padapter, true, 15);
7571 pBtdm8723->psTdmaDuAdjType = 15;
7572 } else if (pBtdm8723->curPsTdma == 15) {
7573 btdm_2AntPsTdma(padapter, true, 16);
7574 pBtdm8723->psTdmaDuAdjType = 16;
7576 } else if (result == 1) {
7577 if (pBtdm8723->curPsTdma == 8) {
7578 btdm_2AntPsTdma(padapter, true, 7);
7579 pBtdm8723->psTdmaDuAdjType = 7;
7580 } else if (pBtdm8723->curPsTdma == 7) {
7581 btdm_2AntPsTdma(padapter, true, 6);
7582 pBtdm8723->psTdmaDuAdjType = 6;
7583 } else if (pBtdm8723->curPsTdma == 6) {
7584 btdm_2AntPsTdma(padapter, true, 6);
7585 pBtdm8723->psTdmaDuAdjType = 6;
7586 } else if (pBtdm8723->curPsTdma == 16) {
7587 btdm_2AntPsTdma(padapter, true, 15);
7588 pBtdm8723->psTdmaDuAdjType = 15;
7589 } else if (pBtdm8723->curPsTdma == 15) {
7590 btdm_2AntPsTdma(padapter, true, 14);
7591 pBtdm8723->psTdmaDuAdjType = 14;
7592 } else if (pBtdm8723->curPsTdma == 14) {
7593 btdm_2AntPsTdma(padapter, true, 14);
7594 pBtdm8723->psTdmaDuAdjType = 14;
7598 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7599 if (pBtdm8723->curPsTdma == 5) {
7600 btdm_2AntPsTdma(padapter, true, 2);
7601 pBtdm8723->psTdmaDuAdjType = 2;
7602 } else if (pBtdm8723->curPsTdma == 6) {
7603 btdm_2AntPsTdma(padapter, true, 2);
7604 pBtdm8723->psTdmaDuAdjType = 2;
7605 } else if (pBtdm8723->curPsTdma == 7) {
7606 btdm_2AntPsTdma(padapter, true, 3);
7607 pBtdm8723->psTdmaDuAdjType = 3;
7608 } else if (pBtdm8723->curPsTdma == 8) {
7609 btdm_2AntPsTdma(padapter, true, 4);
7610 pBtdm8723->psTdmaDuAdjType = 4;
7612 if (pBtdm8723->curPsTdma == 13) {
7613 btdm_2AntPsTdma(padapter, true, 10);
7614 pBtdm8723->psTdmaDuAdjType = 10;
7615 } else if (pBtdm8723->curPsTdma == 14) {
7616 btdm_2AntPsTdma(padapter, true, 10);
7617 pBtdm8723->psTdmaDuAdjType = 10;
7618 } else if (pBtdm8723->curPsTdma == 15) {
7619 btdm_2AntPsTdma(padapter, true, 11);
7620 pBtdm8723->psTdmaDuAdjType = 11;
7621 } else if (pBtdm8723->curPsTdma == 16) {
7622 btdm_2AntPsTdma(padapter, true, 12);
7623 pBtdm8723->psTdmaDuAdjType = 12;
7626 if (pBtdm8723->curPsTdma == 1) {
7627 btdm_2AntPsTdma(padapter, true, 2);
7628 pBtdm8723->psTdmaDuAdjType = 2;
7629 } else if (pBtdm8723->curPsTdma == 2) {
7630 btdm_2AntPsTdma(padapter, true, 3);
7631 pBtdm8723->psTdmaDuAdjType = 3;
7632 } else if (pBtdm8723->curPsTdma == 3) {
7633 btdm_2AntPsTdma(padapter, true, 4);
7634 pBtdm8723->psTdmaDuAdjType = 4;
7635 } else if (pBtdm8723->curPsTdma == 9) {
7636 btdm_2AntPsTdma(padapter, true, 10);
7637 pBtdm8723->psTdmaDuAdjType = 10;
7638 } else if (pBtdm8723->curPsTdma == 10) {
7639 btdm_2AntPsTdma(padapter, true, 11);
7640 pBtdm8723->psTdmaDuAdjType = 11;
7641 } else if (pBtdm8723->curPsTdma == 11) {
7642 btdm_2AntPsTdma(padapter, true, 12);
7643 pBtdm8723->psTdmaDuAdjType = 12;
7645 } else if (result == 1) {
7646 if (pBtdm8723->curPsTdma == 4) {
7647 btdm_2AntPsTdma(padapter, true, 3);
7648 pBtdm8723->psTdmaDuAdjType = 3;
7649 } else if (pBtdm8723->curPsTdma == 3) {
7650 btdm_2AntPsTdma(padapter, true, 2);
7651 pBtdm8723->psTdmaDuAdjType = 2;
7652 } else if (pBtdm8723->curPsTdma == 2) {
7653 btdm_2AntPsTdma(padapter, true, 2);
7654 pBtdm8723->psTdmaDuAdjType = 2;
7655 } else if (pBtdm8723->curPsTdma == 12) {
7656 btdm_2AntPsTdma(padapter, true, 11);
7657 pBtdm8723->psTdmaDuAdjType = 11;
7658 } else if (pBtdm8723->curPsTdma == 11) {
7659 btdm_2AntPsTdma(padapter, true, 10);
7660 pBtdm8723->psTdmaDuAdjType = 10;
7661 } else if (pBtdm8723->curPsTdma == 10) {
7662 btdm_2AntPsTdma(padapter, true, 10);
7663 pBtdm8723->psTdmaDuAdjType = 10;
7667 } else if (maxInterval == 3) {
7669 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7670 if (pBtdm8723->curPsTdma == 1) {
7671 btdm_2AntPsTdma(padapter, true, 7);
7672 pBtdm8723->psTdmaDuAdjType = 7;
7673 } else if (pBtdm8723->curPsTdma == 2) {
7674 btdm_2AntPsTdma(padapter, true, 7);
7675 pBtdm8723->psTdmaDuAdjType = 7;
7676 } else if (pBtdm8723->curPsTdma == 3) {
7677 btdm_2AntPsTdma(padapter, true, 7);
7678 pBtdm8723->psTdmaDuAdjType = 7;
7679 } else if (pBtdm8723->curPsTdma == 4) {
7680 btdm_2AntPsTdma(padapter, true, 8);
7681 pBtdm8723->psTdmaDuAdjType = 8;
7683 if (pBtdm8723->curPsTdma == 9) {
7684 btdm_2AntPsTdma(padapter, true, 15);
7685 pBtdm8723->psTdmaDuAdjType = 15;
7686 } else if (pBtdm8723->curPsTdma == 10) {
7687 btdm_2AntPsTdma(padapter, true, 15);
7688 pBtdm8723->psTdmaDuAdjType = 15;
7689 } else if (pBtdm8723->curPsTdma == 11) {
7690 btdm_2AntPsTdma(padapter, true, 15);
7691 pBtdm8723->psTdmaDuAdjType = 15;
7692 } else if (pBtdm8723->curPsTdma == 12) {
7693 btdm_2AntPsTdma(padapter, true, 16);
7694 pBtdm8723->psTdmaDuAdjType = 16;
7697 if (pBtdm8723->curPsTdma == 5) {
7698 btdm_2AntPsTdma(padapter, true, 7);
7699 pBtdm8723->psTdmaDuAdjType = 7;
7700 } else if (pBtdm8723->curPsTdma == 6) {
7701 btdm_2AntPsTdma(padapter, true, 7);
7702 pBtdm8723->psTdmaDuAdjType = 7;
7703 } else if (pBtdm8723->curPsTdma == 7) {
7704 btdm_2AntPsTdma(padapter, true, 8);
7705 pBtdm8723->psTdmaDuAdjType = 8;
7706 } else if (pBtdm8723->curPsTdma == 13) {
7707 btdm_2AntPsTdma(padapter, true, 15);
7708 pBtdm8723->psTdmaDuAdjType = 15;
7709 } else if (pBtdm8723->curPsTdma == 14) {
7710 btdm_2AntPsTdma(padapter, true, 15);
7711 pBtdm8723->psTdmaDuAdjType = 15;
7712 } else if (pBtdm8723->curPsTdma == 15) {
7713 btdm_2AntPsTdma(padapter, true, 16);
7714 pBtdm8723->psTdmaDuAdjType = 16;
7716 } else if (result == 1) {
7717 if (pBtdm8723->curPsTdma == 8) {
7718 btdm_2AntPsTdma(padapter, true, 7);
7719 pBtdm8723->psTdmaDuAdjType = 7;
7720 } else if (pBtdm8723->curPsTdma == 7) {
7721 btdm_2AntPsTdma(padapter, true, 7);
7722 pBtdm8723->psTdmaDuAdjType = 7;
7723 } else if (pBtdm8723->curPsTdma == 6) {
7724 btdm_2AntPsTdma(padapter, true, 7);
7725 pBtdm8723->psTdmaDuAdjType = 7;
7726 } else if (pBtdm8723->curPsTdma == 16) {
7727 btdm_2AntPsTdma(padapter, true, 15);
7728 pBtdm8723->psTdmaDuAdjType = 15;
7729 } else if (pBtdm8723->curPsTdma == 15) {
7730 btdm_2AntPsTdma(padapter, true, 15);
7731 pBtdm8723->psTdmaDuAdjType = 15;
7732 } else if (pBtdm8723->curPsTdma == 14) {
7733 btdm_2AntPsTdma(padapter, true, 15);
7734 pBtdm8723->psTdmaDuAdjType = 15;
7738 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7739 if (pBtdm8723->curPsTdma == 5) {
7740 btdm_2AntPsTdma(padapter, true, 3);
7741 pBtdm8723->psTdmaDuAdjType = 3;
7742 } else if (pBtdm8723->curPsTdma == 6) {
7743 btdm_2AntPsTdma(padapter, true, 3);
7744 pBtdm8723->psTdmaDuAdjType = 3;
7745 } else if (pBtdm8723->curPsTdma == 7) {
7746 btdm_2AntPsTdma(padapter, true, 3);
7747 pBtdm8723->psTdmaDuAdjType = 3;
7748 } else if (pBtdm8723->curPsTdma == 8) {
7749 btdm_2AntPsTdma(padapter, true, 4);
7750 pBtdm8723->psTdmaDuAdjType = 4;
7752 if (pBtdm8723->curPsTdma == 13) {
7753 btdm_2AntPsTdma(padapter, true, 11);
7754 pBtdm8723->psTdmaDuAdjType = 11;
7755 } else if (pBtdm8723->curPsTdma == 14) {
7756 btdm_2AntPsTdma(padapter, true, 11);
7757 pBtdm8723->psTdmaDuAdjType = 11;
7758 } else if (pBtdm8723->curPsTdma == 15) {
7759 btdm_2AntPsTdma(padapter, true, 11);
7760 pBtdm8723->psTdmaDuAdjType = 11;
7761 } else if (pBtdm8723->curPsTdma == 16) {
7762 btdm_2AntPsTdma(padapter, true, 12);
7763 pBtdm8723->psTdmaDuAdjType = 12;
7766 if (pBtdm8723->curPsTdma == 1) {
7767 btdm_2AntPsTdma(padapter, true, 3);
7768 pBtdm8723->psTdmaDuAdjType = 3;
7769 } else if (pBtdm8723->curPsTdma == 2) {
7770 btdm_2AntPsTdma(padapter, true, 3);
7771 pBtdm8723->psTdmaDuAdjType = 3;
7772 } else if (pBtdm8723->curPsTdma == 3) {
7773 btdm_2AntPsTdma(padapter, true, 4);
7774 pBtdm8723->psTdmaDuAdjType = 4;
7775 } else if (pBtdm8723->curPsTdma == 9) {
7776 btdm_2AntPsTdma(padapter, true, 11);
7777 pBtdm8723->psTdmaDuAdjType = 11;
7778 } else if (pBtdm8723->curPsTdma == 10) {
7779 btdm_2AntPsTdma(padapter, true, 11);
7780 pBtdm8723->psTdmaDuAdjType = 11;
7781 } else if (pBtdm8723->curPsTdma == 11) {
7782 btdm_2AntPsTdma(padapter, true, 12);
7783 pBtdm8723->psTdmaDuAdjType = 12;
7785 } else if (result == 1) {
7786 if (pBtdm8723->curPsTdma == 4) {
7787 btdm_2AntPsTdma(padapter, true, 3);
7788 pBtdm8723->psTdmaDuAdjType = 3;
7789 } else if (pBtdm8723->curPsTdma == 3) {
7790 btdm_2AntPsTdma(padapter, true, 3);
7791 pBtdm8723->psTdmaDuAdjType = 3;
7792 } else if (pBtdm8723->curPsTdma == 2) {
7793 btdm_2AntPsTdma(padapter, true, 3);
7794 pBtdm8723->psTdmaDuAdjType = 3;
7795 } else if (pBtdm8723->curPsTdma == 12) {
7796 btdm_2AntPsTdma(padapter, true, 11);
7797 pBtdm8723->psTdmaDuAdjType = 11;
7798 } else if (pBtdm8723->curPsTdma == 11) {
7799 btdm_2AntPsTdma(padapter, true, 11);
7800 pBtdm8723->psTdmaDuAdjType = 11;
7801 } else if (pBtdm8723->curPsTdma == 10) {
7802 btdm_2AntPsTdma(padapter, true, 11);
7803 pBtdm8723->psTdmaDuAdjType = 11;
7809 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type : recordPsTdma =%d\n", pBtdm8723->psTdmaDuAdjType));
7810 /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
7811 /* then we have to adjust it back to the previous record one. */
7812 if (pBtdm8723->curPsTdma != pBtdm8723->psTdmaDuAdjType) {
7813 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma =%d, recordPsTdma =%d\n",
7814 pBtdm8723->curPsTdma, pBtdm8723->psTdmaDuAdjType));
7816 if (!check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
7817 btdm_2AntPsTdma(padapter, true, pBtdm8723->psTdmaDuAdjType);
7819 RTPRINT(FBT, BT_TRACE, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
7823 /* default Action */
7824 /* SCO only or SCO+PAN(HS) */
7825 static void btdm_2Ant8723ASCOAction(struct rtw_adapter *padapter)
7827 u8 btRssiState, btRssiState1;
7829 if (btdm_NeedToDecBtPwr(padapter))
7830 btdm_2AntDecBtPwr(padapter, true);
7832 btdm_2AntDecBtPwr(padapter, false);
7834 if (BTDM_IsHT40(padapter)) {
7835 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7836 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7838 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7839 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7840 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7841 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7842 btdm_2AntPsTdma(padapter, true, 11);
7844 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7845 btdm_2AntPsTdma(padapter, true, 15);
7849 btdm_2AntAgcTable(padapter, false);
7850 btdm_2AntAdcBackOff(padapter, true);
7851 btdm_2AntDacSwing(padapter, false, 0xc0);
7853 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7854 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7855 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7858 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7859 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7860 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7861 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7862 btdm_2AntPsTdma(padapter, true, 11);
7864 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7865 btdm_2AntPsTdma(padapter, true, 15);
7869 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7870 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7871 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7872 btdm_2AntAgcTable(padapter, true);
7873 btdm_2AntAdcBackOff(padapter, true);
7874 btdm_2AntDacSwing(padapter, false, 0xc0);
7876 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7877 btdm_2AntAgcTable(padapter, false);
7878 btdm_2AntAdcBackOff(padapter, false);
7879 btdm_2AntDacSwing(padapter, false, 0xc0);
7884 static void btdm_2Ant8723AHIDAction(struct rtw_adapter *padapter)
7886 u8 btRssiState, btRssiState1;
7888 if (btdm_NeedToDecBtPwr(padapter))
7889 btdm_2AntDecBtPwr(padapter, true);
7891 btdm_2AntDecBtPwr(padapter, false);
7893 if (BTDM_IsHT40(padapter)) {
7894 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7895 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7897 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7898 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7899 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7900 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7901 btdm_2AntPsTdma(padapter, true, 9);
7903 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7904 btdm_2AntPsTdma(padapter, true, 13);
7908 btdm_2AntAgcTable(padapter, false);
7909 btdm_2AntAdcBackOff(padapter, false);
7910 btdm_2AntDacSwing(padapter, false, 0xc0);
7912 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7913 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7914 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7917 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7918 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7919 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7920 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7921 btdm_2AntPsTdma(padapter, true, 9);
7923 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7924 btdm_2AntPsTdma(padapter, true, 13);
7928 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7929 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7930 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7931 btdm_2AntAgcTable(padapter, true);
7932 btdm_2AntAdcBackOff(padapter, true);
7933 btdm_2AntDacSwing(padapter, false, 0xc0);
7935 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7936 btdm_2AntAgcTable(padapter, false);
7937 btdm_2AntAdcBackOff(padapter, false);
7938 btdm_2AntDacSwing(padapter, false, 0xc0);
7943 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
7944 static void btdm_2Ant8723AA2DPAction(struct rtw_adapter *padapter)
7946 u8 btRssiState, btRssiState1;
7947 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7948 u8 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
7950 if (btdm_NeedToDecBtPwr(padapter))
7951 btdm_2AntDecBtPwr(padapter, true);
7953 btdm_2AntDecBtPwr(padapter, false);
7955 if (BTDM_IsHT40(padapter)) {
7956 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7957 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7960 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7961 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7962 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7963 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7965 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7966 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7967 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
7969 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7970 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
7973 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7974 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7975 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7976 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
7978 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7979 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
7984 btdm_2AntAgcTable(padapter, false);
7985 btdm_2AntAdcBackOff(padapter, true);
7986 btdm_2AntDacSwing(padapter, false, 0xc0);
7988 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7989 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7990 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7993 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7994 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7995 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7996 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7997 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7998 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7999 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
8001 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8002 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8005 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8006 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8007 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8008 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
8010 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8011 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8016 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8017 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8018 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8019 btdm_2AntAgcTable(padapter, true);
8020 btdm_2AntAdcBackOff(padapter, true);
8021 btdm_2AntDacSwing(padapter, false, 0xc0);
8023 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8024 btdm_2AntAgcTable(padapter, false);
8025 btdm_2AntAdcBackOff(padapter, false);
8026 btdm_2AntDacSwing(padapter, false, 0xc0);
8031 static void btdm_2Ant8723APANEDRAction(struct rtw_adapter *padapter)
8033 u8 btRssiState, btRssiState1;
8035 if (btdm_NeedToDecBtPwr(padapter))
8036 btdm_2AntDecBtPwr(padapter, true);
8038 btdm_2AntDecBtPwr(padapter, false);
8040 if (BTDM_IsHT40(padapter)) {
8041 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8042 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8045 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8046 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8047 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8048 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8049 btdm_2AntPsTdma(padapter, true, 2);
8051 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8052 btdm_2AntPsTdma(padapter, true, 6);
8056 btdm_2AntAgcTable(padapter, false);
8057 btdm_2AntAdcBackOff(padapter, true);
8058 btdm_2AntDacSwing(padapter, false, 0xc0);
8060 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8061 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8062 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8065 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8066 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8067 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8068 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8069 btdm_2AntPsTdma(padapter, true, 2);
8071 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8072 btdm_2AntPsTdma(padapter, true, 6);
8076 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8077 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8078 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8079 btdm_2AntAgcTable(padapter, true);
8080 btdm_2AntAdcBackOff(padapter, true);
8081 btdm_2AntDacSwing(padapter, false, 0xc0);
8083 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8084 btdm_2AntAgcTable(padapter, false);
8085 btdm_2AntAdcBackOff(padapter, false);
8086 btdm_2AntDacSwing(padapter, false, 0xc0);
8092 static void btdm_2Ant8723APANHSAction(struct rtw_adapter *padapter)
8096 if (BTDM_IsHT40(padapter)) {
8097 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8098 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8100 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8101 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8102 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8103 btdm_2AntDecBtPwr(padapter, true);
8105 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8106 btdm_2AntDecBtPwr(padapter, false);
8108 btdm_2AntPsTdma(padapter, false, 0);
8111 btdm_2AntAgcTable(padapter, false);
8112 btdm_2AntAdcBackOff(padapter, true);
8113 btdm_2AntDacSwing(padapter, false, 0xc0);
8115 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8116 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8118 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8119 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8120 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high\n"));
8122 btdm_2AntDecBtPwr(padapter, true);
8123 btdm_2AntPsTdma(padapter, false, 0);
8126 btdm_2AntAgcTable(padapter, true);
8127 btdm_2AntAdcBackOff(padapter, true);
8128 btdm_2AntDacSwing(padapter, false, 0xc0);
8130 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low\n"));
8132 btdm_2AntDecBtPwr(padapter, false);
8133 btdm_2AntPsTdma(padapter, false, 0);
8136 btdm_2AntAgcTable(padapter, false);
8137 btdm_2AntAdcBackOff(padapter, false);
8138 btdm_2AntDacSwing(padapter, false, 0xc0);
8144 static void btdm_2Ant8723APANEDRA2DPAction(struct rtw_adapter *padapter)
8146 u8 btRssiState, btRssiState1, btInfoExt;
8147 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8149 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8151 if (btdm_NeedToDecBtPwr(padapter))
8152 btdm_2AntDecBtPwr(padapter, true);
8154 btdm_2AntDecBtPwr(padapter, false);
8156 if (BTDM_IsHT40(padapter)) {
8157 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8158 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8160 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8161 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8162 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8164 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8166 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8167 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8168 btdm_2AntPsTdma(padapter, true, 4);
8170 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8171 btdm_2AntPsTdma(padapter, true, 2);
8174 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8176 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8177 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8178 btdm_2AntPsTdma(padapter, true, 8);
8180 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8181 btdm_2AntPsTdma(padapter, true, 6);
8186 btdm_2AntAgcTable(padapter, false);
8187 btdm_2AntAdcBackOff(padapter, true);
8188 btdm_2AntDacSwing(padapter, false, 0xc0);
8190 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8191 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8192 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8194 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8195 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8196 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8197 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8199 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8200 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8201 btdm_2AntPsTdma(padapter, true, 4);
8203 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8204 btdm_2AntPsTdma(padapter, true, 2);
8207 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8209 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8210 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8211 btdm_2AntPsTdma(padapter, true, 8);
8213 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8214 btdm_2AntPsTdma(padapter, true, 6);
8219 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8220 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8221 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8222 btdm_2AntAgcTable(padapter, true);
8223 btdm_2AntAdcBackOff(padapter, true);
8224 btdm_2AntDacSwing(padapter, false, 0xc0);
8226 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8227 btdm_2AntAgcTable(padapter, false);
8228 btdm_2AntAdcBackOff(padapter, false);
8229 btdm_2AntDacSwing(padapter, false, 0xc0);
8234 static void btdm_2Ant8723APANEDRHIDAction(struct rtw_adapter *padapter)
8236 u8 btRssiState, btRssiState1;
8238 if (btdm_NeedToDecBtPwr(padapter))
8239 btdm_2AntDecBtPwr(padapter, true);
8241 btdm_2AntDecBtPwr(padapter, false);
8243 if (BTDM_IsHT40(padapter)) {
8244 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8245 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8247 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8248 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8249 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8250 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8251 btdm_2AntPsTdma(padapter, true, 10);
8253 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8254 btdm_2AntPsTdma(padapter, true, 14);
8258 btdm_2AntAgcTable(padapter, false);
8259 btdm_2AntAdcBackOff(padapter, true);
8260 btdm_2AntDacSwing(padapter, false, 0xc0);
8262 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8263 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8264 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8267 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8268 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8269 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8270 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8271 btdm_2AntPsTdma(padapter, true, 10);
8273 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8274 btdm_2AntPsTdma(padapter, true, 14);
8278 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8279 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8280 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8281 btdm_2AntAgcTable(padapter, true);
8282 btdm_2AntAdcBackOff(padapter, true);
8283 btdm_2AntDacSwing(padapter, false, 0xc0);
8285 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8286 btdm_2AntAgcTable(padapter, false);
8287 btdm_2AntAdcBackOff(padapter, false);
8288 btdm_2AntDacSwing(padapter, false, 0xc0);
8293 /* HID+A2DP+PAN(EDR) */
8294 static void btdm_2Ant8723AHIDA2DPPANEDRAction(struct rtw_adapter *padapter)
8296 u8 btRssiState, btRssiState1, btInfoExt;
8297 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8299 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8301 if (btdm_NeedToDecBtPwr(padapter))
8302 btdm_2AntDecBtPwr(padapter, true);
8304 btdm_2AntDecBtPwr(padapter, false);
8306 if (BTDM_IsHT40(padapter)) {
8307 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8308 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8309 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8310 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8311 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8312 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8314 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8315 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8316 btdm_2AntPsTdma(padapter, true, 12);
8318 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8319 btdm_2AntPsTdma(padapter, true, 10);
8322 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8323 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8324 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8325 btdm_2AntPsTdma(padapter, true, 16);
8327 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8328 btdm_2AntPsTdma(padapter, true, 14);
8333 btdm_2AntAgcTable(padapter, false);
8334 btdm_2AntAdcBackOff(padapter, true);
8335 btdm_2AntDacSwing(padapter, false, 0xc0);
8337 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8338 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 37, 0);
8339 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8340 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8341 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8342 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8343 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8345 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8346 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8347 btdm_2AntPsTdma(padapter, true, 12);
8349 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8350 btdm_2AntPsTdma(padapter, true, 10);
8353 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8354 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8355 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8356 btdm_2AntPsTdma(padapter, true, 16);
8358 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8359 btdm_2AntPsTdma(padapter, true, 14);
8364 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8365 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8366 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8367 btdm_2AntAgcTable(padapter, true);
8368 btdm_2AntAdcBackOff(padapter, true);
8369 btdm_2AntDacSwing(padapter, false, 0xc0);
8371 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8372 btdm_2AntAgcTable(padapter, false);
8373 btdm_2AntAdcBackOff(padapter, false);
8374 btdm_2AntDacSwing(padapter, false, 0xc0);
8379 static void btdm_2Ant8723AHIDA2DPAction(struct rtw_adapter *padapter)
8381 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8382 u8 btRssiState, btRssiState1, btInfoExt;
8384 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8386 if (btdm_NeedToDecBtPwr(padapter))
8387 btdm_2AntDecBtPwr(padapter, true);
8389 btdm_2AntDecBtPwr(padapter, false);
8391 if (BTDM_IsHT40(padapter)) {
8392 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8393 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8394 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8395 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8396 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8397 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8399 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8400 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8401 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8403 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8404 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8407 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8408 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8409 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8410 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8412 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8413 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8417 btdm_2AntAgcTable(padapter, false);
8418 btdm_2AntAdcBackOff(padapter, true);
8419 btdm_2AntDacSwing(padapter, false, 0xc0);
8421 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8422 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8423 btRssiState1 = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8425 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8426 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8427 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8428 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8430 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8431 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8432 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8434 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8435 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8438 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8439 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8440 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8441 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8443 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8444 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8447 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8448 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8449 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8451 btdm_2AntAgcTable(padapter, true);
8452 btdm_2AntAdcBackOff(padapter, true);
8453 btdm_2AntDacSwing(padapter, false, 0xc0);
8455 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8457 btdm_2AntAgcTable(padapter, false);
8458 btdm_2AntAdcBackOff(padapter, false);
8459 btdm_2AntDacSwing(padapter, false, 0xc0);
8464 static void btdm_2Ant8723AA2dp(struct rtw_adapter *padapter)
8466 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8467 u8 btRssiState, btRssiState1, btInfoExt;
8469 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8471 if (btdm_NeedToDecBtPwr(padapter))
8472 btdm_2AntDecBtPwr(padapter, true);
8474 btdm_2AntDecBtPwr(padapter, false);
8476 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8477 btdm_2AntIgnoreWlanAct(padapter, false);
8479 if (BTDM_IsHT40(padapter)) {
8480 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8481 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8483 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8484 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8485 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8486 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8487 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8489 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8490 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8494 btdm_2AntAgcTable(padapter, false);
8495 btdm_2AntAdcBackOff(padapter, true);
8496 btdm_2AntDacSwing(padapter, false, 0xc0);
8498 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8499 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8500 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8503 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8504 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8505 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8506 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8507 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8509 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8510 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8514 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8515 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8516 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8517 btdm_2AntAgcTable(padapter, true);
8518 btdm_2AntAdcBackOff(padapter, true);
8519 btdm_2AntDacSwing(padapter, false, 0xc0);
8521 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8522 btdm_2AntAgcTable(padapter, false);
8523 btdm_2AntAdcBackOff(padapter, false);
8524 btdm_2AntDacSwing(padapter, false, 0xc0);
8529 /* extern function start with BTDM_ */
8530 static void BTDM_2AntParaInit(struct rtw_adapter *padapter)
8533 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8534 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8536 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2Ant Parameter Init!!\n"));
8538 /* Enable counter statistics */
8539 rtl8723au_write8(padapter, 0x76e, 0x4);
8540 rtl8723au_write8(padapter, 0x778, 0x3);
8541 rtl8723au_write8(padapter, 0x40, 0x20);
8543 /* force to reset coex mechanism */
8544 pBtdm8723->preVal0x6c0 = 0x0;
8545 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8547 pBtdm8723->bPrePsTdmaOn = true;
8548 btdm_2AntPsTdma(padapter, false, 0);
8550 pBtdm8723->preFwDacSwingLvl = 0x10;
8551 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8553 pBtdm8723->bPreDecBtPwr = true;
8554 btdm_2AntDecBtPwr(padapter, false);
8556 pBtdm8723->bPreAgcTableEn = true;
8557 btdm_2AntAgcTable(padapter, false);
8559 pBtdm8723->bPreAdcBackOff = true;
8560 btdm_2AntAdcBackOff(padapter, false);
8562 pBtdm8723->bPreLowPenaltyRa = true;
8563 btdm_2AntLowPenaltyRa(padapter, false);
8565 pBtdm8723->bPreRfRxLpfShrink = true;
8566 btdm_2AntRfShrink(padapter, false);
8568 pBtdm8723->bPreDacSwingOn = true;
8569 btdm_2AntDacSwing(padapter, false, 0xc0);
8571 pBtdm8723->bPreIgnoreWlanAct = true;
8572 btdm_2AntIgnoreWlanAct(padapter, false);
8575 static void BTDM_2AntHwCoexAllOff8723A(struct rtw_adapter *padapter)
8577 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8580 static void BTDM_2AntFwCoexAllOff8723A(struct rtw_adapter *padapter)
8582 btdm_2AntIgnoreWlanAct(padapter, false);
8583 btdm_2AntPsTdma(padapter, false, 0);
8584 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8585 btdm_2AntDecBtPwr(padapter, false);
8588 static void BTDM_2AntSwCoexAllOff8723A(struct rtw_adapter *padapter)
8590 btdm_2AntAgcTable(padapter, false);
8591 btdm_2AntAdcBackOff(padapter, false);
8592 btdm_2AntLowPenaltyRa(padapter, false);
8593 btdm_2AntRfShrink(padapter, false);
8594 btdm_2AntDacSwing(padapter, false, 0xc0);
8597 static void BTDM_2AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
8599 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8600 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8601 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8602 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8604 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
8605 u8 bBtLinkExist = false, bBtHsModeExist = false;
8607 btInfo = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8608 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8610 /* check BIT2 first ==> check if bt is under inquiry or page scan */
8611 if (btInfo & BIT(2)) {
8612 if (!pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
8613 pBtMgnt->ExtConfig.bHoldForBtOperation = true;
8614 pBtMgnt->ExtConfig.bHoldPeriodCnt = 1;
8615 btdm_2AntBtInquiryPage(padapter);
8617 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8618 btdm_HoldForBtInqPage(padapter);
8620 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = true;
8623 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = false;
8624 pBtMgnt->ExtConfig.bHoldForBtOperation = false;
8625 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8628 RTPRINT(FBT, BT_TRACE,
8629 ("[BTC2H], pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage =%x pBtMgnt->ExtConfig.bHoldPeriodCnt =%x pBtMgnt->ExtConfig.bHoldForBtOperation =%x\n",
8630 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage,
8631 pBtMgnt->ExtConfig.bHoldPeriodCnt,
8632 pBtMgnt->ExtConfig.bHoldForBtOperation));
8634 RTPRINT(FBT, BT_TRACE,
8635 ("[BTC2H], btInfo =%x pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal =%x\n",
8636 btInfo, pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal));
8637 if (btInfo&BT_INFO_ACL) {
8638 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = true btInfo =%x\n", btInfo));
8639 bBtLinkExist = true;
8640 if (((btInfo&(BT_INFO_FTP|BT_INFO_A2DP|BT_INFO_HID|BT_INFO_SCO_BUSY)) != 0) ||
8641 pHalData->bt_coexist.halCoex8723.btRetryCnt > 0) {
8642 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
8644 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
8647 if (btInfo&BT_INFO_SCO || btInfo&BT_INFO_SCO_BUSY) {
8648 if (btInfo&BT_INFO_FTP || btInfo&BT_INFO_A2DP || btInfo&BT_INFO_HID) {
8649 switch (btInfo&0xe0) {
8651 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
8652 algorithm = BT_2ANT_COEX_ALGO_HID;
8655 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
8658 if (bBtHsModeExist) {
8659 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
8660 algorithm = BT_2ANT_COEX_ALGO_SCO;
8662 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
8663 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8666 case (BT_INFO_HID | BT_INFO_A2DP):
8667 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8668 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8670 case (BT_INFO_HID | BT_INFO_FTP):
8671 if (bBtHsModeExist) {
8672 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8673 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8675 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8676 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8679 case (BT_INFO_A2DP | BT_INFO_FTP):
8680 if (bBtHsModeExist) {
8681 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8682 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8684 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8685 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8688 case (BT_INFO_HID | BT_INFO_A2DP | BT_INFO_FTP):
8689 if (bBtHsModeExist) {
8690 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8691 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8693 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8694 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8699 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
8700 algorithm = BT_2ANT_COEX_ALGO_SCO;
8703 RTPRINT(FBT, BT_TRACE, ("[BTCoex], non SCO\n"));
8704 switch (btInfo&0xe0) {
8706 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID\n"));
8707 algorithm = BT_2ANT_COEX_ALGO_HID;
8710 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP\n"));
8711 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8714 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR)\n"));
8715 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8717 case (BT_INFO_HID | BT_INFO_A2DP):
8718 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8719 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8721 case (BT_INFO_HID|BT_INFO_FTP):
8722 if (bBtHsModeExist) {
8723 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8724 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8726 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8727 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8730 case (BT_INFO_A2DP|BT_INFO_FTP):
8731 if (bBtHsModeExist) {
8732 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8733 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8735 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8736 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8739 case (BT_INFO_HID|BT_INFO_A2DP|BT_INFO_FTP):
8740 if (bBtHsModeExist) {
8741 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8742 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8744 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8745 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8752 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = false\n"));
8753 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8756 pBtdm8723->curAlgorithm = algorithm;
8757 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8760 BTDM_CheckWiFiState(padapter);
8761 if (pBtMgnt->ExtConfig.bManualControl) {
8762 RTPRINT(FBT, BT_TRACE, ("Action Manual control, won't execute bt coexist mechanism!!\n"));
8767 void BTDM_2AntBtCoexist8723A(struct rtw_adapter *padapter)
8769 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8770 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8771 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
8772 u8 btInfoOriginal = 0;
8773 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8774 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8776 if (BTDM_BtProfileSupport(padapter)) {
8777 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8778 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8781 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8782 RTPRINT(FBT, BT_TRACE, ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8783 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8784 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8785 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8786 /* next time the coexist parameters should be reset again. */
8788 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8793 if (pBtDbg->dbgCtrl)
8794 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8796 pBtdm8723->curAlgorithm = btdm_ActionAlgorithm(padapter);
8797 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8799 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8800 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8801 pBtdm8723->bResetTdmaAdjust = true;
8803 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8804 RTPRINT(FBT, BT_TRACE, ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8805 pBtdm8723->preAlgorithm, pBtdm8723->curAlgorithm));
8806 pBtdm8723->bResetTdmaAdjust = true;
8808 switch (pBtdm8723->curAlgorithm) {
8809 case BT_2ANT_COEX_ALGO_SCO:
8810 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8811 btdm_2Ant8723ASCOAction(padapter);
8813 case BT_2ANT_COEX_ALGO_HID:
8814 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8815 btdm_2Ant8723AHIDAction(padapter);
8817 case BT_2ANT_COEX_ALGO_A2DP:
8818 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8819 btdm_2Ant8723AA2DPAction(padapter);
8821 case BT_2ANT_COEX_ALGO_PANEDR:
8822 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8823 btdm_2Ant8723APANEDRAction(padapter);
8825 case BT_2ANT_COEX_ALGO_PANHS:
8826 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8827 btdm_2Ant8723APANHSAction(padapter);
8829 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8830 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8831 btdm_2Ant8723APANEDRA2DPAction(padapter);
8833 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8834 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8835 btdm_2Ant8723APANEDRHIDAction(padapter);
8837 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8838 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8839 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8841 case BT_2ANT_COEX_ALGO_HID_A2DP:
8842 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8843 btdm_2Ant8723AHIDA2DPAction(padapter);
8846 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8847 btdm_2Ant8723AA2DPAction(padapter);
8850 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8853 RTPRINT(FBT, BT_TRACE, ("[BTCoex] Get bt info by fw!!\n"));
8854 /* msg shows c2h rsp for bt_info is received or not. */
8855 if (pHalData->bt_coexist.halCoex8723.bC2hBtInfoReqSent)
8856 RTPRINT(FBT, BT_TRACE, ("[BTCoex] c2h for btInfo not rcvd yet!!\n"));
8858 btInfoOriginal = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8860 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8861 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8864 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8865 RTPRINT(FBT, BT_TRACE,
8866 ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8867 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8868 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8869 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8870 /* next time the coexist parameters should be reset again. */
8872 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8877 if (pBtDbg->dbgCtrl)
8878 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8879 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8880 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8881 pBtdm8723->bResetTdmaAdjust = true;
8883 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8884 RTPRINT(FBT, BT_TRACE,
8885 ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8886 pBtdm8723->preAlgorithm,
8887 pBtdm8723->curAlgorithm));
8888 pBtdm8723->bResetTdmaAdjust = true;
8890 switch (pBtdm8723->curAlgorithm) {
8891 case BT_2ANT_COEX_ALGO_SCO:
8892 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8893 btdm_2Ant8723ASCOAction(padapter);
8895 case BT_2ANT_COEX_ALGO_HID:
8896 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8897 btdm_2Ant8723AHIDAction(padapter);
8899 case BT_2ANT_COEX_ALGO_A2DP:
8900 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8901 btdm_2Ant8723AA2dp(padapter);
8903 case BT_2ANT_COEX_ALGO_PANEDR:
8904 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8905 btdm_2Ant8723APANEDRAction(padapter);
8907 case BT_2ANT_COEX_ALGO_PANHS:
8908 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8909 btdm_2Ant8723APANHSAction(padapter);
8911 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8912 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8913 btdm_2Ant8723APANEDRA2DPAction(padapter);
8915 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8916 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8917 btdm_2Ant8723APANEDRHIDAction(padapter);
8919 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8920 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8921 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8923 case BT_2ANT_COEX_ALGO_HID_A2DP:
8924 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8925 btdm_2Ant8723AHIDA2DPAction(padapter);
8928 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8929 btdm_2Ant8723AA2DPAction(padapter);
8932 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8937 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
8939 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
8941 static u8 btCoexDbgBuf[BT_TMP_BUF_SIZE];
8943 static const char *const BtProfileString[] = {
8951 static const char *const BtSpecString[] = {
8961 static const char *const BtLinkRoleString[] = {
8966 static u8 btdm_BtWifiAntNum(struct rtw_adapter *padapter)
8968 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8969 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
8971 if (Ant_x2 == pHalData->bt_coexist.BT_Ant_Num) {
8972 if (Ant_x2 == pBtCoex->TotalAntNum)
8982 static void btdm_BtHwCountersMonitor(struct rtw_adapter *padapter)
8984 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8985 u32 regHPTxRx, regLPTxRx, u4Tmp;
8986 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
8988 regHPTxRx = REG_HIGH_PRIORITY_TXRX;
8989 regLPTxRx = REG_LOW_PRIORITY_TXRX;
8991 u4Tmp = rtl8723au_read32(padapter, regHPTxRx);
8992 regHPTx = u4Tmp & bMaskLWord;
8993 regHPRx = (u4Tmp & bMaskHWord)>>16;
8995 u4Tmp = rtl8723au_read32(padapter, regLPTxRx);
8996 regLPTx = u4Tmp & bMaskLWord;
8997 regLPRx = (u4Tmp & bMaskHWord)>>16;
8999 pHalData->bt_coexist.halCoex8723.highPriorityTx = regHPTx;
9000 pHalData->bt_coexist.halCoex8723.highPriorityRx = regHPRx;
9001 pHalData->bt_coexist.halCoex8723.lowPriorityTx = regLPTx;
9002 pHalData->bt_coexist.halCoex8723.lowPriorityRx = regLPRx;
9004 RTPRINT(FBT, BT_TRACE, ("High Priority Tx/Rx = %d / %d\n", regHPTx, regHPRx));
9005 RTPRINT(FBT, BT_TRACE, ("Low Priority Tx/Rx = %d / %d\n", regLPTx, regLPRx));
9008 rtl8723au_write8(padapter, 0x76e, 0xc);
9011 /* This function check if 8723 bt is disabled */
9012 static void btdm_BtEnableDisableCheck8723A(struct rtw_adapter *padapter)
9015 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9017 #ifdef CHECK_BT_EXIST_FROM_REG
9020 /* ox68[28]= 1 => BT enable; otherwise disable */
9021 val8 = rtl8723au_read8(padapter, 0x6B);
9022 if (!(val8 & BIT(4)))
9026 pHalData->bt_coexist.bCurBtDisabled = false;
9028 pHalData->bt_coexist.bCurBtDisabled = true;
9030 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0 &&
9031 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0 &&
9032 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0 &&
9033 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0)
9035 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xeaea &&
9036 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xeaea &&
9037 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xeaea &&
9038 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xeaea)
9040 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xffff &&
9041 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xffff &&
9042 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xffff &&
9043 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xffff)
9046 pHalData->bt_coexist.btActiveZeroCnt = 0;
9047 pHalData->bt_coexist.bCurBtDisabled = false;
9048 RTPRINT(FBT, BT_TRACE, ("8723A BT is enabled !!\n"));
9050 pHalData->bt_coexist.btActiveZeroCnt++;
9051 RTPRINT(FBT, BT_TRACE, ("8723A bt all counters = 0, %d times!!\n",
9052 pHalData->bt_coexist.btActiveZeroCnt));
9053 if (pHalData->bt_coexist.btActiveZeroCnt >= 2) {
9054 pHalData->bt_coexist.bCurBtDisabled = true;
9055 RTPRINT(FBT, BT_TRACE, ("8723A BT is disabled !!\n"));
9060 if (!pHalData->bt_coexist.bCurBtDisabled) {
9061 if (BTDM_IsWifiConnectionExist(padapter))
9062 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
9064 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_DISCONNECT);
9067 if (pHalData->bt_coexist.bPreBtDisabled !=
9068 pHalData->bt_coexist.bCurBtDisabled) {
9069 RTPRINT(FBT, BT_TRACE, ("8723A BT is from %s to %s!!\n",
9070 (pHalData->bt_coexist.bPreBtDisabled ? "disabled":"enabled"),
9071 (pHalData->bt_coexist.bCurBtDisabled ? "disabled":"enabled")));
9072 pHalData->bt_coexist.bPreBtDisabled = pHalData->bt_coexist.bCurBtDisabled;
9076 static void btdm_BTCoexist8723AHandler(struct rtw_adapter *padapter)
9078 struct hal_data_8723a *pHalData;
9080 pHalData = GET_HAL_DATA(padapter);
9082 if (btdm_BtWifiAntNum(padapter) == Ant_x2) {
9083 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2 Ant mechanism\n"));
9084 BTDM_2AntBtCoexist8723A(padapter);
9086 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1 Ant mechanism\n"));
9087 BTDM_1AntBtCoexist8723A(padapter);
9090 if (!BTDM_IsSameCoexistState(padapter)) {
9091 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x\n",
9092 pHalData->bt_coexist.PreviousState,
9093 pHalData->bt_coexist.CurrentState));
9094 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
9096 RTPRINT(FBT, BT_TRACE, ("["));
9097 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT30)
9098 RTPRINT(FBT, BT_TRACE, ("BT 3.0, "));
9099 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT20)
9100 RTPRINT(FBT, BT_TRACE, ("HT20, "));
9101 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT40)
9102 RTPRINT(FBT, BT_TRACE, ("HT40, "));
9103 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_LEGACY)
9104 RTPRINT(FBT, BT_TRACE, ("Legacy, "));
9105 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_LOW)
9106 RTPRINT(FBT, BT_TRACE, ("Rssi_Low, "));
9107 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_MEDIUM)
9108 RTPRINT(FBT, BT_TRACE, ("Rssi_Mid, "));
9109 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_HIGH)
9110 RTPRINT(FBT, BT_TRACE, ("Rssi_High, "));
9111 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_IDLE)
9112 RTPRINT(FBT, BT_TRACE, ("Wifi_Idle, "));
9113 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_UPLINK)
9114 RTPRINT(FBT, BT_TRACE, ("Wifi_Uplink, "));
9115 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_DOWNLINK)
9116 RTPRINT(FBT, BT_TRACE, ("Wifi_Downlink, "));
9117 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)
9118 RTPRINT(FBT, BT_TRACE, ("BT_idle, "));
9119 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_HID)
9120 RTPRINT(FBT, BT_TRACE, ("PRO_HID, "));
9121 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_A2DP)
9122 RTPRINT(FBT, BT_TRACE, ("PRO_A2DP, "));
9123 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_PAN)
9124 RTPRINT(FBT, BT_TRACE, ("PRO_PAN, "));
9125 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_SCO)
9126 RTPRINT(FBT, BT_TRACE, ("PRO_SCO, "));
9127 RTPRINT(FBT, BT_TRACE, ("]\n"));
9131 /* extern function start with BTDM_ */
9132 u32 BTDM_BtTxRxCounterH(struct rtw_adapter *padapter)
9134 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9137 counters = pHalData->bt_coexist.halCoex8723.highPriorityTx+
9138 pHalData->bt_coexist.halCoex8723.highPriorityRx;
9142 u32 BTDM_BtTxRxCounterL(struct rtw_adapter *padapter)
9144 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9147 counters = pHalData->bt_coexist.halCoex8723.lowPriorityTx+
9148 pHalData->bt_coexist.halCoex8723.lowPriorityRx ;
9152 void BTDM_SetFwChnlInfo(struct rtw_adapter *padapter, enum rt_media_status mstatus)
9154 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9155 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9156 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9157 u8 H2C_Parameter[3] = {0};
9161 if (RT_MEDIA_CONNECT == mstatus)
9162 H2C_Parameter[0] = 0x1; /* 0: disconnected, 1:connected */
9164 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) {
9166 chnl = pmlmeext->cur_channel;
9167 if (BTDM_IsHT40(padapter)) {
9168 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
9170 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
9173 H2C_Parameter[1] = chnl;
9174 } else { /* check if HS link is exists */
9176 if (BT_Operation(padapter))
9177 H2C_Parameter[1] = pBtMgnt->BTChannel;
9179 H2C_Parameter[1] = pmlmeext->cur_channel;
9182 if (BTDM_IsHT40(padapter))
9183 H2C_Parameter[2] = 0x30;
9185 H2C_Parameter[2] = 0x20;
9187 FillH2CCmd(padapter, 0x19, 3, H2C_Parameter);
9190 u8 BTDM_IsWifiConnectionExist(struct rtw_adapter *padapter)
9194 if (BTHCI_HsConnectionEstablished(padapter))
9197 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true)
9204 struct rtw_adapter *padapter,
9212 u8 H2C_Parameter[5] = {0};
9214 if (rtl8723a_BT_using_antenna_1(padapter)) {
9215 if ((!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
9216 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
9217 /* for softap mode */
9218 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9219 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9220 u8 BtState = pBtCoex->c2hBtInfo;
9222 if ((BtState != BT_INFO_STATE_NO_CONNECTION) &&
9223 (BtState != BT_INFO_STATE_CONNECT_IDLE)) {
9224 if (byte1 & BIT(4)) {
9236 H2C_Parameter[0] = byte1;
9237 H2C_Parameter[1] = byte2;
9238 H2C_Parameter[2] = byte3;
9239 H2C_Parameter[3] = byte4;
9240 H2C_Parameter[4] = byte5;
9242 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%02x%08x\n",
9244 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
9246 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
9249 void BTDM_QueryBtInformation(struct rtw_adapter *padapter)
9251 u8 H2C_Parameter[1] = {0};
9252 struct hal_data_8723a *pHalData;
9253 struct bt_coexist_8723a *pBtCoex;
9255 pHalData = GET_HAL_DATA(padapter);
9256 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9258 if (!rtl8723a_BT_enabled(padapter)) {
9259 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9260 pBtCoex->bC2hBtInfoReqSent = false;
9264 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9265 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9267 if (pBtCoex->bC2hBtInfoReqSent == true)
9268 RTPRINT(FBT, BT_TRACE, ("[BTCoex], didn't recv previous BtInfo report!\n"));
9270 pBtCoex->bC2hBtInfoReqSent = true;
9272 H2C_Parameter[0] |= BIT(0); /* trigger */
9274 /*RTPRINT(FBT, BT_TRACE, ("[BTCoex], Query Bt information, write 0x38 = 0x%x\n", */
9275 /*H2C_Parameter[0])); */
9277 FillH2CCmd(padapter, 0x38, 1, H2C_Parameter);
9280 void BTDM_SetSwRfRxLpfCorner(struct rtw_adapter *padapter, u8 type)
9282 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9284 if (BT_RF_RX_LPF_CORNER_SHRINK == type) {
9285 /* Shrink RF Rx LPF corner */
9286 RTPRINT(FBT, BT_TRACE, ("Shrink RF Rx LPF corner!!\n"));
9287 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, 0xf0ff7);
9288 pHalData->bt_coexist.bSWCoexistAllOff = false;
9289 } else if (BT_RF_RX_LPF_CORNER_RESUME == type) {
9290 /* Resume RF Rx LPF corner */
9291 RTPRINT(FBT, BT_TRACE, ("Resume RF Rx LPF corner!!\n"));
9292 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, pHalData->bt_coexist.BtRfRegOrigin1E);
9297 BTDM_SetSwPenaltyTxRateAdaptive(
9298 struct rtw_adapter *padapter,
9302 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9305 tmpU1 = rtl8723au_read8(padapter, 0x4fd);
9307 if (BT_TX_RATE_ADAPTIVE_LOW_PENALTY == raType) {
9309 pHalData->bt_coexist.bSWCoexistAllOff = false;
9310 } else if (BT_TX_RATE_ADAPTIVE_NORMAL == raType) {
9314 rtl8723au_write8(padapter, 0x4fd, tmpU1);
9317 void BTDM_SetFwDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
9319 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9320 u8 H2C_Parameter[1] = {0};
9322 H2C_Parameter[0] = 0;
9325 H2C_Parameter[0] |= BIT(1);
9326 pHalData->bt_coexist.bFWCoexistAllOff = false;
9329 RTPRINT(FBT, BT_TRACE, ("[BTCoex], decrease Bt Power : %s, write 0x21 = 0x%x\n",
9330 (bDecBtPwr ? "Yes!!" : "No!!"), H2C_Parameter[0]));
9332 FillH2CCmd(padapter, 0x21, 1, H2C_Parameter);
9335 u8 BTDM_BtProfileSupport(struct rtw_adapter *padapter)
9338 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9339 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9340 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9342 if (pBtMgnt->bSupportProfile &&
9343 !pHalData->bt_coexist.halCoex8723.bForceFwBtInfo)
9349 static void BTDM_AdjustForBtOperation8723A(struct rtw_adapter *padapter)
9351 /* BTDM_2AntAdjustForBtOperation8723(padapter); */
9354 static void BTDM_FwC2hBtRssi8723A(struct rtw_adapter *padapter, u8 *tmpBuf)
9356 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9357 u8 percent = 0, u1tmp = 0;
9360 percent = u1tmp*2+10;
9362 pHalData->bt_coexist.halCoex8723.btRssi = percent;
9363 /*RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", percent)); */
9367 rtl8723a_fw_c2h_BT_info(struct rtw_adapter *padapter, u8 *tmpBuf, u8 length)
9369 struct hal_data_8723a *pHalData;
9370 struct bt_30info *pBTInfo;
9371 struct bt_mgnt *pBtMgnt;
9372 struct bt_coexist_8723a *pBtCoex;
9375 pHalData = GET_HAL_DATA(padapter);
9376 pBTInfo = GET_BT_INFO(padapter);
9377 pBtMgnt = &pBTInfo->BtMgnt;
9378 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9380 pBtCoex->bC2hBtInfoReqSent = false;
9382 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT info[%d]=[", length));
9384 pBtCoex->btRetryCnt = 0;
9385 for (i = 0; i < length; i++) {
9388 pBtCoex->c2hBtInfoOriginal = tmpBuf[i];
9391 pBtCoex->btRetryCnt = tmpBuf[i];
9394 BTDM_FwC2hBtRssi8723A(padapter, &tmpBuf[i]);
9397 pBtCoex->btInfoExt = tmpBuf[i]&BIT(0);
9402 RTPRINT(FBT, BT_TRACE, ("0x%02x]\n", tmpBuf[i]));
9404 RTPRINT(FBT, BT_TRACE, ("0x%02x, ", tmpBuf[i]));
9406 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", pBtCoex->btRssi));
9407 if (pBtCoex->btInfoExt)
9408 RTPRINT(FBT, BT_TRACE, ("[BTC2H], pBtCoex->btInfoExt =%x\n", pBtCoex->btInfoExt));
9410 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9411 BTDM_1AntFwC2hBtInfo8723A(padapter);
9413 BTDM_2AntFwC2hBtInfo8723A(padapter);
9415 if (pBtMgnt->ExtConfig.bManualControl) {
9416 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9420 btdm_BTCoexist8723AHandler(padapter);
9423 static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
9425 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9426 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9427 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9428 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9429 u8 u1Tmp, u1Tmp1, u1Tmp2, i, btInfoExt, psTdmaCase = 0;
9433 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
9434 DCMD_Printf(btCoexDbgBuf);
9436 if (!rtl8723a_BT_coexist(padapter)) {
9437 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");
9438 DCMD_Printf(btCoexDbgBuf);
9442 antNum = btdm_BtWifiAntNum(padapter);
9443 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/%d ", "Ant mechanism PG/Now run :", \
9444 ((pHalData->bt_coexist.BT_Ant_Num == Ant_x2) ? 2 : 1), ((antNum == Ant_x2) ? 2 : 1));
9445 DCMD_Printf(btCoexDbgBuf);
9447 if (pBtMgnt->ExtConfig.bManualControl) {
9448 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
9449 DCMD_Printf(btCoexDbgBuf);
9451 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
9452 ((pBtMgnt->bSupportProfile) ? "Yes" : "No"), pBtMgnt->ExtConfig.HCIExtensionVer);
9453 DCMD_Printf(btCoexDbgBuf);
9456 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = / %d", "Dot11 channel / BT channel", \
9457 pBtMgnt->BTChannel);
9458 DCMD_Printf(btCoexDbgBuf);
9460 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %d / %d / %d", "Wifi/BT/HS rssi", \
9461 BTDM_GetRxSS(padapter),
9462 pHalData->bt_coexist.halCoex8723.btRssi,
9463 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB);
9464 DCMD_Printf(btCoexDbgBuf);
9466 if (!pBtMgnt->ExtConfig.bManualControl) {
9467 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %s / %s ", "WIfi status",
9468 ((BTDM_Legacy(padapter)) ? "Legacy" : (((BTDM_IsHT40(padapter)) ? "HT40" : "HT20"))),
9469 ((!BTDM_IsWifiBusy(padapter)) ? "idle" : ((BTDM_IsWifiUplink(padapter)) ? "uplink" : "downlink")));
9470 DCMD_Printf(btCoexDbgBuf);
9472 if (pBtMgnt->bSupportProfile) {
9473 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
9474 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_SCO)) ? 1 : 0),
9475 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) ? 1 : 0),
9476 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) ? 1 : 0),
9477 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) ? 1 : 0));
9478 DCMD_Printf(btCoexDbgBuf);
9480 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
9481 if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
9482 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role",
9483 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9484 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec],
9485 BtLinkRoleString[pBtMgnt->ExtConfig.linkInfo[i].linkRole]);
9486 DCMD_Printf(btCoexDbgBuf);
9488 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
9489 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "A2DP rate", \
9490 (btInfoExt & BIT(0)) ?
9491 "Basic rate" : "EDR rate");
9492 DCMD_Printf(btCoexDbgBuf);
9494 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
9495 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9496 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec]);
9497 DCMD_Printf(btCoexDbgBuf);
9504 if (!pBtMgnt->ExtConfig.bManualControl) {
9505 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw BT Coex mechanism]============");
9506 DCMD_Printf(btCoexDbgBuf);
9507 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "AGC Table", \
9508 pBtCoex->btdm2Ant.bCurAgcTableEn);
9509 DCMD_Printf(btCoexDbgBuf);
9510 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "ADC Backoff", \
9511 pBtCoex->btdm2Ant.bCurAdcBackOff);
9512 DCMD_Printf(btCoexDbgBuf);
9513 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Low penalty RA", \
9514 pBtCoex->btdm2Ant.bCurLowPenaltyRa);
9515 DCMD_Printf(btCoexDbgBuf);
9516 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "RF Rx LPF Shrink", \
9517 pBtCoex->btdm2Ant.bCurRfRxLpfShrink);
9518 DCMD_Printf(btCoexDbgBuf);
9520 u4Tmp[0] = PHY_QueryRFReg(padapter, PathA, 0x1e, 0xff0);
9521 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "RF-A, 0x1e[11:4]/original val", \
9522 u4Tmp[0], pHalData->bt_coexist.BtRfRegOrigin1E);
9523 DCMD_Printf(btCoexDbgBuf);
9526 if (!pBtMgnt->ExtConfig.bManualControl) {
9527 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw BT Coex mechanism]============");
9528 DCMD_Printf(btCoexDbgBuf);
9530 if (!pBtMgnt->ExtConfig.bManualControl) {
9531 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9532 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm1Ant.curPsTdma;
9534 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm2Ant.curPsTdma;
9535 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA(0x3a)", \
9536 pHalData->bt_coexist.fw3aVal[0], pHalData->bt_coexist.fw3aVal[1],
9537 pHalData->bt_coexist.fw3aVal[2], pHalData->bt_coexist.fw3aVal[3],
9538 pHalData->bt_coexist.fw3aVal[4], psTdmaCase);
9539 DCMD_Printf(btCoexDbgBuf);
9541 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Decrease Bt Power", \
9542 pBtCoex->btdm2Ant.bCurDecBtPwr);
9543 DCMD_Printf(btCoexDbgBuf);
9545 u1Tmp = rtl8723au_read8(padapter, 0x778);
9546 u1Tmp1 = rtl8723au_read8(padapter, 0x783);
9547 u1Tmp2 = rtl8723au_read8(padapter, 0x796);
9548 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
9549 u1Tmp, u1Tmp1, u1Tmp2);
9550 DCMD_Printf(btCoexDbgBuf);
9552 if (!pBtMgnt->ExtConfig.bManualControl) {
9553 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "Sw DacSwing Ctrl/Val", \
9554 pBtCoex->btdm2Ant.bCurDacSwingOn, pBtCoex->btdm2Ant.curDacSwingLvl);
9555 DCMD_Printf(btCoexDbgBuf);
9557 u4Tmp[0] = rtl8723au_read32(padapter, 0x880);
9558 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \
9560 DCMD_Printf(btCoexDbgBuf);
9563 if (!pBtMgnt->ExtConfig.bManualControl) {
9564 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw BT Coex mechanism]============");
9565 DCMD_Printf(btCoexDbgBuf);
9568 u1Tmp = rtl8723au_read8(padapter, 0x40);
9569 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
9571 DCMD_Printf(btCoexDbgBuf);
9573 u4Tmp[0] = rtl8723au_read32(padapter, 0x550);
9574 u1Tmp = rtl8723au_read8(padapter, 0x522);
9575 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x", "0x550(bcn contrl)/0x522", \
9577 DCMD_Printf(btCoexDbgBuf);
9579 u4Tmp[0] = rtl8723au_read32(padapter, 0x484);
9580 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
9582 DCMD_Printf(btCoexDbgBuf);
9584 u4Tmp[0] = rtl8723au_read32(padapter, 0x50);
9585 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
9587 DCMD_Printf(btCoexDbgBuf);
9589 u4Tmp[0] = rtl8723au_read32(padapter, 0xda0);
9590 u4Tmp[1] = rtl8723au_read32(padapter, 0xda4);
9591 u4Tmp[2] = rtl8723au_read32(padapter, 0xda8);
9592 u4Tmp[3] = rtl8723au_read32(padapter, 0xdac);
9593 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
9594 u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);
9595 DCMD_Printf(btCoexDbgBuf);
9597 u4Tmp[0] = rtl8723au_read32(padapter, 0x6c0);
9598 u4Tmp[1] = rtl8723au_read32(padapter, 0x6c4);
9599 u4Tmp[2] = rtl8723au_read32(padapter, 0x6c8);
9600 u1Tmp = rtl8723au_read8(padapter, 0x6cc);
9601 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
9602 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp);
9603 DCMD_Printf(btCoexDbgBuf);
9605 /* u4Tmp = rtl8723au_read32(padapter, 0x770); */
9606 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x770(Hi pri Rx[31:16]/Tx[15:0])", \
9607 pHalData->bt_coexist.halCoex8723.highPriorityRx,
9608 pHalData->bt_coexist.halCoex8723.highPriorityTx);
9609 DCMD_Printf(btCoexDbgBuf);
9610 /* u4Tmp = rtl8723au_read32(padapter, 0x774); */
9611 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x774(Lo pri Rx[31:16]/Tx[15:0])", \
9612 pHalData->bt_coexist.halCoex8723.lowPriorityRx,
9613 pHalData->bt_coexist.halCoex8723.lowPriorityTx);
9614 DCMD_Printf(btCoexDbgBuf);
9616 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang */
9617 u1Tmp = rtl8723au_read8(padapter, 0x41b);
9618 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x41b (hang chk == 0xf)", \
9620 DCMD_Printf(btCoexDbgBuf);
9621 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
9622 pHalData->LastHMEBoxNum);
9623 DCMD_Printf(btCoexDbgBuf);
9627 BTDM_8723ASignalCompensation(struct rtw_adapter *padapter,
9628 u8 *rssi_wifi, u8 *rssi_bt)
9630 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9631 BTDM_1AntSignalCompensation(padapter, rssi_wifi, rssi_bt);
9634 static void BTDM_8723AInit(struct rtw_adapter *padapter)
9636 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9637 BTDM_2AntParaInit(padapter);
9639 BTDM_1AntParaInit(padapter);
9642 static void BTDM_HWCoexAllOff8723A(struct rtw_adapter *padapter)
9644 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9645 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9647 if (pBtMgnt->ExtConfig.bManualControl)
9650 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9651 BTDM_2AntHwCoexAllOff8723A(padapter);
9654 static void BTDM_FWCoexAllOff8723A(struct rtw_adapter *padapter)
9656 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9657 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9659 if (pBtMgnt->ExtConfig.bManualControl)
9662 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9663 BTDM_2AntFwCoexAllOff8723A(padapter);
9666 static void BTDM_SWCoexAllOff8723A(struct rtw_adapter *padapter)
9668 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9669 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9671 if (pBtMgnt->ExtConfig.bManualControl)
9674 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9675 BTDM_2AntSwCoexAllOff8723A(padapter);
9679 BTDM_Set8723ABtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
9681 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9682 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9685 pBtCoex->TotalAntNum = Ant_x1;
9686 else if (antNum == 2)
9687 pBtCoex->TotalAntNum = Ant_x2;
9690 void rtl8723a_BT_lps_leave(struct rtw_adapter *padapter)
9692 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9693 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9695 if (pBtMgnt->ExtConfig.bManualControl)
9698 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9699 BTDM_1AntLpsLeave(padapter);
9702 static void BTDM_ForHalt8723A(struct rtw_adapter *padapter)
9704 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9705 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9707 if (pBtMgnt->ExtConfig.bManualControl)
9710 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9711 BTDM_1AntForHalt(padapter);
9714 static void BTDM_WifiScanNotify8723A(struct rtw_adapter *padapter, u8 scanType)
9716 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9717 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9719 if (pBtMgnt->ExtConfig.bManualControl)
9722 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9723 BTDM_1AntWifiScanNotify(padapter, scanType);
9727 BTDM_WifiAssociateNotify8723A(struct rtw_adapter *padapter, u8 action)
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_1AntWifiAssociateNotify(padapter, action);
9740 BTDM_MediaStatusNotify8723A(struct rtw_adapter *padapter,
9741 enum rt_media_status mstatus)
9743 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9744 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9746 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatusNotify, %s\n",
9747 mstatus?"connect":"disconnect"));
9749 BTDM_SetFwChnlInfo(padapter, mstatus);
9751 if (pBtMgnt->ExtConfig.bManualControl)
9754 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9755 BTDM_1AntMediaStatusNotify(padapter, mstatus);
9758 static void BTDM_ForDhcp8723A(struct rtw_adapter *padapter)
9760 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9761 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9763 if (pBtMgnt->ExtConfig.bManualControl)
9766 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9767 BTDM_1AntForDhcp(padapter);
9770 bool rtl8723a_BT_using_antenna_1(struct rtw_adapter *padapter)
9772 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9778 static void BTDM_BTCoexist8723A(struct rtw_adapter *padapter)
9780 struct hal_data_8723a *pHalData;
9781 struct bt_30info *pBTInfo;
9782 struct bt_mgnt *pBtMgnt;
9783 struct bt_coexist_8723a *pBtCoex;
9785 pHalData = GET_HAL_DATA(padapter);
9786 pBTInfo = GET_BT_INFO(padapter);
9787 pBtMgnt = &pBTInfo->BtMgnt;
9788 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9790 RTPRINT(FBT, BT_TRACE, ("[BTCoex], beacon RSSI = 0x%x(%d)\n",
9791 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB,
9792 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB));
9794 btdm_BtHwCountersMonitor(padapter);
9795 btdm_BtEnableDisableCheck8723A(padapter);
9797 if (pBtMgnt->ExtConfig.bManualControl) {
9798 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9802 if (pBtCoex->bC2hBtInfoReqSent) {
9803 if (!rtl8723a_BT_enabled(padapter)) {
9804 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9806 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9807 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9810 btdm_BTCoexist8723AHandler(padapter);
9811 } else if (!rtl8723a_BT_enabled(padapter)) {
9812 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9813 btdm_BTCoexist8723AHandler(padapter);
9816 BTDM_QueryBtInformation(padapter);
9819 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
9821 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
9823 /* local function start with btdm_ */
9824 /* extern function start with BTDM_ */
9826 static void BTDM_SetAntenna(struct rtw_adapter *padapter, u8 who)
9832 struct rtw_adapter *padapter,
9838 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9839 u8 H2C_Parameter[3] = {0};
9841 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9844 H2C_Parameter[2] = 0;
9845 H2C_Parameter[1] = 0;
9846 H2C_Parameter[0] = 0;
9849 H2C_Parameter[2] |= 0x02; /* BIT1 */
9850 pHalData->bt_coexist.bFWCoexistAllOff = false;
9852 pHalData->bt_coexist.bInterruptOn = bInterruptOn;
9855 H2C_Parameter[2] |= 0x10; /* BIT4 */
9856 pHalData->bt_coexist.bFWCoexistAllOff = false;
9858 pHalData->bt_coexist.bSingleAntOn = bSingleAntOn;
9861 H2C_Parameter[2] |= 0x20; /* BIT5 */
9862 pHalData->bt_coexist.bFWCoexistAllOff = false;
9864 pHalData->bt_coexist.bMultiNAVOn = bMultiNAVOn;
9866 RTPRINT(FBT, BT_TRACE, ("[DM][BT], SingleAntenna =[%s:%s:%s], write 0xe = 0x%x\n",
9867 bSingleAntOn?"ON":"OFF", bInterruptOn?"ON":"OFF", bMultiNAVOn?"ON":"OFF",
9868 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
9871 void BTDM_CheckBTIdleChange1Ant(struct rtw_adapter *padapter)
9873 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9874 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9875 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9876 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
9877 u8 stateChange = false;
9878 u32 BT_Polling, Ratio_Act, Ratio_STA;
9879 u32 BT_Active, BT_State;
9880 u32 regBTActive = 0, regBTState = 0, regBTPolling = 0;
9882 if (!rtl8723a_BT_coexist(padapter))
9884 if (pBtMgnt->ExtConfig.bManualControl)
9886 if (pHalData->bt_coexist.BT_CoexistType != BT_CSR_BC8)
9888 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9891 /* The following we only consider CSR BC8 and fw version should be >= 62 */
9892 RTPRINT(FBT, BT_TRACE, ("[DM][BT], FirmwareVersion = 0x%x(%d)\n",
9893 pHalData->FirmwareVersion, pHalData->FirmwareVersion));
9894 regBTActive = REG_BT_ACTIVE;
9895 regBTState = REG_BT_STATE;
9896 if (pHalData->FirmwareVersion >= FW_VER_BT_REG1)
9897 regBTPolling = REG_BT_POLLING1;
9899 regBTPolling = REG_BT_POLLING;
9901 BT_Active = rtl8723au_read32(padapter, regBTActive);
9902 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Active(0x%x) =%x\n", regBTActive, BT_Active));
9903 BT_Active = BT_Active & 0x00ffffff;
9905 BT_State = rtl8723au_read32(padapter, regBTState);
9906 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_State(0x%x) =%x\n", regBTState, BT_State));
9907 BT_State = BT_State & 0x00ffffff;
9909 BT_Polling = rtl8723au_read32(padapter, regBTPolling);
9910 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Polling(0x%x) =%x\n", regBTPolling, BT_Polling));
9912 if (BT_Active == 0xffffffff && BT_State == 0xffffffff && BT_Polling == 0xffffffff)
9914 if (BT_Polling == 0)
9917 Ratio_Act = BT_Active*1000/BT_Polling;
9918 Ratio_STA = BT_State*1000/BT_Polling;
9920 pHalData->bt_coexist.Ratio_Tx = Ratio_Act;
9921 pHalData->bt_coexist.Ratio_PRI = Ratio_STA;
9923 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_Act =%d\n", Ratio_Act));
9924 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_STA =%d\n", Ratio_STA));
9926 if (Ratio_STA < 60 && Ratio_Act < 500) { /* BT PAN idle */
9927 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_IDLE;
9928 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9929 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9931 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_IDLE;
9934 /* Check if BT PAN (under BT 2.1) is uplink or downlink */
9935 if ((Ratio_Act/Ratio_STA) < 2) {
9937 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = true;
9938 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_UPLINK;
9939 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = false;
9940 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9942 /* BT PAN downlink */
9943 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9944 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9945 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9946 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9949 /* BT PAN downlink */
9950 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9951 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9952 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9953 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9957 /* Check BT is idle or not */
9958 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9959 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9960 pBtMgnt->ExtConfig.bBTBusy = false;
9961 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9963 if (Ratio_STA < 60) {
9964 pBtMgnt->ExtConfig.bBTBusy = false;
9965 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9967 pBtMgnt->ExtConfig.bBTBusy = true;
9968 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_IDLE;
9972 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9973 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9974 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
9975 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
9976 BTDM_SetAntenna(padapter, BTDM_ANT_BT_IDLE);
9978 if (pBtMgnt->ExtConfig.MIN_BT_RSSI <= -5) {
9979 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_RSSI_LOW;
9980 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Low\n"));
9982 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
9983 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Normal\n"));
9987 if (pHalData->bt_coexist.bBTBusyTraffic != pBtMgnt->ExtConfig.bBTBusy) {
9988 /* BT idle or BT non-idle */
9989 pHalData->bt_coexist.bBTBusyTraffic = pBtMgnt->ExtConfig.bBTBusy;
9994 if (!pBtMgnt->ExtConfig.bBTBusy)
9995 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
9997 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is non-idle\n"));
9999 if (!pBtMgnt->ExtConfig.bBTBusy) {
10000 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
10001 if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING|WIFI_SITE_MONITOR) == true)
10002 BTDM_SetAntenna(padapter, BTDM_ANT_WIFI);
10006 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
10008 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
10010 /* local function start with btdm_ */
10013 /* In the following, FW should be done before SW mechanism. */
10014 /* BTDM_Balance(), BTDM_DiminishWiFi(), BT_NAV() should be done */
10015 /* before BTDM_AGCTable(), BTDM_BBBackOffLevel(), btdm_DacSwing(). */
10017 /* extern function start with BTDM_ */
10021 struct rtw_adapter *padapter,
10028 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10029 u8 H2C_Parameter[3] = {0};
10031 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x2)
10034 if ((pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_RSSI_LOW) &&
10035 (DACSwingLevel == 0x20)) {
10036 RTPRINT(FBT, BT_TRACE, ("[BT]DiminishWiFi 0x20 original, but set 0x18 for Low RSSI!\n"));
10037 DACSwingLevel = 0x18;
10040 H2C_Parameter[2] = 0;
10041 H2C_Parameter[1] = DACSwingLevel;
10042 H2C_Parameter[0] = 0;
10044 H2C_Parameter[2] |= 0x01; /* BIT0 */
10046 H2C_Parameter[2] |= 0x02; /* BIT1 */
10047 pHalData->bt_coexist.bFWCoexistAllOff = false;
10050 H2C_Parameter[2] |= 0x08; /* BIT3 */
10051 pHalData->bt_coexist.bFWCoexistAllOff = false;
10054 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bDACOn = %s, bInterruptOn = %s, write 0xe = 0x%x\n",
10055 bDACOn?"ON":"OFF", bInterruptOn?"ON":"OFF",
10056 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10057 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bNAVOn = %s\n",
10058 bNAVOn?"ON":"OFF"));
10061 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
10063 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
10065 /* local function */
10066 static void btdm_ResetFWCoexState(struct rtw_adapter *padapter)
10068 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10070 pHalData->bt_coexist.CurrentState = 0;
10071 pHalData->bt_coexist.PreviousState = 0;
10074 static void btdm_InitBtCoexistDM(struct rtw_adapter *padapter)
10076 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10078 /* 20100415 Joseph: Restore RF register 0x1E and 0x1F value for further usage. */
10079 pHalData->bt_coexist.BtRfRegOrigin1E = PHY_QueryRFReg(padapter, PathA, RF_RCK1, bRFRegOffsetMask);
10080 pHalData->bt_coexist.BtRfRegOrigin1F = PHY_QueryRFReg(padapter, PathA, RF_RCK2, 0xf0);
10082 pHalData->bt_coexist.CurrentState = 0;
10083 pHalData->bt_coexist.PreviousState = 0;
10085 BTDM_8723AInit(padapter);
10086 pHalData->bt_coexist.bInitlized = true;
10090 /* extern function */
10092 void BTDM_CheckAntSelMode(struct rtw_adapter *padapter)
10096 void BTDM_FwC2hBtRssi(struct rtw_adapter *padapter, u8 *tmpBuf)
10098 BTDM_FwC2hBtRssi8723A(padapter, tmpBuf);
10101 void BTDM_DisplayBtCoexInfo(struct rtw_adapter *padapter)
10103 BTDM_Display8723ABtCoexInfo(padapter);
10106 void BTDM_RejectAPAggregatedPacket(struct rtw_adapter *padapter, u8 bReject)
10110 u8 BTDM_IsHT40(struct rtw_adapter *padapter)
10113 enum ht_channel_width bw;
10115 bw = padapter->mlmeextpriv.cur_bwmode;
10117 if (bw == HT_CHANNEL_WIDTH_20)
10119 else if (bw == HT_CHANNEL_WIDTH_40)
10125 u8 BTDM_Legacy(struct rtw_adapter *padapter)
10127 struct mlme_ext_priv *pmlmeext;
10128 u8 isLegacy = false;
10130 pmlmeext = &padapter->mlmeextpriv;
10131 if ((pmlmeext->cur_wireless_mode == WIRELESS_11B) ||
10132 (pmlmeext->cur_wireless_mode == WIRELESS_11G) ||
10133 (pmlmeext->cur_wireless_mode == WIRELESS_11BG))
10139 void BTDM_CheckWiFiState(struct rtw_adapter *padapter)
10141 struct hal_data_8723a *pHalData;
10142 struct mlme_priv *pmlmepriv;
10143 struct bt_30info *pBTInfo;
10144 struct bt_mgnt *pBtMgnt;
10146 pHalData = GET_HAL_DATA(padapter);
10147 pmlmepriv = &padapter->mlmepriv;
10148 pBTInfo = GET_BT_INFO(padapter);
10149 pBtMgnt = &pBTInfo->BtMgnt;
10151 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
10152 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_IDLE;
10154 if (pmlmepriv->LinkDetectInfo.bTxBusyTraffic)
10155 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_UPLINK;
10157 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10159 if (pmlmepriv->LinkDetectInfo.bRxBusyTraffic)
10160 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_DOWNLINK;
10162 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10164 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_IDLE;
10165 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10166 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10169 if (BTDM_Legacy(padapter)) {
10170 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_LEGACY;
10171 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10172 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10174 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_LEGACY;
10175 if (BTDM_IsHT40(padapter)) {
10176 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT40;
10177 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10179 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT20;
10180 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10184 if (pBtMgnt->BtOperationOn)
10185 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT30;
10187 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT30;
10190 s32 BTDM_GetRxSS(struct rtw_adapter *padapter)
10192 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10193 struct mlme_priv *pmlmepriv;
10194 struct hal_data_8723a *pHalData;
10195 s32 UndecoratedSmoothedPWDB = 0;
10197 pmlmepriv = &padapter->mlmepriv;
10198 pHalData = GET_HAL_DATA(padapter);
10200 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10201 UndecoratedSmoothedPWDB = GET_UNDECORATED_AVERAGE_RSSI(padapter);
10202 } else { /* associated entry pwdb */
10203 UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10204 /* pHalData->BT_EntryMinUndecoratedSmoothedPWDB */
10206 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxSS() = %d\n", UndecoratedSmoothedPWDB));
10207 return UndecoratedSmoothedPWDB;
10210 static s32 BTDM_GetRxBeaconSS(struct rtw_adapter *padapter)
10212 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10213 struct mlme_priv *pmlmepriv;
10214 struct hal_data_8723a *pHalData;
10215 s32 pwdbBeacon = 0;
10217 pmlmepriv = &padapter->mlmepriv;
10218 pHalData = GET_HAL_DATA(padapter);
10220 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10221 /* pwdbBeacon = pHalData->dmpriv.UndecoratedSmoothedBeacon; */
10222 pwdbBeacon = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10224 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxBeaconSS() = %d\n", pwdbBeacon));
10228 /* Get beacon rssi state */
10229 u8 BTDM_CheckCoexBcnRssiState(struct rtw_adapter *padapter, u8 levelNum,
10230 u8 RssiThresh, u8 RssiThresh1)
10232 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10233 s32 pwdbBeacon = 0;
10234 u8 bcnRssiState = 0;
10236 pwdbBeacon = BTDM_GetRxBeaconSS(padapter);
10238 if (levelNum == 2) {
10239 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10241 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10242 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10243 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10244 bcnRssiState = BT_RSSI_STATE_HIGH;
10245 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10246 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10247 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10249 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10250 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10253 if (pwdbBeacon < RssiThresh) {
10254 bcnRssiState = BT_RSSI_STATE_LOW;
10255 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10256 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10257 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10259 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10260 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10263 } else if (levelNum == 3) {
10264 if (RssiThresh > RssiThresh1) {
10265 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON thresh error!!\n"));
10266 return pHalData->bt_coexist.preRssiStateBeacon;
10269 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10270 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10271 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10272 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10273 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10274 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10275 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10276 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10278 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10279 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10281 } else if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_MEDIUM) ||
10282 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_MEDIUM)) {
10283 if (pwdbBeacon >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10284 bcnRssiState = BT_RSSI_STATE_HIGH;
10285 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10286 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10287 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10288 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10289 } else if (pwdbBeacon < RssiThresh) {
10290 bcnRssiState = BT_RSSI_STATE_LOW;
10291 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10292 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10293 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10294 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10296 bcnRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10297 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Medium\n"));
10300 if (pwdbBeacon < RssiThresh1) {
10301 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10302 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10303 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10304 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10305 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10307 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10308 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10313 pHalData->bt_coexist.preRssiStateBeacon = bcnRssiState;
10315 return bcnRssiState;
10318 u8 BTDM_CheckCoexRSSIState1(struct rtw_adapter *padapter, u8 levelNum,
10319 u8 RssiThresh, u8 RssiThresh1)
10321 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10322 s32 UndecoratedSmoothedPWDB = 0;
10323 u8 btRssiState = 0;
10325 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10327 if (levelNum == 2) {
10328 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10330 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10331 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10332 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10333 btRssiState = BT_RSSI_STATE_HIGH;
10334 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10335 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10336 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10338 btRssiState = BT_RSSI_STATE_STAY_LOW;
10339 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10342 if (UndecoratedSmoothedPWDB < RssiThresh) {
10343 btRssiState = BT_RSSI_STATE_LOW;
10344 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10345 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10346 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10348 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10349 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10352 } else if (levelNum == 3) {
10353 if (RssiThresh > RssiThresh1) {
10354 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 thresh error!!\n"));
10355 return pHalData->bt_coexist.preRssiState1;
10358 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10359 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10360 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10361 btRssiState = BT_RSSI_STATE_MEDIUM;
10362 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10363 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10364 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10365 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10367 btRssiState = BT_RSSI_STATE_STAY_LOW;
10368 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10370 } else if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_MEDIUM) ||
10371 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_MEDIUM)) {
10372 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10373 btRssiState = BT_RSSI_STATE_HIGH;
10374 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10375 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10376 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10377 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10378 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10379 btRssiState = BT_RSSI_STATE_LOW;
10380 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10381 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10382 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10383 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10385 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10386 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Medium\n"));
10389 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10390 btRssiState = BT_RSSI_STATE_MEDIUM;
10391 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10392 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10393 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10394 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10396 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10397 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10402 pHalData->bt_coexist.preRssiState1 = btRssiState;
10404 return btRssiState;
10407 u8 BTDM_CheckCoexRSSIState(struct rtw_adapter *padapter, u8 levelNum,
10408 u8 RssiThresh, u8 RssiThresh1)
10410 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10411 s32 UndecoratedSmoothedPWDB = 0;
10412 u8 btRssiState = 0;
10414 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10416 if (levelNum == 2) {
10417 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10419 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10420 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10421 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10422 btRssiState = BT_RSSI_STATE_HIGH;
10423 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10424 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10425 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10427 btRssiState = BT_RSSI_STATE_STAY_LOW;
10428 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10431 if (UndecoratedSmoothedPWDB < RssiThresh) {
10432 btRssiState = BT_RSSI_STATE_LOW;
10433 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10434 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10435 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10437 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10438 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10441 } else if (levelNum == 3) {
10442 if (RssiThresh > RssiThresh1) {
10443 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI thresh error!!\n"));
10444 return pHalData->bt_coexist.preRssiState;
10447 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10448 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10449 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10450 btRssiState = BT_RSSI_STATE_MEDIUM;
10451 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10452 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10453 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10454 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10456 btRssiState = BT_RSSI_STATE_STAY_LOW;
10457 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10459 } else if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_MEDIUM) ||
10460 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_MEDIUM)) {
10461 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10462 btRssiState = BT_RSSI_STATE_HIGH;
10463 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10464 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10465 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10466 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10467 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10468 btRssiState = BT_RSSI_STATE_LOW;
10469 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10470 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10471 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10472 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10474 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10475 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Medium\n"));
10478 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10479 btRssiState = BT_RSSI_STATE_MEDIUM;
10480 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10481 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10482 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10483 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10485 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10486 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10491 pHalData->bt_coexist.preRssiState = btRssiState;
10493 return btRssiState;
10496 bool rtl8723a_BT_disable_EDCA_turbo(struct rtw_adapter *padapter)
10498 struct bt_mgnt *pBtMgnt;
10499 struct hal_data_8723a *pHalData;
10500 u8 bBtChangeEDCA = false;
10501 u32 EDCA_BT_BE = 0x5ea42b, cur_EDCA_reg;
10504 pHalData = GET_HAL_DATA(padapter);
10505 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10507 if (!rtl8723a_BT_coexist(padapter)) {
10509 pHalData->bt_coexist.lastBtEdca = 0;
10512 if (!((pBtMgnt->bSupportProfile) ||
10513 (pHalData->bt_coexist.BT_CoexistType == BT_CSR_BC8))) {
10515 pHalData->bt_coexist.lastBtEdca = 0;
10519 if (rtl8723a_BT_using_antenna_1(padapter)) {
10521 pHalData->bt_coexist.lastBtEdca = 0;
10525 if (pHalData->bt_coexist.exec_cnt < 3)
10526 pHalData->bt_coexist.exec_cnt++;
10528 pHalData->bt_coexist.bEDCAInitialized = true;
10530 /* When BT is non idle */
10531 if (!(pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)) {
10532 RTPRINT(FBT, BT_TRACE, ("BT state non idle, set bt EDCA\n"));
10534 /* aggr_num = 0x0909; */
10535 if (pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA) {
10536 bBtChangeEDCA = true;
10537 pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA = false;
10538 pHalData->dmpriv.prv_traffic_idx = 3;
10540 cur_EDCA_reg = rtl8723au_read32(padapter, REG_EDCA_BE_PARAM);
10542 if (cur_EDCA_reg != EDCA_BT_BE)
10543 bBtChangeEDCA = true;
10544 if (bBtChangeEDCA || !pHalData->bt_coexist.bEDCAInitialized) {
10545 rtl8723au_write32(padapter, REG_EDCA_BE_PARAM,
10547 pHalData->bt_coexist.lastBtEdca = EDCA_BT_BE;
10551 RTPRINT(FBT, BT_TRACE, ("BT state idle, set original EDCA\n"));
10552 pHalData->bt_coexist.lastBtEdca = 0;
10560 struct rtw_adapter *padapter,
10566 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10567 u8 H2C_Parameter[3] = {0};
10570 H2C_Parameter[2] = 1;
10571 H2C_Parameter[1] = ms1;
10572 H2C_Parameter[0] = ms0;
10573 pHalData->bt_coexist.bFWCoexistAllOff = false;
10575 H2C_Parameter[2] = 0;
10576 H2C_Parameter[1] = 0;
10577 H2C_Parameter[0] = 0;
10579 pHalData->bt_coexist.bBalanceOn = bBalanceOn;
10581 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Balance =[%s:%dms:%dms], write 0xc = 0x%x\n",
10582 bBalanceOn?"ON":"OFF", ms0, ms1,
10583 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10585 FillH2CCmd(padapter, 0xc, 3, H2C_Parameter);
10588 void BTDM_AGCTable(struct rtw_adapter *padapter, u8 type)
10590 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10591 if (type == BT_AGCTABLE_OFF) {
10592 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable Off!\n"));
10593 rtl8723au_write32(padapter, 0xc78, 0x641c0001);
10594 rtl8723au_write32(padapter, 0xc78, 0x631d0001);
10595 rtl8723au_write32(padapter, 0xc78, 0x621e0001);
10596 rtl8723au_write32(padapter, 0xc78, 0x611f0001);
10597 rtl8723au_write32(padapter, 0xc78, 0x60200001);
10599 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x32000);
10600 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x71000);
10601 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xb0000);
10602 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xfc000);
10603 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x30355);
10605 pHalData->bt_coexist.b8723aAgcTableOn = false;
10606 } else if (type == BT_AGCTABLE_ON) {
10607 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable On!\n"));
10608 rtl8723au_write32(padapter, 0xc78, 0x4e1c0001);
10609 rtl8723au_write32(padapter, 0xc78, 0x4d1d0001);
10610 rtl8723au_write32(padapter, 0xc78, 0x4c1e0001);
10611 rtl8723au_write32(padapter, 0xc78, 0x4b1f0001);
10612 rtl8723au_write32(padapter, 0xc78, 0x4a200001);
10614 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xdc000);
10615 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x90000);
10616 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x51000);
10617 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x12000);
10618 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x00355);
10620 pHalData->bt_coexist.b8723aAgcTableOn = true;
10622 pHalData->bt_coexist.bSWCoexistAllOff = false;
10626 void BTDM_BBBackOffLevel(struct rtw_adapter *padapter, u8 type)
10628 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10630 if (type == BT_BB_BACKOFF_OFF) {
10631 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel Off!\n"));
10632 rtl8723au_write32(padapter, 0xc04, 0x3a05611);
10633 } else if (type == BT_BB_BACKOFF_ON) {
10634 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel On!\n"));
10635 rtl8723au_write32(padapter, 0xc04, 0x3a07611);
10636 pHalData->bt_coexist.bSWCoexistAllOff = false;
10640 void BTDM_FWCoexAllOff(struct rtw_adapter *padapter)
10642 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10644 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff()\n"));
10645 if (pHalData->bt_coexist.bFWCoexistAllOff)
10647 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff(), real Do\n"));
10649 BTDM_FWCoexAllOff8723A(padapter);
10651 pHalData->bt_coexist.bFWCoexistAllOff = true;
10654 void BTDM_SWCoexAllOff(struct rtw_adapter *padapter)
10656 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10658 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff()\n"));
10659 if (pHalData->bt_coexist.bSWCoexistAllOff)
10661 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff(), real Do\n"));
10662 BTDM_SWCoexAllOff8723A(padapter);
10664 pHalData->bt_coexist.bSWCoexistAllOff = true;
10667 void BTDM_HWCoexAllOff(struct rtw_adapter *padapter)
10669 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10671 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff()\n"));
10672 if (pHalData->bt_coexist.bHWCoexistAllOff)
10674 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff(), real Do\n"));
10676 BTDM_HWCoexAllOff8723A(padapter);
10678 pHalData->bt_coexist.bHWCoexistAllOff = true;
10681 void BTDM_CoexAllOff(struct rtw_adapter *padapter)
10683 BTDM_FWCoexAllOff(padapter);
10684 BTDM_SWCoexAllOff(padapter);
10685 BTDM_HWCoexAllOff(padapter);
10688 void rtl8723a_BT_disable_coexist(struct rtw_adapter *padapter)
10690 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
10692 if (!rtl8723a_BT_coexist(padapter))
10695 /* 8723 1Ant doesn't need to turn off bt coexist mechanism. */
10696 if (rtl8723a_BT_using_antenna_1(padapter))
10699 /* Before enter IPS, turn off FW BT Co-exist mechanism */
10700 if (ppwrctrl->reg_rfoff == rf_on) {
10701 RTPRINT(FBT, BT_TRACE, ("[BT][DM], Before enter IPS, turn off all Coexist DM\n"));
10702 btdm_ResetFWCoexState(padapter);
10703 BTDM_CoexAllOff(padapter);
10704 BTDM_SetAntenna(padapter, BTDM_ANT_BT);
10708 void BTDM_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
10710 BTDM_8723ASignalCompensation(padapter, rssi_wifi, rssi_bt);
10713 void rtl8723a_BT_do_coexist(struct rtw_adapter *padapter)
10715 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10717 if (!rtl8723a_BT_coexist(padapter)) {
10718 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT not exists!!\n"));
10722 if (!pHalData->bt_coexist.bInitlized) {
10723 RTPRINT(FBT, BT_TRACE, ("[DM][BT], btdm_InitBtCoexistDM()\n"));
10724 btdm_InitBtCoexistDM(padapter);
10727 RTPRINT(FBT, BT_TRACE, ("\n\n[DM][BT], BTDM start!!\n"));
10729 BTDM_PWDBMonitor(padapter);
10731 RTPRINT(FBT, BT_TRACE, ("[DM][BT], HW type is 8723\n"));
10732 BTDM_BTCoexist8723A(padapter);
10733 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BTDM end!!\n\n"));
10736 void BTDM_UpdateCoexState(struct rtw_adapter *padapter)
10738 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10740 if (!BTDM_IsSameCoexistState(padapter)) {
10741 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x, changeBits = 0x%"i64fmt"x\n",
10742 pHalData->bt_coexist.PreviousState,
10743 pHalData->bt_coexist.CurrentState,
10744 (pHalData->bt_coexist.PreviousState^pHalData->bt_coexist.CurrentState)));
10745 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
10749 u8 BTDM_IsSameCoexistState(struct rtw_adapter *padapter)
10751 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10753 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState) {
10756 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Coexist state changed!!\n"));
10761 void BTDM_PWDBMonitor(struct rtw_adapter *padapter)
10763 struct bt_30info *pBTInfo = GET_BT_INFO(GetDefaultAdapter(padapter));
10764 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10765 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10766 u8 H2C_Parameter[3] = {0};
10767 s32 tmpBTEntryMaxPWDB = 0, tmpBTEntryMinPWDB = 0xff;
10770 if (pBtMgnt->BtOperationOn) {
10771 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
10772 if (pBTInfo->BtAsocEntry[i].bUsed) {
10773 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB < tmpBTEntryMinPWDB)
10774 tmpBTEntryMinPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10775 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB > tmpBTEntryMaxPWDB)
10776 tmpBTEntryMaxPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10777 /* Report every BT connection (HS mode) RSSI to FW */
10778 H2C_Parameter[2] = (u8)(pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB & 0xFF);
10779 H2C_Parameter[0] = (MAX_FW_SUPPORT_MACID_NUM-1-i);
10780 RTPRINT(FDM, DM_BT30, ("RSSI report for BT[%d], H2C_Par = 0x%x\n", i, H2C_Parameter[0]));
10781 FillH2CCmd(padapter, RSSI_SETTING_EID, 3, H2C_Parameter);
10782 RTPRINT_ADDR(FDM, (DM_PWDB|DM_BT30), ("BT_Entry Mac :"),
10783 pBTInfo->BtAsocEntry[i].BTRemoteMACAddr)
10784 RTPRINT(FDM, (DM_PWDB|DM_BT30),
10785 ("BT rx pwdb[%d] = 0x%x(%d)\n", i,
10786 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB,
10787 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB));
10790 if (tmpBTEntryMaxPWDB != 0) { /* If associated entry is found */
10791 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = tmpBTEntryMaxPWDB;
10792 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMaxPWDB = 0x%x(%d)\n",
10793 tmpBTEntryMaxPWDB, tmpBTEntryMaxPWDB));
10795 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = 0;
10797 if (tmpBTEntryMinPWDB != 0xff) { /* If associated entry is found */
10798 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = tmpBTEntryMinPWDB;
10799 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMinPWDB = 0x%x(%d)\n",
10800 tmpBTEntryMinPWDB, tmpBTEntryMinPWDB));
10802 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = 0;
10807 u8 BTDM_IsBTBusy(struct rtw_adapter *padapter)
10809 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10810 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10812 if (pBtMgnt->ExtConfig.bBTBusy)
10818 u8 BTDM_IsWifiBusy(struct rtw_adapter *padapter)
10820 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10821 struct mlme_priv *pmlmepriv = &GetDefaultAdapter(padapter)->mlmepriv;
10822 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10823 struct bt_traffic *pBtTraffic = &pBTInfo->BtTraffic;
10825 if (pmlmepriv->LinkDetectInfo.bBusyTraffic ||
10826 pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic ||
10827 pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic)
10833 u8 BTDM_IsCoexistStateChanged(struct rtw_adapter *padapter)
10835 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10837 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState)
10843 u8 BTDM_IsWifiUplink(struct rtw_adapter *padapter)
10845 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10846 struct mlme_priv *pmlmepriv;
10847 struct bt_30info *pBTInfo;
10848 struct bt_traffic *pBtTraffic;
10850 pmlmepriv = &padapter->mlmepriv;
10851 pBTInfo = GET_BT_INFO(padapter);
10852 pBtTraffic = &pBTInfo->BtTraffic;
10854 if ((pmlmepriv->LinkDetectInfo.bTxBusyTraffic) ||
10855 (pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic))
10861 u8 BTDM_IsWifiDownlink(struct rtw_adapter *padapter)
10863 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10864 struct mlme_priv *pmlmepriv;
10865 struct bt_30info *pBTInfo;
10866 struct bt_traffic *pBtTraffic;
10868 pmlmepriv = &padapter->mlmepriv;
10869 pBTInfo = GET_BT_INFO(padapter);
10870 pBtTraffic = &pBTInfo->BtTraffic;
10872 if ((pmlmepriv->LinkDetectInfo.bRxBusyTraffic) ||
10873 (pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic))
10879 u8 BTDM_IsBTHSMode(struct rtw_adapter *padapter)
10881 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10882 struct hal_data_8723a *pHalData;
10883 struct bt_mgnt *pBtMgnt;
10885 pHalData = GET_HAL_DATA(padapter);
10886 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10888 if (pBtMgnt->BtOperationOn)
10894 u8 BTDM_IsBTUplink(struct rtw_adapter *padapter)
10896 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10898 if (pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic)
10904 u8 BTDM_IsBTDownlink(struct rtw_adapter *padapter)
10906 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10908 if (pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic)
10914 void BTDM_AdjustForBtOperation(struct rtw_adapter *padapter)
10916 RTPRINT(FBT, BT_TRACE, ("[BT][DM], BTDM_AdjustForBtOperation()\n"));
10917 BTDM_AdjustForBtOperation8723A(padapter);
10920 void BTDM_SetBtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
10922 BTDM_Set8723ABtCoexCurrAntNum(padapter, antNum);
10925 void BTDM_ForHalt(struct rtw_adapter *padapter)
10927 if (!rtl8723a_BT_coexist(padapter))
10930 BTDM_ForHalt8723A(padapter);
10931 GET_HAL_DATA(padapter)->bt_coexist.bInitlized = false;
10934 void BTDM_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
10936 if (!rtl8723a_BT_coexist(padapter))
10939 BTDM_WifiScanNotify8723A(padapter, scanType);
10942 void BTDM_WifiAssociateNotify(struct rtw_adapter *padapter, u8 action)
10944 if (!rtl8723a_BT_coexist(padapter))
10947 BTDM_WifiAssociateNotify8723A(padapter, action);
10950 void rtl8723a_BT_mediastatus_notify(struct rtw_adapter *padapter,
10951 enum rt_media_status mstatus)
10953 if (!rtl8723a_BT_coexist(padapter))
10956 BTDM_MediaStatusNotify8723A(padapter, mstatus);
10959 void rtl8723a_BT_specialpacket_notify(struct rtw_adapter *padapter)
10961 if (!rtl8723a_BT_coexist(padapter))
10964 BTDM_ForDhcp8723A(padapter);
10967 void BTDM_ResetActionProfileState(struct rtw_adapter *padapter)
10969 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10971 pHalData->bt_coexist.CurrentState &= ~\
10972 (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP|
10973 BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_SCO);
10976 u8 BTDM_IsActionSCO(struct rtw_adapter *padapter)
10978 struct hal_data_8723a *pHalData;
10979 struct bt_30info *pBTInfo;
10980 struct bt_mgnt *pBtMgnt;
10981 struct bt_dgb *pBtDbg;
10984 pHalData = GET_HAL_DATA(padapter);
10985 pBTInfo = GET_BT_INFO(padapter);
10986 pBtMgnt = &pBTInfo->BtMgnt;
10987 pBtDbg = &pBTInfo->BtDbg;
10990 if (pBtDbg->dbgCtrl) {
10991 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_SCO) {
10992 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
10996 if (pBtMgnt->ExtConfig.NumberOfSCO > 0) {
10997 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
11004 u8 BTDM_IsActionHID(struct rtw_adapter *padapter)
11006 struct bt_30info *pBTInfo;
11007 struct hal_data_8723a *pHalData;
11008 struct bt_mgnt *pBtMgnt;
11009 struct bt_dgb *pBtDbg;
11012 pHalData = GET_HAL_DATA(padapter);
11013 pBTInfo = GET_BT_INFO(padapter);
11014 pBtMgnt = &pBTInfo->BtMgnt;
11015 pBtDbg = &pBTInfo->BtDbg;
11018 if (pBtDbg->dbgCtrl) {
11019 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID) {
11020 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11024 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11025 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11026 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11033 u8 BTDM_IsActionA2DP(struct rtw_adapter *padapter)
11035 struct hal_data_8723a *pHalData;
11036 struct bt_30info *pBTInfo;
11037 struct bt_mgnt *pBtMgnt;
11038 struct bt_dgb *pBtDbg;
11041 pHalData = GET_HAL_DATA(padapter);
11042 pBTInfo = GET_BT_INFO(padapter);
11043 pBtMgnt = &pBTInfo->BtMgnt;
11044 pBtDbg = &pBTInfo->BtDbg;
11047 if (pBtDbg->dbgCtrl) {
11048 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_A2DP) {
11049 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11053 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP) &&
11054 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11055 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11062 u8 BTDM_IsActionPAN(struct rtw_adapter *padapter)
11064 struct hal_data_8723a *pHalData;
11065 struct bt_30info *pBTInfo;
11066 struct bt_mgnt *pBtMgnt;
11067 struct bt_dgb *pBtDbg;
11070 pHalData = GET_HAL_DATA(padapter);
11071 pBTInfo = GET_BT_INFO(padapter);
11072 pBtMgnt = &pBTInfo->BtMgnt;
11073 pBtDbg = &pBTInfo->BtDbg;
11076 if (pBtDbg->dbgCtrl) {
11077 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN) {
11078 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11082 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
11083 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11084 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11091 u8 BTDM_IsActionHIDA2DP(struct rtw_adapter *padapter)
11093 struct hal_data_8723a *pHalData;
11094 struct bt_30info *pBTInfo;
11095 struct bt_mgnt *pBtMgnt;
11096 struct bt_dgb *pBtDbg;
11099 pHalData = GET_HAL_DATA(padapter);
11100 pBTInfo = GET_BT_INFO(padapter);
11101 pBtMgnt = &pBTInfo->BtMgnt;
11102 pBtDbg = &pBTInfo->BtDbg;
11105 if (pBtDbg->dbgCtrl) {
11106 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_A2DP) {
11107 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11111 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11112 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11113 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11120 u8 BTDM_IsActionHIDPAN(struct rtw_adapter *padapter)
11122 struct hal_data_8723a *pHalData;
11123 struct bt_30info *pBTInfo;
11124 struct bt_dgb *pBtDbg;
11127 pHalData = GET_HAL_DATA(padapter);
11128 pBTInfo = GET_BT_INFO(padapter);
11129 pBtDbg = &pBTInfo->BtDbg;
11132 if (pBtDbg->dbgCtrl) {
11133 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_PAN) {
11134 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11138 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11139 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
11140 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11147 u8 BTDM_IsActionPANA2DP(struct rtw_adapter *padapter)
11149 struct hal_data_8723a *pHalData;
11150 struct bt_30info *pBTInfo;
11151 struct bt_dgb *pBtDbg;
11154 pHalData = GET_HAL_DATA(padapter);
11155 pBTInfo = GET_BT_INFO(padapter);
11156 pBtDbg = &pBTInfo->BtDbg;
11159 if (pBtDbg->dbgCtrl) {
11160 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN_A2DP) {
11161 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11165 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) && BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11166 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11173 bool rtl8723a_BT_enabled(struct rtw_adapter *padapter)
11175 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11177 if (pHalData->bt_coexist.bCurBtDisabled)
11183 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
11185 /* ===== Below this line is sync from SD7 driver HAL/HalBT.c ===== */
11188 /*local function */
11191 static void halbt_InitHwConfig8723A(struct rtw_adapter *padapter)
11196 /*extern function */
11198 u8 HALBT_GetPGAntNum(struct rtw_adapter *padapter)
11200 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11202 return pHalData->bt_coexist.BT_Ant_Num;
11205 void HALBT_SetKey(struct rtw_adapter *padapter, u8 EntryNum)
11207 struct bt_30info *pBTinfo;
11208 struct bt_asoc_entry *pBtAssocEntry;
11211 pBTinfo = GET_BT_INFO(padapter);
11212 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11214 pBtAssocEntry->HwCAMIndex = BT_HWCAM_STAR + EntryNum;
11216 usConfig = CAM_VALID | (CAM_AES << 2);
11217 rtl8723a_cam_write(padapter, pBtAssocEntry->HwCAMIndex, usConfig,
11218 pBtAssocEntry->BTRemoteMACAddr,
11219 pBtAssocEntry->PTK + TKIP_ENC_KEY_POS);
11222 void HALBT_RemoveKey(struct rtw_adapter *padapter, u8 EntryNum)
11224 struct bt_30info *pBTinfo;
11225 struct bt_asoc_entry *pBtAssocEntry;
11227 pBTinfo = GET_BT_INFO(padapter);
11228 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11230 if (pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex != 0) {
11231 /* ToDo : add New HALBT_RemoveKey function !! */
11232 if (pBtAssocEntry->HwCAMIndex >= BT_HWCAM_STAR &&
11233 pBtAssocEntry->HwCAMIndex < HALF_CAM_ENTRY)
11234 rtl8723a_cam_empty_entry(padapter,
11235 pBtAssocEntry->HwCAMIndex);
11236 pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex = 0;
11240 void rtl8723a_BT_init_hal_vars(struct rtw_adapter *padapter)
11242 struct hal_data_8723a *pHalData;
11244 pHalData = GET_HAL_DATA(padapter);
11246 pHalData->bt_coexist.BluetoothCoexist = pHalData->EEPROMBluetoothCoexist;
11247 pHalData->bt_coexist.BT_Ant_Num = pHalData->EEPROMBluetoothAntNum;
11248 pHalData->bt_coexist.BT_CoexistType = pHalData->EEPROMBluetoothType;
11249 pHalData->bt_coexist.BT_Ant_isolation = pHalData->EEPROMBluetoothAntIsolation;
11250 pHalData->bt_coexist.bt_radiosharedtype = pHalData->EEPROMBluetoothRadioShared;
11252 RT_TRACE(_module_hal_init_c_, _drv_info_,
11253 ("BT Coexistance = 0x%x\n", rtl8723a_BT_coexist(padapter)));
11255 if (rtl8723a_BT_coexist(padapter)) {
11256 if (pHalData->bt_coexist.BT_Ant_Num == Ant_x2) {
11257 BTDM_SetBtCoexCurrAntNum(padapter, 2);
11258 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx2\n"));
11259 } else if (pHalData->bt_coexist.BT_Ant_Num == Ant_x1) {
11260 BTDM_SetBtCoexCurrAntNum(padapter, 1);
11261 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx1\n"));
11263 pHalData->bt_coexist.bBTBusyTraffic = false;
11264 pHalData->bt_coexist.bBTTrafficModeSet = false;
11265 pHalData->bt_coexist.bBTNonTrafficModeSet = false;
11266 pHalData->bt_coexist.CurrentState = 0;
11267 pHalData->bt_coexist.PreviousState = 0;
11269 RT_TRACE(_module_hal_init_c_, _drv_info_,
11270 ("bt_radiosharedType = 0x%x\n",
11271 pHalData->bt_coexist.bt_radiosharedtype));
11275 bool rtl8723a_BT_coexist(struct rtw_adapter *padapter)
11277 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11279 if (pHalData->bt_coexist.BluetoothCoexist)
11285 u8 HALBT_BTChipType(struct rtw_adapter *padapter)
11287 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11289 return pHalData->bt_coexist.BT_CoexistType;
11292 void rtl8723a_BT_init_hwconfig(struct rtw_adapter *padapter)
11294 halbt_InitHwConfig8723A(padapter);
11295 rtl8723a_BT_do_coexist(padapter);
11298 void HALBT_SetRtsCtsNoLenLimit(struct rtw_adapter *padapter)
11302 /* ===== End of sync from SD7 driver HAL/HalBT.c ===== */
11304 void rtl8723a_dual_antenna_detection(struct rtw_adapter *padapter)
11306 struct hal_data_8723a *pHalData;
11307 struct dm_odm_t *pDM_Odm;
11308 struct sw_ant_sw *pDM_SWAT_Table;
11311 pHalData = GET_HAL_DATA(padapter);
11312 pDM_Odm = &pHalData->odmpriv;
11313 pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
11316 /* <Roger_Notes> RTL8723A Single and Dual antenna dynamic detection
11317 mechanism when RF power state is on. */
11318 /* We should take power tracking, IQK, LCK, RCK RF read/write
11319 operation into consideration. */
11322 if (!pHalData->bAntennaDetected) {
11323 u8 btAntNum = BT_GetPGAntNum(padapter);
11325 /* Set default antenna B status */
11326 if (btAntNum == Ant_x2)
11327 pDM_SWAT_Table->ANTB_ON = true;
11328 else if (btAntNum == Ant_x1)
11329 pDM_SWAT_Table->ANTB_ON = false;
11331 pDM_SWAT_Table->ANTB_ON = true;
11333 if (pHalData->CustomerID != RT_CID_TOSHIBA) {
11334 for (i = 0; i < MAX_ANTENNA_DETECTION_CNT; i++) {
11335 if (ODM_SingleDualAntennaDetection
11336 (&pHalData->odmpriv, ANTTESTALL) == true)
11340 /* Set default antenna number for BT coexistence */
11341 if (btAntNum == Ant_x2)
11342 BT_SetBtCoexCurrAntNum(padapter,
11346 pHalData->bAntennaDetected = true;