1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 *published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
15 #include <drv_types.h>
16 #include <rtl8723a_hal.h>
17 #include <usb_ops_linux.h>
21 u32 BTCoexDbgLevel = _bt_dbg_off_;
23 #define RTPRINT(_Comp, _Level, Fmt)\
25 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
30 #define RTPRINT_ADDR(dbgtype, dbgflag, printstr, _Ptr)\
31 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
33 u8 *ptr = (u8 *)_Ptr; \
36 for (__i = 0; __i < 6; __i++) \
37 printk("%02X%s", ptr[__i], (__i == 5)?"":"-"); \
40 #define RTPRINT_DATA(dbgtype, dbgflag, _TitleString, _HexData, _HexDataLen)\
41 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
43 u8 *ptr = (u8 *)_HexData; \
44 printk(_TitleString); \
45 for (__i = 0; __i < (u32)_HexDataLen; __i++) { \
46 printk("%02X%s", ptr[__i], (((__i + 1) % 4) == 0)?" ":" ");\
47 if (((__i + 1) % 16) == 0) \
52 /* Added by Annie, 2005-11-22. */
53 #define MAX_STR_LEN 64
54 /* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. */
55 #define PRINTABLE(_ch) (_ch >= ' ' && _ch <= '~')
56 #define RT_PRINT_STR(_Comp, _Level, _TitleString, _Ptr, _Len) \
59 u8 buffer[MAX_STR_LEN]; \
60 u32 length = (_Len < MAX_STR_LEN) ? _Len : (MAX_STR_LEN-1);\
61 memset(buffer, 0, MAX_STR_LEN); \
62 memcpy(buffer, (u8 *)_Ptr, length); \
63 for (__i = 0; __i < length; __i++) { \
64 if (!PRINTABLE(buffer[__i])) \
67 buffer[length] = '\0'; \
68 printk(_TitleString); \
69 printk(": %d, <%s>\n", _Len, buffer); \
72 #define DCMD_Printf(...)
73 #define RT_ASSERT(...)
75 #define rsprintf snprintf
77 #define GetDefaultAdapter(padapter) padapter
79 #define PlatformZeroMemory(ptr, sz) memset(ptr, 0, sz)
81 #define PlatformProcessHCICommands(...)
82 #define PlatformTxBTQueuedPackets(...)
83 #define PlatformIndicateBTACLData(...) (RT_STATUS_SUCCESS)
84 #define PlatformAcquireSpinLock(padapter, type)
85 #define PlatformReleaseSpinLock(padapter, type)
87 #define GET_UNDECORATED_AVERAGE_RSSI(padapter) \
88 (GET_HAL_DATA(padapter)->dmpriv.EntryMinUndecoratedSmoothedPWDB)
89 #define RT_RF_CHANGE_SOURCE u32
100 /* ===== Below this line is sync from SD7 driver COMMOM/BT.c ===== */
102 static u8 BT_Operation(struct rtw_adapter *padapter)
104 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
105 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
107 if (pBtMgnt->BtOperationOn)
113 static u8 BT_IsLegalChannel(struct rtw_adapter *padapter, u8 channel)
115 struct rt_channel_info *pChanneList = NULL;
118 pChanneList = padapter->mlmeextpriv.channel_set;
119 channelLen = padapter->mlmeextpriv.max_chan_nums;
121 for (i = 0; i < channelLen; i++) {
122 RTPRINT(FIOCTL, IOCTL_STATE,
123 ("Check if chnl(%d) in channel plan contains bt target chnl(%d) for BT connection\n",
124 pChanneList[i].ChannelNum, channel));
125 if ((channel == pChanneList[i].ChannelNum) ||
126 (channel == pChanneList[i].ChannelNum + 2))
132 void BT_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
134 BTDM_SignalCompensation(padapter, rssi_wifi, rssi_bt);
137 void rtl8723a_BT_wifiscan_notify(struct rtw_adapter *padapter, u8 scanType)
139 BTHCI_WifiScanNotify(padapter, scanType);
140 BTDM_CheckAntSelMode(padapter);
141 BTDM_WifiScanNotify(padapter, scanType);
144 void rtl8723a_BT_wifiassociate_notify(struct rtw_adapter *padapter, u8 action)
147 /* true = associate start */
148 /* false = associate finished */
150 BTDM_CheckAntSelMode(padapter);
152 BTDM_WifiAssociateNotify(padapter, action);
155 void BT_HaltProcess(struct rtw_adapter *padapter)
157 BTDM_ForHalt(padapter);
160 /* ===== End of sync from SD7 driver COMMOM/BT.c ===== */
163 #define UINT64_C(v) (v)
165 #define FillOctetString(_os, _octet, _len) \
166 (_os).Octet = (u8 *)(_octet); \
167 (_os).Length = (_len);
169 static enum rt_status PlatformIndicateBTEvent(
170 struct rtw_adapter *padapter,
175 enum rt_status rt_status = RT_STATUS_FAILURE;
177 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event start, %d bytes data to Transferred!!\n", dataLen));
178 RTPRINT_DATA(FIOCTL, IOCTL_BT_EVENT_DETAIL, "To transfer Hex Data :\n",
181 BT_EventParse(padapter, pEvntData, dataLen);
183 printk(KERN_WARNING "%s: Linux has no way to report BT event!!\n", __func__);
185 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event end, %s\n",
186 (rt_status == RT_STATUS_SUCCESS) ? "SUCCESS" : "FAIL"));
191 /* ===== Below this line is sync from SD7 driver COMMOM/bt_hci.c ===== */
193 static u8 bthci_GetLocalChannel(struct rtw_adapter *padapter)
195 return padapter->mlmeextpriv.cur_channel;
198 static u8 bthci_GetCurrentEntryNum(struct rtw_adapter *padapter, u8 PhyHandle)
200 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
203 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
204 if ((pBTInfo->BtAsocEntry[i].bUsed) &&
205 (pBTInfo->BtAsocEntry[i].PhyLinkCmdData.BtPhyLinkhandle == PhyHandle))
212 static void bthci_DecideBTChannel(struct rtw_adapter *padapter, u8 EntryNum)
214 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
215 struct mlme_priv *pmlmepriv;
216 struct bt_30info *pBTInfo;
217 struct bt_mgnt *pBtMgnt;
218 struct bt_hci_info *pBtHciInfo;
219 struct chnl_txpower_triple *pTriple_subband = NULL;
220 struct common_triple *pTriple;
221 u8 i, j, localchnl, firstRemoteLegalChnlInTriplet = 0;
222 u8 regulatory_skipLen = 0;
223 u8 subbandTripletCnt = 0;
225 pmlmepriv = &padapter->mlmepriv;
226 pBTInfo = GET_BT_INFO(padapter);
227 pBtMgnt = &pBTInfo->BtMgnt;
228 pBtHciInfo = &pBTInfo->BtHciInfo;
230 pBtMgnt->CheckChnlIsSuit = true;
231 localchnl = bthci_GetLocalChannel(padapter);
233 pTriple = (struct common_triple *)
234 &pBtHciInfo->BTPreChnllist[COUNTRY_STR_LEN];
236 /* contains country string, len is 3 */
237 for (i = 0; i < (pBtHciInfo->BtPreChnlListLen-COUNTRY_STR_LEN); i += 3, pTriple++) {
239 /* check every triplet, an triplet may be */
240 /* regulatory extension identifier or sub-band triplet */
242 if (pTriple->byte_1st == 0xc9) {
243 /* Regulatory Extension Identifier, skip it */
244 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
245 ("Find Regulatory ID, regulatory class = %d\n", pTriple->byte_2nd));
246 regulatory_skipLen += 3;
247 pTriple_subband = NULL;
249 } else { /* Sub-band triplet */
250 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Find Sub-band triplet \n"));
252 pTriple_subband = (struct chnl_txpower_triple *)pTriple;
253 /* if remote first legal channel not found, then find first remote channel */
254 /* and it's legal for our channel plan. */
256 /* search the sub-band triplet and find if remote channel is legal to our channel plan. */
257 for (j = pTriple_subband->FirstChnl; j < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls); j++) {
258 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), (" Check if chnl(%d) is legal\n", j));
259 if (BT_IsLegalChannel(padapter, j)) {
260 /* remote channel is legal for our channel plan. */
261 firstRemoteLegalChnlInTriplet = j;
262 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
263 ("Find first remote legal channel : %d\n",
264 firstRemoteLegalChnlInTriplet));
266 /* If we find a remote legal channel in the sub-band triplet */
267 /* and only BT connection is established(local not connect to any AP or IBSS), */
268 /* then we just switch channel to remote channel. */
269 if (!(check_fwstate(pmlmepriv, WIFI_ASOC_STATE|WIFI_ADHOC_STATE|WIFI_AP_STATE) ||
270 BTHCI_HsConnectionEstablished(padapter))) {
271 pBtMgnt->BTChannel = firstRemoteLegalChnlInTriplet;
272 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Remote legal channel (%d) is selected, Local not connect to any!!\n", pBtMgnt->BTChannel));
275 if ((localchnl >= firstRemoteLegalChnlInTriplet) &&
276 (localchnl < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls))) {
277 pBtMgnt->BTChannel = localchnl;
278 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected, wifi or BT connection exists\n", pBtMgnt->BTChannel));
288 if (subbandTripletCnt) {
289 /* if any preferred channel triplet exists */
290 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("There are %d sub band triplet exists, ", subbandTripletCnt));
291 if (firstRemoteLegalChnlInTriplet == 0) {
292 /* no legal channel is found, reject the connection. */
293 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("no legal channel is found!!\n"));
295 /* Remote Legal channel is found but not match to local */
296 /* wifi connection exists), so reject the connection. */
297 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
298 ("Remote Legal channel is found but not match to local(wifi connection exists)!!\n"));
300 pBtMgnt->CheckChnlIsSuit = false;
302 /* There are not any preferred channel triplet exists */
303 /* Use current legal channel as the bt channel. */
304 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("No sub band triplet exists!!\n"));
306 pBtMgnt->BTChannel = localchnl;
307 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected!!\n", pBtMgnt->BTChannel));
310 /* Success:return true */
311 /* Fail:return false */
312 static u8 bthci_GetAssocInfo(struct rtw_adapter *padapter, u8 EntryNum)
314 struct bt_30info *pBTInfo;
315 struct bt_hci_info *pBtHciInfo;
318 u8 BaseMemoryShift = 0;
320 struct amp_assoc_structure *pAmpAsoc;
322 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo start\n"));
323 pBTInfo = GET_BT_INFO(padapter);
324 pBtHciInfo = &pBTInfo->BtHciInfo;
326 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar == 0) {
327 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen < (MAX_AMP_ASSOC_FRAG_LEN))
328 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen;
329 else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen == (MAX_AMP_ASSOC_FRAG_LEN))
330 TotalLen = MAX_AMP_ASSOC_FRAG_LEN;
331 } else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar > 0)
332 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar;
334 while ((pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar >= BaseMemoryShift) || TotalLen > BaseMemoryShift) {
335 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("GetAssocInfo, TotalLen =%d, BaseMemoryShift =%d\n", TotalLen, BaseMemoryShift));
337 (u8 *)pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment+BaseMemoryShift,
338 TotalLen-BaseMemoryShift);
339 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, "GetAssocInfo :\n",
340 tempBuf, TotalLen-BaseMemoryShift);
342 pAmpAsoc = (struct amp_assoc_structure *)tempBuf;
343 pAmpAsoc->Length = le16_to_cpu(pAmpAsoc->Length);
344 BaseMemoryShift += 3 + pAmpAsoc->Length;
346 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TypeID = 0x%x, ", pAmpAsoc->TypeID));
347 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Hex Data: \n", pAmpAsoc->Data, pAmpAsoc->Length);
348 switch (pAmpAsoc->TypeID) {
350 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_MAC_ADDR\n"));
351 if (pAmpAsoc->Length > 6)
353 memcpy(pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, pAmpAsoc->Data, 6);
354 RTPRINT_ADDR(FIOCTL, IOCTL_BT_HCICMD, ("Remote Mac address \n"), pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr);
356 case AMP_PREFERRED_CHANNEL_LIST:
357 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_PREFERRED_CHANNEL_LIST\n"));
358 pBtHciInfo->BtPreChnlListLen = pAmpAsoc->Length;
359 memcpy(pBtHciInfo->BTPreChnllist,
361 pBtHciInfo->BtPreChnlListLen);
362 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Preferred channel list : \n", pBtHciInfo->BTPreChnllist, pBtHciInfo->BtPreChnlListLen);
363 bthci_DecideBTChannel(padapter, EntryNum);
365 case AMP_CONNECTED_CHANNEL:
366 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_CONNECTED_CHANNEL\n"));
367 pBtHciInfo->BTConnectChnlListLen = pAmpAsoc->Length;
368 memcpy(pBtHciInfo->BTConnectChnllist,
370 pBtHciInfo->BTConnectChnlListLen);
372 case AMP_80211_PAL_CAP_LIST:
373 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_80211_PAL_CAP_LIST\n"));
374 pBTInfo->BtAsocEntry[EntryNum].BTCapability = *(u32 *)(pAmpAsoc->Data);
375 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000001) {
378 /* Signifies PAL capable of utilizing received activity reports. */
380 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000002) {
382 /* Signifies PAL is capable of utilizing scheduling information received in an activity reports. */
385 case AMP_80211_PAL_VISION:
386 pBtHciInfo->BTPalVersion = *(u8 *)(pAmpAsoc->Data);
387 pBtHciInfo->BTPalCompanyID = *(u16 *)(((u8 *)(pAmpAsoc->Data))+1);
388 pBtHciInfo->BTPalsubversion = *(u16 *)(((u8 *)(pAmpAsoc->Data))+3);
389 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("==> AMP_80211_PAL_VISION PalVersion 0x%x, PalCompanyID 0x%x, Palsubversion 0x%x\n",
390 pBtHciInfo->BTPalVersion,
391 pBtHciInfo->BTPalCompanyID,
392 pBtHciInfo->BTPalsubversion));
395 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> Unsupport TypeID !!\n"));
400 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo end\n"));
405 static u8 bthci_AddEntry(struct rtw_adapter *padapter)
407 struct bt_30info *pBTInfo;
408 struct bt_mgnt *pBtMgnt;
411 pBTInfo = GET_BT_INFO(padapter);
412 pBtMgnt = &pBTInfo->BtMgnt;
414 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
415 if (pBTInfo->BtAsocEntry[i].bUsed == false) {
416 pBTInfo->BtAsocEntry[i].bUsed = true;
417 pBtMgnt->CurrentConnectEntryNum = i;
422 if (i == MAX_BT_ASOC_ENTRY_NUM) {
423 RTPRINT(FIOCTL, IOCTL_STATE, ("bthci_AddEntry(), Add entry fail!!\n"));
429 static u8 bthci_DiscardTxPackets(struct rtw_adapter *padapter, u16 LLH)
435 bthci_CheckLogLinkBehavior(
436 struct rtw_adapter *padapter,
437 struct hci_flow_spec TxFlowSpec
440 u8 ID = TxFlowSpec.Identifier;
441 u8 ServiceType = TxFlowSpec.ServiceType;
442 u16 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
443 u32 SDUInterArrivatime = TxFlowSpec.SDUInterArrivalTime;
448 if (ServiceType == BT_LL_BE) {
450 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX best effort flowspec\n"));
451 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 0xffff)) {
453 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed latency flowspec\n"));
454 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
455 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed Large latency flowspec\n"));
459 if (ServiceType == BT_LL_BE) {
461 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX best effort flowspec\n"));
466 if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 1492)) {
468 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed latency flowspec\n"));
469 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
470 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed Large latency flowspec\n"));
474 if (ServiceType == BT_LL_BE) {
475 if ((SDUInterArrivatime == 0xffffffff) && (ServiceType == BT_LL_BE) && (MaxSDUSize == 1492)) {
477 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX aggregated best effort flowspec\n"));
479 } else if (ServiceType == BT_LL_GU) {
480 if (SDUInterArrivatime == 100) {
482 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX guaranteed bandwidth flowspec\n"));
487 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = Unknow Type !!!!!!!!\n"));
491 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
492 ("ID = 0x%x, ServiceType = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, AccessLatency = 0x%x, FlushTimeout = 0x%x\n",
493 TxFlowSpec.Identifier, TxFlowSpec.ServiceType, MaxSDUSize,
494 SDUInterArrivatime, TxFlowSpec.AccessLatency, TxFlowSpec.FlushTimeout));
498 static u16 bthci_AssocMACAddr(struct rtw_adapter *padapter, void *pbuf)
500 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
501 pAssoStrc->TypeID = AMP_MAC_ADDR;
502 pAssoStrc->Length = 0x06;
503 memcpy(&pAssoStrc->Data[0], padapter->eeprompriv.mac_addr, 6);
504 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
505 ("AssocMACAddr : \n"), pAssoStrc, pAssoStrc->Length+3);
507 return pAssoStrc->Length + 3;
511 bthci_PALCapabilities(
512 struct rtw_adapter *padapter,
516 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
518 pAssoStrc->TypeID = AMP_80211_PAL_CAP_LIST;
519 pAssoStrc->Length = 0x04;
521 pAssoStrc->Data[0] = 0x00;
522 pAssoStrc->Data[1] = 0x00;
524 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("PALCapabilities:\n"), pAssoStrc, pAssoStrc->Length+3);
525 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("PALCapabilities \n"));
527 RTPRINT(FIOCTL, IOCTL_BT_LOGO, (" TypeID = 0x%x,\n Length = 0x%x,\n Content = 0x0000\n",
531 return pAssoStrc->Length + 3;
534 static u16 bthci_AssocPreferredChannelList(struct rtw_adapter *padapter,
535 void *pbuf, u8 EntryNum)
537 struct bt_30info *pBTInfo;
538 struct amp_assoc_structure *pAssoStrc;
539 struct amp_pref_chnl_regulatory *pReg;
540 struct chnl_txpower_triple *pTriple;
541 char ctrString[3] = {'X', 'X', 'X'};
545 pBTInfo = GET_BT_INFO(padapter);
546 pAssoStrc = (struct amp_assoc_structure *)pbuf;
547 pReg = (struct amp_pref_chnl_regulatory *)&pAssoStrc->Data[3];
549 preferredChnl = bthci_GetLocalChannel(padapter);
550 pAssoStrc->TypeID = AMP_PREFERRED_CHANNEL_LIST;
553 memcpy(&pAssoStrc->Data[0], &ctrString[0], 3);
555 pReg->regulatoryClass = 254;
556 pReg->coverageClass = 0;
558 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("PREFERRED_CHNL_LIST\n"));
559 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("XXX, 201, 254, 0\n"));
560 /* at the following, chnl 1~11 should be contained */
561 pTriple = (struct chnl_txpower_triple *)&pAssoStrc->Data[len];
563 /* (1) if any wifi or bt HS connection exists */
564 if ((pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR) ||
565 (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE |
566 WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE |
568 BTHCI_HsConnectionEstablished(padapter)) {
569 pTriple->FirstChnl = preferredChnl;
570 pTriple->NumChnls = 1;
571 pTriple->MaxTxPowerInDbm = 20;
573 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("First Channel = %d, Channel Num = %d, MaxDbm = %d\n",
576 pTriple->MaxTxPowerInDbm));
579 pAssoStrc->Length = (u16)len;
580 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, ("AssocPreferredChannelList : \n"), pAssoStrc, pAssoStrc->Length+3);
582 return pAssoStrc->Length + 3;
585 static u16 bthci_AssocPALVer(struct rtw_adapter *padapter, void *pbuf)
587 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
591 pAssoStrc->TypeID = AMP_80211_PAL_VISION;
592 pAssoStrc->Length = 0x5;
593 pu1Tmp = &pAssoStrc->Data[0];
594 *pu1Tmp = 0x1; /* PAL Version */
595 pu2Tmp = (u16 *)&pAssoStrc->Data[1];
596 *pu2Tmp = 0x5D; /* SIG Company identifier of 802.11 PAL vendor */
597 pu2Tmp = (u16 *)&pAssoStrc->Data[3];
598 *pu2Tmp = 0x1; /* PAL Sub-version specifier */
600 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("AssocPALVer : \n"), pAssoStrc, pAssoStrc->Length+3);
601 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("AssocPALVer \n"));
603 RTPRINT(FIOCTL, IOCTL_BT_LOGO, (" TypeID = 0x%x,\n Length = 0x%x,\n PAL Version = 0x01,\n PAL vendor = 0x01,\n PAL Sub-version specifier = 0x01\n",
606 return pAssoStrc->Length + 3;
609 static u8 bthci_CheckRfStateBeforeConnect(struct rtw_adapter *padapter)
611 struct bt_30info *pBTInfo;
612 enum rt_rf_power_state RfState;
614 pBTInfo = GET_BT_INFO(padapter);
616 RfState = padapter->pwrctrlpriv.rf_pwrstate;
618 if (RfState != rf_on) {
619 mod_timer(&pBTInfo->BTPsDisableTimer,
620 jiffies + msecs_to_jiffies(50));
626 static void bthci_ResponderStartToScan(struct rtw_adapter *padapter)
630 static u8 bthci_PhyLinkConnectionInProgress(struct rtw_adapter *padapter, u8 PhyLinkHandle)
632 struct bt_30info *pBTInfo;
633 struct bt_mgnt *pBtMgnt;
635 pBTInfo = GET_BT_INFO(padapter);
636 pBtMgnt = &pBTInfo->BtMgnt;
638 if (pBtMgnt->bPhyLinkInProgress &&
639 (pBtMgnt->BtCurrentPhyLinkhandle == PhyLinkHandle))
644 static void bthci_ResetFlowSpec(struct rtw_adapter *padapter, u8 EntryNum, u8 index)
646 struct bt_30info *pBTinfo;
648 pBTinfo = GET_BT_INFO(padapter);
650 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtLogLinkhandle = 0;
651 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtPhyLinkhandle = 0;
652 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCompleteEventIsSet = false;
653 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCancelCMDIsSetandComplete = false;
654 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtTxFlowSpecID = 0;
655 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].TxPacketCount = 0;
657 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.Identifier = 0x01;
658 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
659 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.MaximumSDUSize = 0xffff;
660 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
661 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.AccessLatency = 0xffffffff;
662 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.FlushTimeout = 0xffffffff;
664 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.Identifier = 0x01;
665 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
666 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.MaximumSDUSize = 0xffff;
667 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
668 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.AccessLatency = 0xffffffff;
669 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.FlushTimeout = 0xffffffff;
672 static void bthci_ResetEntry(struct rtw_adapter *padapter, u8 EntryNum)
674 struct bt_30info *pBTinfo;
675 struct bt_mgnt *pBtMgnt;
678 pBTinfo = GET_BT_INFO(padapter);
679 pBtMgnt = &pBTinfo->BtMgnt;
681 pBTinfo->BtAsocEntry[EntryNum].bUsed = false;
682 pBTinfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_DISCONNECTED;
683 pBTinfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED;
685 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen = 0;
686 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = 0;
687 if (pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment != NULL)
688 memset(pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment, 0, TOTAL_ALLOCIATE_ASSOC_LEN);
689 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = 0;
691 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = 0;
692 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = 0;
693 memset(pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, 0,
694 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
695 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = 0;
697 /* 0x640; 0.625ms*1600 = 1000ms, 0.625ms*16000 = 10000ms */
698 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = 0x3e80;
700 pBTinfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_NONE;
702 pBTinfo->BtAsocEntry[EntryNum].mAssoc = false;
703 pBTinfo->BtAsocEntry[EntryNum].b4waySuccess = false;
706 pBTinfo->BtAsocEntry[EntryNum].KeyReplayCounter = 0;
707 pBTinfo->BtAsocEntry[EntryNum].BTWPAAuthState = STATE_WPA_AUTH_UNINITIALIZED;
709 pBTinfo->BtAsocEntry[EntryNum].bSendSupervisionPacket = false;
710 pBTinfo->BtAsocEntry[EntryNum].NoRxPktCnt = 0;
711 pBTinfo->BtAsocEntry[EntryNum].ShortRangeMode = 0;
712 pBTinfo->BtAsocEntry[EntryNum].rxSuvpPktCnt = 0;
714 for (j = 0; j < MAX_LOGICAL_LINK_NUM; j++)
715 bthci_ResetFlowSpec(padapter, EntryNum, j);
717 pBtMgnt->BTAuthCount = 0;
718 pBtMgnt->BTAsocCount = 0;
719 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
720 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
722 HALBT_RemoveKey(padapter, EntryNum);
725 static void bthci_RemoveEntryByEntryNum(struct rtw_adapter *padapter, u8 EntryNum)
727 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
728 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
730 bthci_ResetEntry(padapter, EntryNum);
732 if (pBtMgnt->CurrentBTConnectionCnt > 0)
733 pBtMgnt->CurrentBTConnectionCnt--;
735 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d!!\n",
736 pBtMgnt->CurrentBTConnectionCnt));
738 if (pBtMgnt->CurrentBTConnectionCnt > 0) {
739 pBtMgnt->BtOperationOn = true;
741 pBtMgnt->BtOperationOn = false;
742 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation OFF!!\n"));
745 if (!pBtMgnt->BtOperationOn) {
746 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
747 del_timer_sync(&pBTInfo->BTBeaconTimer);
748 pBtMgnt->bStartSendSupervisionPkt = false;
753 bthci_CommandCompleteHeader(
757 enum hci_status status
760 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
761 u8 NumHCI_Comm = 0x1;
763 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
764 PPacketIrpEvent->Data[0] = NumHCI_Comm; /* packet # */
765 PPacketIrpEvent->Data[1] = HCIOPCODELOW(OCF, OGF);
766 PPacketIrpEvent->Data[2] = HCIOPCODEHIGHT(OCF, OGF);
768 if (OGF == OGF_EXTENSION) {
769 if (OCF == HCI_SET_RSSI_VALUE) {
770 RTPRINT(FIOCTL, (IOCTL_BT_EVENT_PERIODICAL),
771 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
772 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
774 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_EXT),
775 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
776 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
779 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
780 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
781 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
786 static u8 bthci_ExtensionEventHeaderRtk(u8 *pbuf, u8 extensionEvent)
788 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
789 PPacketIrpEvent->EventCode = HCI_EVENT_EXTENSION_RTK;
790 PPacketIrpEvent->Data[0] = extensionEvent; /* extension event code */
795 static enum rt_status
797 struct rtw_adapter *padapter,
802 enum rt_status rt_status;
804 rt_status = PlatformIndicateBTEvent(padapter, pEvntData, dataLen);
810 bthci_EventWriteRemoteAmpAssoc(
811 struct rtw_adapter *padapter,
812 enum hci_status status,
816 u8 localBuf[TmpLocalBufSize] = "";
819 struct packet_irp_hcievent_data *PPacketIrpEvent;
821 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
822 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
824 len += bthci_CommandCompleteHeader(&localBuf[0],
825 OGF_STATUS_PARAMETERS,
826 HCI_WRITE_REMOTE_AMP_ASSOC,
828 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("PhyLinkHandle = 0x%x, status = %d\n", PLHandle, status));
829 /* Return parameters starts from here */
830 pRetPar = &PPacketIrpEvent->Data[len];
831 pRetPar[0] = status; /* status */
832 pRetPar[1] = PLHandle;
834 PPacketIrpEvent->Length = len;
836 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
840 bthci_EventEnhancedFlushComplete(
841 struct rtw_adapter *padapter,
846 struct packet_irp_hcievent_data *PPacketIrpEvent;
848 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("EventEnhancedFlushComplete, LLH = 0x%x\n", LLH));
850 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
851 PPacketIrpEvent->EventCode = HCI_EVENT_ENHANCED_FLUSH_COMPLETE;
852 PPacketIrpEvent->Length = 2;
853 /* Logical link handle */
854 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LLH);
855 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LLH);
857 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
861 bthci_EventShortRangeModeChangeComplete(
862 struct rtw_adapter *padapter,
863 enum hci_status HciStatus,
868 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
869 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
871 struct packet_irp_hcievent_data *PPacketIrpEvent;
873 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE)) {
874 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
875 ("[BT event], Short Range Mode Change Complete, Ignore to send this event due to event mask page 2\n"));
878 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Short Range Mode Change Complete, Status = %d\n , PLH = 0x%x\n, Short_Range_Mode_State = 0x%x\n",
879 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, ShortRangeState));
881 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
882 PPacketIrpEvent->EventCode = HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE;
883 PPacketIrpEvent->Length = 3;
884 PPacketIrpEvent->Data[0] = HciStatus;
885 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
886 PPacketIrpEvent->Data[2] = ShortRangeState;
887 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
890 static void bthci_EventSendFlowSpecModifyComplete(struct rtw_adapter *padapter,
891 enum hci_status HciStatus,
895 struct packet_irp_hcievent_data *PPacketIrpEvent;
896 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
897 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
899 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE)) {
900 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
901 ("[BT event], Flow Spec Modify Complete, Ignore to send this event due to event mask page 2\n"));
904 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
905 ("[BT event], Flow Spec Modify Complete, status = 0x%x, LLH = 0x%x\n", HciStatus, logicHandle));
906 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
907 PPacketIrpEvent->EventCode = HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE;
908 PPacketIrpEvent->Length = 3;
910 PPacketIrpEvent->Data[0] = HciStatus;
911 /* Logical link handle */
912 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(logicHandle);
913 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(logicHandle);
915 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
919 bthci_EventExtWifiScanNotify(
920 struct rtw_adapter *padapter,
924 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
925 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
930 struct packet_irp_hcievent_data *PPacketIrpEvent;
932 if (!pBtMgnt->BtOperationOn)
935 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
937 len += bthci_ExtensionEventHeaderRtk(&localBuf[0], HCI_EVENT_EXT_WIFI_SCAN_NOTIFY);
939 /* Return parameters starts from here */
940 pRetPar = &PPacketIrpEvent->Data[len];
941 pu1Temp = (u8 *)&pRetPar[0];
945 PPacketIrpEvent->Length = len;
947 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS) {
948 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Wifi scan notify, scan type = %d\n",
954 bthci_EventAMPReceiverReport(
955 struct rtw_adapter *padapter,
959 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
960 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
962 if (pBtHciInfo->bTestNeedReport) {
963 u8 localBuf[20] = "";
966 struct packet_irp_hcievent_data *PPacketIrpEvent;
968 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_EVENT_AMP_RECEIVER_REPORT\n"));
969 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
970 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_RECEIVER_REPORT;
971 PPacketIrpEvent->Length = 2;
973 PPacketIrpEvent->Data[0] = pBtHciInfo->TestCtrType;
975 PPacketIrpEvent->Data[1] = Reason;
977 pu4Temp = (u32 *)&PPacketIrpEvent->Data[2];
978 *pu4Temp = pBtHciInfo->TestEventType;
980 pu2Temp = (u16 *)&PPacketIrpEvent->Data[6];
981 *pu2Temp = pBtHciInfo->TestNumOfFrame;
983 pu2Temp = (u16 *)&PPacketIrpEvent->Data[8];
984 *pu2Temp = pBtHciInfo->TestNumOfErrFrame;
986 pu4Temp = (u32 *)&PPacketIrpEvent->Data[10];
987 *pu4Temp = pBtHciInfo->TestNumOfBits;
989 pu4Temp = (u32 *)&PPacketIrpEvent->Data[14];
990 *pu4Temp = pBtHciInfo->TestNumOfErrBits;
992 bthci_IndicateEvent(padapter, PPacketIrpEvent, 20);
994 /* Return to Idel state with RX and TX off. */
998 pBtHciInfo->TestNumOfFrame = 0x00;
1002 bthci_EventChannelSelected(
1003 struct rtw_adapter *padapter,
1007 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1008 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1009 u8 localBuf[3] = "";
1010 struct packet_irp_hcievent_data *PPacketIrpEvent;
1012 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_CHANNEL_SELECT)) {
1013 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1014 ("[BT event], Channel Selected, Ignore to send this event due to event mask page 2\n"));
1018 RTPRINT(FIOCTL, IOCTL_BT_EVENT|IOCTL_STATE,
1019 ("[BT event], Channel Selected, PhyLinkHandle %d\n",
1020 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle));
1022 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1023 PPacketIrpEvent->EventCode = HCI_EVENT_CHANNEL_SELECT;
1024 PPacketIrpEvent->Length = 1;
1025 PPacketIrpEvent->Data[0] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1026 bthci_IndicateEvent(padapter, PPacketIrpEvent, 3);
1030 bthci_EventDisconnectPhyLinkComplete(
1031 struct rtw_adapter *padapter,
1032 enum hci_status HciStatus,
1033 enum hci_status Reason,
1037 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1038 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1039 u8 localBuf[5] = "";
1040 struct packet_irp_hcievent_data *PPacketIrpEvent;
1042 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE)) {
1043 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1044 ("[BT event], Disconnect Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1047 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1048 ("[BT event], Disconnect Physical Link Complete, Status = 0x%x, PLH = 0x%x Reason = 0x%x\n",
1049 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, Reason));
1050 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1051 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE;
1052 PPacketIrpEvent->Length = 3;
1053 PPacketIrpEvent->Data[0] = HciStatus;
1054 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1055 PPacketIrpEvent->Data[2] = Reason;
1056 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
1060 bthci_EventPhysicalLinkComplete(
1061 struct rtw_adapter *padapter,
1062 enum hci_status HciStatus,
1067 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1068 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1069 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1070 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1071 u8 localBuf[4] = "";
1072 struct packet_irp_hcievent_data *PPacketIrpEvent;
1075 pBtMgnt->bPhyLinkInProgress = false;
1076 pBtDbg->dbgHciInfo.hciCmdPhyLinkStatus = HciStatus;
1077 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_PHY_LINK_COMPLETE)) {
1078 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1079 ("[BT event], Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1083 if (EntryNum == 0xff) {
1084 /* connection not started yet, just use the input physical link handle to response. */
1085 PL_handle = PLHandle;
1087 /* connection is under progress, use the phy link handle we recorded. */
1088 PL_handle = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1089 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = false;
1092 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Physical Link Complete, Status = 0x%x PhyLinkHandle = 0x%x\n", HciStatus,
1095 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1096 PPacketIrpEvent->EventCode = HCI_EVENT_PHY_LINK_COMPLETE;
1097 PPacketIrpEvent->Length = 2;
1099 PPacketIrpEvent->Data[0] = HciStatus;
1100 PPacketIrpEvent->Data[1] = PL_handle;
1101 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1106 bthci_EventCommandStatus(
1107 struct rtw_adapter *padapter,
1110 enum hci_status HciStatus
1114 u8 localBuf[6] = "";
1115 struct packet_irp_hcievent_data *PPacketIrpEvent;
1116 u8 Num_Hci_Comm = 0x1;
1117 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1118 ("[BT event], CommandStatus, Opcode = 0x%02x%02x, OGF = 0x%x, OCF = 0x%x, Status = 0x%x, Num_HCI_COMM = 0x%x\n",
1119 (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), OGF, OCF, HciStatus, Num_Hci_Comm));
1121 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1122 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_STATUS;
1123 PPacketIrpEvent->Length = 4;
1124 PPacketIrpEvent->Data[0] = HciStatus; /* current pending */
1125 PPacketIrpEvent->Data[1] = Num_Hci_Comm; /* packet # */
1126 PPacketIrpEvent->Data[2] = HCIOPCODELOW(OCF, OGF);
1127 PPacketIrpEvent->Data[3] = HCIOPCODEHIGHT(OCF, OGF);
1129 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1134 bthci_EventLogicalLinkComplete(
1135 struct rtw_adapter *padapter,
1136 enum hci_status HciStatus,
1143 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1144 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1145 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1146 u8 localBuf[7] = "";
1147 struct packet_irp_hcievent_data *PPacketIrpEvent;
1149 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_LOGICAL_LINK_COMPLETE)) {
1150 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1151 ("[BT event], Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1154 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Logical Link Complete, PhyLinkHandle = 0x%x, LogLinkHandle = 0x%x, Status = 0x%x\n",
1155 PhyLinkHandle, LogLinkHandle, HciStatus));
1157 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1158 PPacketIrpEvent->EventCode = HCI_EVENT_LOGICAL_LINK_COMPLETE;
1159 PPacketIrpEvent->Length = 5;
1161 PPacketIrpEvent->Data[0] = HciStatus;/* status code */
1162 /* Logical link handle */
1163 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1164 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1165 /* Physical link handle */
1166 PPacketIrpEvent->Data[3] = TWOBYTE_LOWBYTE(PhyLinkHandle);
1167 /* corresponding Tx flow spec ID */
1168 if (HciStatus == HCI_STATUS_SUCCESS) {
1169 PPacketIrpEvent->Data[4] =
1170 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData[LogLinkIndex].Tx_Flow_Spec.Identifier;
1172 PPacketIrpEvent->Data[4] = 0x0;
1175 bthci_IndicateEvent(padapter, PPacketIrpEvent, 7);
1179 bthci_EventDisconnectLogicalLinkComplete(
1180 struct rtw_adapter *padapter,
1181 enum hci_status HciStatus,
1183 enum hci_status Reason
1186 u8 localBuf[6] = "";
1187 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1188 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1189 struct packet_irp_hcievent_data *PPacketIrpEvent;
1191 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE)) {
1192 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1195 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Status = 0x%x, LLH = 0x%x Reason = 0x%x\n", HciStatus, LogLinkHandle, Reason));
1197 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1198 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE;
1199 PPacketIrpEvent->Length = 4;
1201 PPacketIrpEvent->Data[0] = HciStatus;
1202 /* Logical link handle */
1203 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1204 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1205 /* Disconnect reason */
1206 PPacketIrpEvent->Data[3] = Reason;
1208 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1212 bthci_EventFlushOccurred(
1213 struct rtw_adapter *padapter,
1217 u8 localBuf[4] = "";
1218 struct packet_irp_hcievent_data *PPacketIrpEvent;
1219 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("bthci_EventFlushOccurred(), LLH = 0x%x\n", LogLinkHandle));
1221 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1222 PPacketIrpEvent->EventCode = HCI_EVENT_FLUSH_OCCRUED;
1223 PPacketIrpEvent->Length = 2;
1224 /* Logical link handle */
1225 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LogLinkHandle);
1226 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1228 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1231 static enum hci_status
1232 bthci_BuildPhysicalLink(
1233 struct rtw_adapter *padapter,
1234 struct packet_irp_hcicmd_data *pHciCmd,
1238 enum hci_status status = HCI_STATUS_SUCCESS;
1239 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1240 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1243 /* Send HCI Command status event to AMP. */
1244 bthci_EventCommandStatus(padapter,
1245 LINK_CONTROL_COMMANDS,
1247 HCI_STATUS_SUCCESS);
1249 PLH = *((u8 *)pHciCmd->Data);
1251 /* Check if resource or bt connection is under progress, if yes, reject the link creation. */
1252 if (!bthci_AddEntry(padapter)) {
1253 status = HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE;
1254 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1258 EntryNum = pBtMgnt->CurrentConnectEntryNum;
1259 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = PLH;
1260 pBtMgnt->BtCurrentPhyLinkhandle = PLH;
1262 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1263 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Create/Accept PhysicalLink, AMP controller is busy\n"));
1264 status = HCI_STATUS_CONTROLLER_BUSY;
1265 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1269 /* Record Key and the info */
1270 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = (*((u8 *)pHciCmd->Data+1));
1271 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = (*((u8 *)pHciCmd->Data+2));
1272 memcpy(pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1273 (((u8 *)pHciCmd->Data+3)), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1274 memcpy(pBTInfo->BtAsocEntry[EntryNum].PMK, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, PMK_LEN);
1275 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildPhysicalLink, EntryNum = %d, PLH = 0x%x KeyLen = 0x%x, KeyType = 0x%x\n",
1276 EntryNum, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1277 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen,
1278 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType));
1279 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("BtAMPKey\n"), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1280 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1281 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("PMK\n"), pBTInfo->BtAsocEntry[EntryNum].PMK,
1284 if (OCF == HCI_CREATE_PHYSICAL_LINK) {
1285 /* These macros require braces */
1286 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_CREATE_PHY_LINK, EntryNum);
1287 } else if (OCF == HCI_ACCEPT_PHYSICAL_LINK) {
1288 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ACCEPT_PHY_LINK, EntryNum);
1295 bthci_BuildLogicalLink(
1296 struct rtw_adapter *padapter,
1297 struct packet_irp_hcicmd_data *pHciCmd,
1301 enum hci_status status = HCI_STATUS_SUCCESS;
1302 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1303 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
1304 u8 PhyLinkHandle, EntryNum;
1305 static u16 AssignLogHandle = 1;
1307 struct hci_flow_spec TxFlowSpec;
1308 struct hci_flow_spec RxFlowSpec;
1309 u32 MaxSDUSize, ArriveTime, Bandwidth;
1311 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1313 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1316 &pHciCmd->Data[1], sizeof(struct hci_flow_spec));
1318 &pHciCmd->Data[17], sizeof(struct hci_flow_spec));
1320 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
1321 ArriveTime = TxFlowSpec.SDUInterArrivalTime;
1323 if (bthci_CheckLogLinkBehavior(padapter, TxFlowSpec) && bthci_CheckLogLinkBehavior(padapter, RxFlowSpec))
1324 Bandwidth = BTTOTALBANDWIDTH;
1325 else if (MaxSDUSize == 0xffff && ArriveTime == 0xffffffff)
1326 Bandwidth = BTTOTALBANDWIDTH;
1328 Bandwidth = MaxSDUSize*8*1000/(ArriveTime+244);
1330 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
1331 ("BuildLogicalLink, PhyLinkHandle = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, Bandwidth = 0x%x\n",
1332 PhyLinkHandle, MaxSDUSize, ArriveTime, Bandwidth));
1334 if (EntryNum == 0xff) {
1335 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Invalid Physical Link handle = 0x%x, status = HCI_STATUS_UNKNOW_CONNECT_ID, return\n", PhyLinkHandle));
1336 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1338 /* When we receive Create/Accept logical link command, we should send command status event first. */
1339 bthci_EventCommandStatus(padapter,
1340 LINK_CONTROL_COMMANDS,
1346 if (!pBtMgnt->bLogLinkInProgress) {
1347 if (bthci_PhyLinkConnectionInProgress(padapter, PhyLinkHandle)) {
1348 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Physical link connection in progress, status = HCI_STATUS_CMD_DISALLOW, return\n"));
1349 status = HCI_STATUS_CMD_DISALLOW;
1351 pBtMgnt->bPhyLinkInProgressStartLL = true;
1352 /* When we receive Create/Accept logical link command, we should send command status event first. */
1353 bthci_EventCommandStatus(padapter,
1354 LINK_CONTROL_COMMANDS,
1361 if (Bandwidth > BTTOTALBANDWIDTH) {
1362 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_QOS_REJECT, Bandwidth = 0x%x, return\n", Bandwidth));
1363 status = HCI_STATUS_QOS_REJECT;
1365 /* When we receive Create/Accept logical link command, we should send command status event first. */
1366 bthci_EventCommandStatus(padapter,
1367 LINK_CONTROL_COMMANDS,
1371 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_SUCCESS\n"));
1372 status = HCI_STATUS_SUCCESS;
1374 /* When we receive Create/Accept logical link command, we should send command status event first. */
1375 bthci_EventCommandStatus(padapter,
1376 LINK_CONTROL_COMMANDS,
1382 if (pBTinfo->BtAsocEntry[EntryNum].BtCurrentState != HCI_STATE_CONNECTED) {
1383 bthci_EventLogicalLinkComplete(padapter,
1384 HCI_STATUS_CMD_DISALLOW, 0, 0, 0, EntryNum);
1388 pBtMgnt->bLogLinkInProgress = true;
1390 /* find an unused logical link index and copy the data */
1391 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
1392 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle == 0) {
1393 enum hci_status LogCompEventstatus = HCI_STATUS_SUCCESS;
1395 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
1396 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle = AssignLogHandle;
1397 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildLogicalLink, EntryNum = %d, physical link handle = 0x%x, logical link handle = 0x%x\n",
1398 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1399 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle));
1400 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Tx_Flow_Spec,
1401 &TxFlowSpec, sizeof(struct hci_flow_spec));
1402 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Rx_Flow_Spec,
1403 &RxFlowSpec, sizeof(struct hci_flow_spec));
1405 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = false;
1407 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCancelCMDIsSetandComplete)
1408 LogCompEventstatus = HCI_STATUS_UNKNOW_CONNECT_ID;
1409 bthci_EventLogicalLinkComplete(padapter,
1411 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle,
1412 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle, i, EntryNum);
1414 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = true;
1417 pBtMgnt->BtCurrentLogLinkhandle = AssignLogHandle;
1424 bthci_EventLogicalLinkComplete(padapter,
1425 HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE, 0, 0, 0, EntryNum);
1427 pBtMgnt->bLogLinkInProgress = false;
1430 bthci_EventLogicalLinkComplete(padapter,
1431 HCI_STATUS_CONTROLLER_BUSY, 0, 0, 0, EntryNum);
1437 bthci_StartBeaconAndConnect(
1438 struct rtw_adapter *padapter,
1439 struct packet_irp_hcicmd_data *pHciCmd,
1443 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1444 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1445 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1447 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("StartBeaconAndConnect, CurrentAssocNum =%d, AMPRole =%d\n",
1449 pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole));
1451 if (!pBtMgnt->CheckChnlIsSuit) {
1452 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONNECT_REJ_NOT_SUIT_CHNL_FOUND, CurrentAssocNum, INVALID_PL_HANDLE);
1453 bthci_RemoveEntryByEntryNum(padapter, CurrentAssocNum);
1457 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1458 rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
1459 padapter->eeprompriv.mac_addr[0],
1460 padapter->eeprompriv.mac_addr[1],
1461 padapter->eeprompriv.mac_addr[2],
1462 padapter->eeprompriv.mac_addr[3],
1463 padapter->eeprompriv.mac_addr[4],
1464 padapter->eeprompriv.mac_addr[5]);
1465 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1466 rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
1467 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[0],
1468 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[1],
1469 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[2],
1470 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[3],
1471 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[4],
1472 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[5]);
1475 FillOctetString(pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid, pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 21);
1476 pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid.Length = 21;
1478 /* To avoid set the start ap or connect twice, or the original connection will be disconnected. */
1479 if (!pBtMgnt->bBTConnectInProgress) {
1480 pBtMgnt->bBTConnectInProgress = true;
1481 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress ON!!\n"));
1482 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_STARTING, STATE_CMD_MAC_START_COMPLETE, CurrentAssocNum);
1484 /* 20100325 Joseph: Check RF ON/OFF. */
1485 /* If RF OFF, it reschedule connecting operation after 50ms. */
1486 if (!bthci_CheckRfStateBeforeConnect(padapter))
1489 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1490 /* These macros need braces */
1491 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_COMPLETE, CurrentAssocNum);
1492 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1493 bthci_ResponderStartToScan(padapter);
1496 RT_PRINT_STR(_module_rtl871x_mlme_c_, _drv_notice_,
1497 "StartBeaconAndConnect, SSID:\n",
1498 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Octet,
1499 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Length);
1502 static void bthci_ResetBtMgnt(struct bt_mgnt *pBtMgnt)
1504 pBtMgnt->BtOperationOn = false;
1505 pBtMgnt->bBTConnectInProgress = false;
1506 pBtMgnt->bLogLinkInProgress = false;
1507 pBtMgnt->bPhyLinkInProgress = false;
1508 pBtMgnt->bPhyLinkInProgressStartLL = false;
1509 pBtMgnt->DisconnectEntryNum = 0xff;
1510 pBtMgnt->bStartSendSupervisionPkt = false;
1511 pBtMgnt->JoinerNeedSendAuth = false;
1512 pBtMgnt->CurrentBTConnectionCnt = 0;
1513 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
1514 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
1515 pBtMgnt->BTAuthCount = 0;
1516 pBtMgnt->btLogoTest = 0;
1519 static void bthci_ResetBtHciInfo(struct bt_hci_info *pBtHciInfo)
1521 pBtHciInfo->BTEventMask = 0;
1522 pBtHciInfo->BTEventMaskPage2 = 0;
1523 pBtHciInfo->ConnAcceptTimeout = 10000;
1524 pBtHciInfo->PageTimeout = 0x30;
1525 pBtHciInfo->LocationDomainAware = 0x0;
1526 pBtHciInfo->LocationDomain = 0x5858;
1527 pBtHciInfo->LocationDomainOptions = 0x58;
1528 pBtHciInfo->LocationOptions = 0x0;
1529 pBtHciInfo->FlowControlMode = 0x1; /* 0:Packet based data flow control mode(BR/EDR), 1: Data block based data flow control mode(AMP). */
1531 pBtHciInfo->enFlush_LLH = 0;
1532 pBtHciInfo->FLTO_LLH = 0;
1534 /* Test command only */
1535 pBtHciInfo->bTestIsEnd = true;
1536 pBtHciInfo->bInTestMode = false;
1537 pBtHciInfo->bTestNeedReport = false;
1538 pBtHciInfo->TestScenario = 0xff;
1539 pBtHciInfo->TestReportInterval = 0x01;
1540 pBtHciInfo->TestCtrType = 0x5d;
1541 pBtHciInfo->TestEventType = 0x00;
1542 pBtHciInfo->TestNumOfFrame = 0;
1543 pBtHciInfo->TestNumOfErrFrame = 0;
1544 pBtHciInfo->TestNumOfBits = 0;
1545 pBtHciInfo->TestNumOfErrBits = 0;
1548 static void bthci_ResetBtSec(struct rtw_adapter *padapter, struct bt_security *pBtSec)
1550 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1552 /* Set BT used HW or SW encrypt !! */
1553 if (GET_HAL_DATA(padapter)->bBTMode)
1554 pBtSec->bUsedHwEncrypt = true;
1556 pBtSec->bUsedHwEncrypt = false;
1557 RT_TRACE(_module_rtl871x_security_c_, _drv_info_, ("%s: bUsedHwEncrypt =%d\n", __func__, pBtSec->bUsedHwEncrypt));
1559 pBtSec->RSNIE.Octet = pBtSec->RSNIEBuf;
1562 static void bthci_ResetBtExtInfo(struct bt_mgnt *pBtMgnt)
1566 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
1567 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = 0;
1568 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = 0;
1569 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = 0;
1570 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = BT_PROFILE_NONE;
1571 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = BT_SPEC_2_1_EDR;
1572 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = 0;
1573 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
1574 pBtMgnt->ExtConfig.linkInfo[i].linkRole = BT_LINK_MASTER;
1577 pBtMgnt->ExtConfig.CurrentConnectHandle = 0;
1578 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = 0;
1579 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = 0;
1580 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
1581 pBtMgnt->ExtConfig.NumberOfHandle = 0;
1582 pBtMgnt->ExtConfig.NumberOfSCO = 0;
1583 pBtMgnt->ExtConfig.CurrentBTStatus = 0;
1584 pBtMgnt->ExtConfig.HCIExtensionVer = 0;
1586 pBtMgnt->ExtConfig.bManualControl = false;
1587 pBtMgnt->ExtConfig.bBTBusy = false;
1588 pBtMgnt->ExtConfig.bBTA2DPBusy = false;
1591 static enum hci_status bthci_CmdReset(struct rtw_adapter *_padapter, u8 bNeedSendEvent)
1593 enum hci_status status = HCI_STATUS_SUCCESS;
1594 struct rtw_adapter *padapter;
1595 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1596 struct bt_30info *pBTInfo;
1597 struct bt_mgnt *pBtMgnt;
1598 struct bt_hci_info *pBtHciInfo;
1599 struct bt_security *pBtSec;
1600 struct bt_dgb *pBtDbg;
1603 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_CmdReset()\n"));
1605 padapter = GetDefaultAdapter(_padapter);
1606 pBTInfo = GET_BT_INFO(padapter);
1607 pBtMgnt = &pBTInfo->BtMgnt;
1608 pBtHciInfo = &pBTInfo->BtHciInfo;
1609 pBtSec = &pBTInfo->BtSec;
1610 pBtDbg = &pBTInfo->BtDbg;
1612 pBTInfo->padapter = padapter;
1614 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++)
1615 bthci_ResetEntry(padapter, i);
1617 bthci_ResetBtMgnt(pBtMgnt);
1618 bthci_ResetBtHciInfo(pBtHciInfo);
1619 bthci_ResetBtSec(padapter, pBtSec);
1621 pBtMgnt->BTChannel = BT_Default_Chnl;
1622 pBtMgnt->CheckChnlIsSuit = true;
1624 pBTInfo->BTBeaconTmrOn = false;
1626 pBtMgnt->bCreateSpportQos = true;
1628 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
1629 del_timer_sync(&pBTInfo->BTBeaconTimer);
1631 HALBT_SetRtsCtsNoLenLimit(padapter);
1633 /* Maybe we need to take care Group != AES case !! */
1634 /* now we Pairwise and Group all used AES !! */
1636 bthci_ResetBtExtInfo(pBtMgnt);
1638 /* send command complete event here when all data are received. */
1639 if (bNeedSendEvent) {
1640 u8 localBuf[6] = "";
1643 struct packet_irp_hcievent_data *PPacketIrpEvent;
1645 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1647 len += bthci_CommandCompleteHeader(&localBuf[0],
1648 OGF_SET_EVENT_MASK_COMMAND,
1652 /* Return parameters starts from here */
1653 pRetPar = &PPacketIrpEvent->Data[len];
1654 pRetPar[0] = status; /* status */
1656 PPacketIrpEvent->Length = len;
1658 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1664 static enum hci_status
1665 bthci_CmdWriteRemoteAMPAssoc(
1666 struct rtw_adapter *padapter,
1667 struct packet_irp_hcicmd_data *pHciCmd
1670 enum hci_status status = HCI_STATUS_SUCCESS;
1671 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1672 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1676 pBtDbg->dbgHciInfo.hciCmdCntWriteRemoteAmpAssoc++;
1677 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1678 CurrentAssocNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1680 if (CurrentAssocNum == 0xff) {
1681 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, No such Handle in the Entry\n"));
1682 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1683 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1687 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1688 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, AMP controller is busy\n"));
1689 status = HCI_STATUS_CONTROLLER_BUSY;
1690 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1694 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.BtPhyLinkhandle = PhyLinkHandle;/* u8 *)pHciCmd->Data); */
1695 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
1696 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen = *((u16 *)((u8 *)pHciCmd->Data+3));
1698 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, LenSoFar = 0x%x, AssocRemLen = 0x%x\n",
1699 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar,
1700 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1702 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
1703 ("WriteRemoteAMPAssoc fragment \n"),
1705 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen+5);
1706 if ((pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen) > MAX_AMP_ASSOC_FRAG_LEN) {
1707 memcpy(((u8 *)pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8)))),
1708 (u8 *)pHciCmd->Data+5,
1709 MAX_AMP_ASSOC_FRAG_LEN);
1711 memcpy((u8 *)(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment)+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8))),
1712 ((u8 *)pHciCmd->Data+5),
1713 (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1715 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "WriteRemoteAMPAssoc :\n",
1716 pHciCmd->Data+5, pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen);
1718 if (!bthci_GetAssocInfo(padapter, CurrentAssocNum))
1719 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
1721 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1723 bthci_StartBeaconAndConnect(padapter, pHciCmd, CurrentAssocNum);
1730 static enum hci_status bthci_CmdReadConnectionAcceptTimeout(struct rtw_adapter *padapter)
1732 enum hci_status status = HCI_STATUS_SUCCESS;
1733 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1734 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1735 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1736 u8 localBuf[8] = "";
1739 struct packet_irp_hcievent_data *PPacketIrpEvent;
1742 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1744 len += bthci_CommandCompleteHeader(&localBuf[0],
1745 OGF_SET_EVENT_MASK_COMMAND,
1746 HCI_READ_CONNECTION_ACCEPT_TIMEOUT,
1749 /* Return parameters starts from here */
1750 pRetPar = &PPacketIrpEvent->Data[len];
1751 pRetPar[0] = status; /* status */
1752 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
1753 *pu2Temp = pBtHciInfo->ConnAcceptTimeout;
1755 PPacketIrpEvent->Length = len;
1757 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1763 static enum hci_status
1764 bthci_CmdSetEventFilter(
1765 struct rtw_adapter *padapter,
1766 struct packet_irp_hcicmd_data *pHciCmd
1769 enum hci_status status = HCI_STATUS_SUCCESS;
1775 static enum hci_status
1776 bthci_CmdWriteConnectionAcceptTimeout(
1777 struct rtw_adapter *padapter,
1778 struct packet_irp_hcicmd_data *pHciCmd
1781 enum hci_status status = HCI_STATUS_SUCCESS;
1782 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1783 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1785 u8 localBuf[6] = "";
1788 struct packet_irp_hcievent_data *PPacketIrpEvent;
1790 pu2Temp = (u16 *)&pHciCmd->Data[0];
1791 pBtHciInfo->ConnAcceptTimeout = *pu2Temp;
1792 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ConnAcceptTimeout = 0x%x",
1793 pBtHciInfo->ConnAcceptTimeout));
1795 /* send command complete event here when all data are received. */
1796 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1798 len += bthci_CommandCompleteHeader(&localBuf[0],
1799 OGF_SET_EVENT_MASK_COMMAND,
1800 HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT,
1803 /* Return parameters starts from here */
1804 pRetPar = &PPacketIrpEvent->Data[len];
1805 pRetPar[0] = status; /* status */
1807 PPacketIrpEvent->Length = len;
1809 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1814 static enum hci_status
1815 bthci_CmdReadPageTimeout(
1816 struct rtw_adapter *padapter,
1817 struct packet_irp_hcicmd_data *pHciCmd
1820 enum hci_status status = HCI_STATUS_SUCCESS;
1821 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1822 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1823 u8 localBuf[8] = "";
1826 struct packet_irp_hcievent_data *PPacketIrpEvent;
1829 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1831 len += bthci_CommandCompleteHeader(&localBuf[0],
1832 OGF_SET_EVENT_MASK_COMMAND,
1833 HCI_READ_PAGE_TIMEOUT,
1836 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Read PageTimeout = 0x%x\n", pBtHciInfo->PageTimeout));
1837 /* Return parameters starts from here */
1838 pRetPar = &PPacketIrpEvent->Data[len];
1839 pRetPar[0] = status; /* status */
1840 pu2Temp = (u16 *)&pRetPar[1]; /* Page_Timeout */
1841 *pu2Temp = pBtHciInfo->PageTimeout;
1843 PPacketIrpEvent->Length = len;
1845 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1850 static enum hci_status
1851 bthci_CmdWritePageTimeout(
1852 struct rtw_adapter *padapter,
1853 struct packet_irp_hcicmd_data *pHciCmd
1856 enum hci_status status = HCI_STATUS_SUCCESS;
1857 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1858 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1861 pu2Temp = (u16 *)&pHciCmd->Data[0];
1862 pBtHciInfo->PageTimeout = *pu2Temp;
1863 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Write PageTimeout = 0x%x\n",
1864 pBtHciInfo->PageTimeout));
1866 /* send command complete event here when all data are received. */
1868 u8 localBuf[6] = "";
1871 struct packet_irp_hcievent_data *PPacketIrpEvent;
1873 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1875 len += bthci_CommandCompleteHeader(&localBuf[0],
1876 OGF_SET_EVENT_MASK_COMMAND,
1877 HCI_WRITE_PAGE_TIMEOUT,
1880 /* Return parameters starts from here */
1881 pRetPar = &PPacketIrpEvent->Data[len];
1882 pRetPar[0] = status; /* status */
1884 PPacketIrpEvent->Length = len;
1886 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1892 static enum hci_status
1893 bthci_CmdReadLinkSupervisionTimeout(
1894 struct rtw_adapter *padapter,
1895 struct packet_irp_hcicmd_data *pHciCmd
1898 enum hci_status status = HCI_STATUS_SUCCESS;
1899 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1900 u8 physicalLinkHandle, EntryNum;
1902 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1904 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1906 if (EntryNum == 0xff) {
1907 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLinkSupervisionTimeout, No such Handle in the Entry\n"));
1908 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1912 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle)
1913 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1916 u8 localBuf[10] = "";
1919 struct packet_irp_hcievent_data *PPacketIrpEvent;
1922 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1924 len += bthci_CommandCompleteHeader(&localBuf[0],
1925 OGF_SET_EVENT_MASK_COMMAND,
1926 HCI_READ_LINK_SUPERVISION_TIMEOUT,
1929 /* Return parameters starts from here */
1930 pRetPar = &PPacketIrpEvent->Data[len];
1931 pRetPar[0] = status;
1932 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1934 pu2Temp = (u16 *)&pRetPar[3]; /* Conn_Accept_Timeout */
1935 *pu2Temp = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout;
1937 PPacketIrpEvent->Length = len;
1939 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1945 static enum hci_status
1946 bthci_CmdWriteLinkSupervisionTimeout(
1947 struct rtw_adapter *padapter,
1948 struct packet_irp_hcicmd_data *pHciCmd
1951 enum hci_status status = HCI_STATUS_SUCCESS;
1952 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1953 u8 physicalLinkHandle, EntryNum;
1955 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1957 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1959 if (EntryNum == 0xff) {
1960 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("WriteLinkSupervisionTimeout, No such Handle in the Entry\n"));
1961 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1963 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle) {
1964 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1966 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = *((u16 *)(((u8 *)pHciCmd->Data)+2));
1967 RTPRINT(FIOCTL, IOCTL_STATE, ("BT Write LinkSuperversionTimeout[%d] = 0x%x\n",
1968 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout));
1973 u8 localBuf[8] = "";
1976 struct packet_irp_hcievent_data *PPacketIrpEvent;
1978 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1980 len += bthci_CommandCompleteHeader(&localBuf[0],
1981 OGF_SET_EVENT_MASK_COMMAND,
1982 HCI_WRITE_LINK_SUPERVISION_TIMEOUT,
1985 /* Return parameters starts from here */
1986 pRetPar = &PPacketIrpEvent->Data[len];
1987 pRetPar[0] = status;
1988 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1991 PPacketIrpEvent->Length = len;
1993 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1999 static enum hci_status
2000 bthci_CmdEnhancedFlush(
2001 struct rtw_adapter *padapter,
2002 struct packet_irp_hcicmd_data *pHciCmd
2005 enum hci_status status = HCI_STATUS_SUCCESS;
2006 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2007 struct bt_hci_info *pBtHciInfo = &pBTinfo->BtHciInfo;
2011 logicHandle = *((u16 *)&pHciCmd->Data[0]);
2012 Packet_Type = pHciCmd->Data[2];
2014 if (Packet_Type != 0)
2015 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
2017 pBtHciInfo->enFlush_LLH = logicHandle;
2019 if (bthci_DiscardTxPackets(padapter, pBtHciInfo->enFlush_LLH))
2020 bthci_EventFlushOccurred(padapter, pBtHciInfo->enFlush_LLH);
2022 /* should send command status event */
2023 bthci_EventCommandStatus(padapter,
2024 OGF_SET_EVENT_MASK_COMMAND,
2028 if (pBtHciInfo->enFlush_LLH) {
2029 bthci_EventEnhancedFlushComplete(padapter, pBtHciInfo->enFlush_LLH);
2030 pBtHciInfo->enFlush_LLH = 0;
2036 static enum hci_status
2037 bthci_CmdReadLogicalLinkAcceptTimeout(
2038 struct rtw_adapter *padapter,
2039 struct packet_irp_hcicmd_data *pHciCmd
2042 enum hci_status status = HCI_STATUS_SUCCESS;
2043 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2044 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2045 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2046 u8 localBuf[8] = "";
2049 struct packet_irp_hcievent_data *PPacketIrpEvent;
2052 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2054 len += bthci_CommandCompleteHeader(&localBuf[0],
2055 OGF_SET_EVENT_MASK_COMMAND,
2056 HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT,
2059 /* Return parameters starts from here */
2060 pRetPar = &PPacketIrpEvent->Data[len];
2061 pRetPar[0] = status;
2063 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
2064 *pu2Temp = pBtHciInfo->LogicalAcceptTimeout;
2066 PPacketIrpEvent->Length = len;
2068 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2073 static enum hci_status
2074 bthci_CmdWriteLogicalLinkAcceptTimeout(
2075 struct rtw_adapter *padapter,
2076 struct packet_irp_hcicmd_data *pHciCmd
2079 enum hci_status status = HCI_STATUS_SUCCESS;
2080 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2081 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2082 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2083 u8 localBuf[6] = "";
2086 struct packet_irp_hcievent_data *PPacketIrpEvent;
2088 pBtHciInfo->LogicalAcceptTimeout = *((u16 *)pHciCmd->Data);
2090 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2092 len += bthci_CommandCompleteHeader(&localBuf[0],
2093 OGF_SET_EVENT_MASK_COMMAND,
2094 HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT,
2097 /* Return parameters starts from here */
2098 pRetPar = &PPacketIrpEvent->Data[len];
2099 pRetPar[0] = status;
2102 PPacketIrpEvent->Length = len;
2104 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2108 static enum hci_status
2109 bthci_CmdSetEventMask(
2110 struct rtw_adapter *padapter,
2111 struct packet_irp_hcicmd_data *pHciCmd
2114 enum hci_status status = HCI_STATUS_SUCCESS;
2115 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2116 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2117 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2119 u8 localBuf[6] = "";
2122 struct packet_irp_hcievent_data *PPacketIrpEvent;
2124 pu8Temp = (u8 *)&pHciCmd->Data[0];
2125 pBtHciInfo->BTEventMask = *pu8Temp;
2126 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("BTEventMask = 0x%"i64fmt"x\n",
2127 pBtHciInfo->BTEventMask));
2129 /* send command complete event here when all data are received. */
2130 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2132 len += bthci_CommandCompleteHeader(&localBuf[0],
2133 OGF_SET_EVENT_MASK_COMMAND,
2137 /* Return parameters starts from here */
2138 pRetPar = &PPacketIrpEvent->Data[len];
2139 pRetPar[0] = status; /* status */
2141 PPacketIrpEvent->Length = len;
2143 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2149 static enum hci_status
2150 bthci_CmdSetEventMaskPage2(
2151 struct rtw_adapter *padapter,
2152 struct packet_irp_hcicmd_data *pHciCmd
2155 enum hci_status status = HCI_STATUS_SUCCESS;
2156 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2157 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2159 u8 localBuf[6] = "";
2162 struct packet_irp_hcievent_data *PPacketIrpEvent;
2164 pu8Temp = (u8 *)&pHciCmd->Data[0];
2165 pBtHciInfo->BTEventMaskPage2 = *pu8Temp;
2166 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("BTEventMaskPage2 = 0x%"i64fmt"x\n",
2167 pBtHciInfo->BTEventMaskPage2));
2169 /* send command complete event here when all data are received. */
2170 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2172 len += bthci_CommandCompleteHeader(&localBuf[0],
2173 OGF_SET_EVENT_MASK_COMMAND,
2174 HCI_SET_EVENT_MASK_PAGE_2,
2177 /* Return parameters starts from here */
2178 pRetPar = &PPacketIrpEvent->Data[len];
2179 pRetPar[0] = status; /* status */
2181 PPacketIrpEvent->Length = len;
2183 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2188 static enum hci_status
2189 bthci_CmdReadLocationData(
2190 struct rtw_adapter *padapter,
2191 struct packet_irp_hcicmd_data *pHciCmd
2194 enum hci_status status = HCI_STATUS_SUCCESS;
2195 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2196 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2197 u8 localBuf[12] = "";
2200 struct packet_irp_hcievent_data *PPacketIrpEvent;
2203 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2205 len += bthci_CommandCompleteHeader(&localBuf[0],
2206 OGF_SET_EVENT_MASK_COMMAND,
2207 HCI_READ_LOCATION_DATA,
2209 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2210 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2211 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2212 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2214 /* Return parameters starts from here */
2215 pRetPar = &PPacketIrpEvent->Data[len];
2216 pRetPar[0] = status;
2218 pRetPar[1] = pBtHciInfo->LocationDomainAware; /* 0x0; Location_Domain_Aware */
2219 pu2Temp = (u16 *)&pRetPar[2]; /* Location_Domain */
2220 *pu2Temp = pBtHciInfo->LocationDomain; /* 0x5858; */
2221 pRetPar[4] = pBtHciInfo->LocationDomainOptions; /* 0x58; Location_Domain_Options */
2222 pRetPar[5] = pBtHciInfo->LocationOptions; /* 0x0; Location_Options */
2224 PPacketIrpEvent->Length = len;
2226 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2230 static enum hci_status
2231 bthci_CmdWriteLocationData(
2232 struct rtw_adapter *padapter,
2233 struct packet_irp_hcicmd_data *pHciCmd
2236 enum hci_status status = HCI_STATUS_SUCCESS;
2237 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2238 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2240 u8 localBuf[6] = "";
2243 struct packet_irp_hcievent_data *PPacketIrpEvent;
2245 pBtHciInfo->LocationDomainAware = pHciCmd->Data[0];
2246 pu2Temp = (u16 *)&pHciCmd->Data[1];
2247 pBtHciInfo->LocationDomain = *pu2Temp;
2248 pBtHciInfo->LocationDomainOptions = pHciCmd->Data[3];
2249 pBtHciInfo->LocationOptions = pHciCmd->Data[4];
2250 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2251 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2252 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2253 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2255 /* send command complete event here when all data are received. */
2256 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2258 len += bthci_CommandCompleteHeader(&localBuf[0],
2259 OGF_SET_EVENT_MASK_COMMAND,
2260 HCI_WRITE_LOCATION_DATA,
2263 /* Return parameters starts from here */
2264 pRetPar = &PPacketIrpEvent->Data[len];
2265 pRetPar[0] = status; /* status */
2267 PPacketIrpEvent->Length = len;
2269 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2274 static enum hci_status
2275 bthci_CmdReadFlowControlMode(
2276 struct rtw_adapter *padapter,
2277 struct packet_irp_hcicmd_data *pHciCmd
2280 enum hci_status status = HCI_STATUS_SUCCESS;
2281 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2282 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2283 u8 localBuf[7] = "";
2286 struct packet_irp_hcievent_data *PPacketIrpEvent;
2288 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2290 len += bthci_CommandCompleteHeader(&localBuf[0],
2291 OGF_SET_EVENT_MASK_COMMAND,
2292 HCI_READ_FLOW_CONTROL_MODE,
2295 /* Return parameters starts from here */
2296 pRetPar = &PPacketIrpEvent->Data[len];
2297 pRetPar[0] = status;
2298 pRetPar[1] = pBtHciInfo->FlowControlMode; /* Flow Control Mode */
2300 PPacketIrpEvent->Length = len;
2302 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2306 static enum hci_status
2307 bthci_CmdWriteFlowControlMode(
2308 struct rtw_adapter *padapter,
2309 struct packet_irp_hcicmd_data *pHciCmd
2312 enum hci_status status = HCI_STATUS_SUCCESS;
2313 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2314 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2315 u8 localBuf[6] = "";
2318 struct packet_irp_hcievent_data *PPacketIrpEvent;
2320 pBtHciInfo->FlowControlMode = pHciCmd->Data[0];
2322 /* send command complete event here when all data are received. */
2323 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2325 len += bthci_CommandCompleteHeader(&localBuf[0],
2326 OGF_SET_EVENT_MASK_COMMAND,
2327 HCI_WRITE_FLOW_CONTROL_MODE,
2330 /* Return parameters starts from here */
2331 pRetPar = &PPacketIrpEvent->Data[len];
2332 pRetPar[0] = status; /* status */
2334 PPacketIrpEvent->Length = len;
2336 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2341 static enum hci_status
2342 bthci_CmdReadBestEffortFlushTimeout(
2343 struct rtw_adapter *padapter,
2344 struct packet_irp_hcicmd_data *pHciCmd
2347 enum hci_status status = HCI_STATUS_SUCCESS;
2348 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2349 u16 i, j, logicHandle;
2350 u32 BestEffortFlushTimeout = 0xffffffff;
2353 logicHandle = *((u16 *)pHciCmd->Data);
2354 /* find an matched logical link index and copy the data */
2355 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2356 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2357 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2358 BestEffortFlushTimeout = pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout;
2366 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2369 u8 localBuf[10] = "";
2372 struct packet_irp_hcievent_data *PPacketIrpEvent;
2375 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2377 len += bthci_CommandCompleteHeader(&localBuf[0],
2378 OGF_SET_EVENT_MASK_COMMAND,
2379 HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT,
2382 /* Return parameters starts from here */
2383 pRetPar = &PPacketIrpEvent->Data[len];
2384 pRetPar[0] = status;
2385 pu4Temp = (u32 *)&pRetPar[1]; /* Best_Effort_Flush_Timeout */
2386 *pu4Temp = BestEffortFlushTimeout;
2388 PPacketIrpEvent->Length = len;
2390 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2395 static enum hci_status
2396 bthci_CmdWriteBestEffortFlushTimeout(
2397 struct rtw_adapter *padapter,
2398 struct packet_irp_hcicmd_data *pHciCmd
2401 enum hci_status status = HCI_STATUS_SUCCESS;
2402 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2403 u16 i, j, logicHandle;
2404 u32 BestEffortFlushTimeout = 0xffffffff;
2407 logicHandle = *((u16 *)pHciCmd->Data);
2408 BestEffortFlushTimeout = *((u32 *)(pHciCmd->Data+1));
2410 /* find an matched logical link index and copy the data */
2411 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2412 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2413 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2414 pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout = BestEffortFlushTimeout;
2422 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2425 u8 localBuf[6] = "";
2428 struct packet_irp_hcievent_data *PPacketIrpEvent;
2430 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2432 len += bthci_CommandCompleteHeader(&localBuf[0],
2433 OGF_SET_EVENT_MASK_COMMAND,
2434 HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT,
2437 /* Return parameters starts from here */
2438 pRetPar = &PPacketIrpEvent->Data[len];
2439 pRetPar[0] = status;
2441 PPacketIrpEvent->Length = len;
2443 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2448 static enum hci_status
2449 bthci_CmdShortRangeMode(
2450 struct rtw_adapter *padapter,
2451 struct packet_irp_hcicmd_data *pHciCmd
2454 enum hci_status status = HCI_STATUS_SUCCESS;
2455 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2456 u8 PhyLinkHandle, EntryNum, ShortRangeMode;
2458 PhyLinkHandle = pHciCmd->Data[0];
2459 ShortRangeMode = pHciCmd->Data[1];
2460 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x, Short_Range_Mode = 0x%x\n", PhyLinkHandle, ShortRangeMode));
2462 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2463 if (EntryNum != 0xff) {
2464 pBTInfo->BtAsocEntry[EntryNum].ShortRangeMode = ShortRangeMode;
2466 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PhyLinkHandle));
2467 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2470 bthci_EventCommandStatus(padapter,
2471 OGF_SET_EVENT_MASK_COMMAND,
2472 HCI_SHORT_RANGE_MODE,
2475 bthci_EventShortRangeModeChangeComplete(padapter, status, ShortRangeMode, EntryNum);
2480 static enum hci_status bthci_CmdReadLocalSupportedCommands(struct rtw_adapter *padapter)
2482 enum hci_status status = HCI_STATUS_SUCCESS;
2483 u8 localBuf[TmpLocalBufSize] = "";
2484 u8 *pRetPar, *pSupportedCmds;
2486 struct packet_irp_hcievent_data *PPacketIrpEvent;
2488 /* send command complete event here when all data are received. */
2489 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2490 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2492 len += bthci_CommandCompleteHeader(&localBuf[0],
2493 OGF_INFORMATIONAL_PARAMETERS,
2494 HCI_READ_LOCAL_SUPPORTED_COMMANDS,
2497 /* Return parameters starts from here */
2498 pRetPar = &PPacketIrpEvent->Data[len];
2499 pRetPar[0] = status; /* status */
2501 pSupportedCmds = &pRetPar[1];
2502 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[5]= 0xc0\nBit [6]= Set Event Mask, [7]= Reset\n"));
2503 pSupportedCmds[5] = 0xc0;
2504 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[6]= 0x01\nBit [0]= Set Event Filter\n"));
2505 pSupportedCmds[6] = 0x01;
2506 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[7]= 0x0c\nBit [2]= Read Connection Accept Timeout, [3]= Write Connection Accept Timeout\n"));
2507 pSupportedCmds[7] = 0x0c;
2508 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[10]= 0x80\nBit [7]= Host Number Of Completed Packets\n"));
2509 pSupportedCmds[10] = 0x80;
2510 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[11]= 0x03\nBit [0]= Read Link Supervision Timeout, [1]= Write Link Supervision Timeout\n"));
2511 pSupportedCmds[11] = 0x03;
2512 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"));
2513 pSupportedCmds[14] = 0xa8;
2514 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"));
2515 pSupportedCmds[15] = 0x1c;
2516 /* pSupportedCmds[16] = 0x04; */
2517 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[19]= 0x40\nBit [6]= Enhanced Flush\n"));
2518 pSupportedCmds[19] = 0x40;
2519 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"));
2520 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"));
2521 pSupportedCmds[21] = 0xff;
2522 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"));
2523 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"));
2524 pSupportedCmds[22] = 0xff;
2525 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"));
2526 pSupportedCmds[23] = 0x07;
2527 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"));
2528 pSupportedCmds[24] = 0x1c;
2530 PPacketIrpEvent->Length = len;
2532 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2537 static enum hci_status bthci_CmdReadLocalSupportedFeatures(struct rtw_adapter *padapter)
2539 enum hci_status status = HCI_STATUS_SUCCESS;
2540 u8 localBuf[TmpLocalBufSize] = "";
2543 struct packet_irp_hcievent_data *PPacketIrpEvent;
2545 /* send command complete event here when all data are received. */
2546 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2547 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2549 len += bthci_CommandCompleteHeader(&localBuf[0],
2550 OGF_INFORMATIONAL_PARAMETERS,
2551 HCI_READ_LOCAL_SUPPORTED_FEATURES,
2554 /* Return parameters starts from here */
2555 pRetPar = &PPacketIrpEvent->Data[len];
2556 pRetPar[0] = status; /* status */
2558 PPacketIrpEvent->Length = len;
2560 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2564 static enum hci_status bthci_CmdReadLocalAMPAssoc(struct rtw_adapter *padapter,
2565 struct packet_irp_hcicmd_data *pHciCmd)
2567 enum hci_status status = HCI_STATUS_SUCCESS;
2568 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2569 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
2570 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2571 u8 PhyLinkHandle, EntryNum;
2573 pBtDbg->dbgHciInfo.hciCmdCntReadLocalAmpAssoc++;
2574 PhyLinkHandle = *((u8 *)pHciCmd->Data);
2575 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2577 if ((EntryNum == 0xff) && PhyLinkHandle != 0) {
2578 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x\n",
2579 EntryNum, PhyLinkHandle));
2580 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2581 } else if (pBtMgnt->bPhyLinkInProgressStartLL) {
2582 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2583 pBtMgnt->bPhyLinkInProgressStartLL = false;
2585 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
2586 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
2587 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen = *((u16 *)((u8 *)pHciCmd->Data+3));
2588 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ReadLocalAMPAssoc, LenSoFar =%d, MaxRemoteASSOCLen =%d\n",
2589 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar,
2590 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen));
2593 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x, LengthSoFar = %x \n",
2594 EntryNum, PhyLinkHandle, pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar));
2596 /* send command complete event here when all data are received. */
2598 struct packet_irp_hcievent_data *PPacketIrpEvent;
2600 /* PVOID buffer = padapter->IrpHCILocalbuf.Ptr; */
2601 u8 localBuf[TmpLocalBufSize] = "";
2604 u16 typeLen = 0, remainLen = 0, ret_index = 0;
2607 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2608 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2609 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2611 totalLen += bthci_CommandCompleteHeader(&localBuf[0],
2612 OGF_STATUS_PARAMETERS,
2613 HCI_READ_LOCAL_AMP_ASSOC,
2615 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2616 /* Return parameters starts from here */
2617 pRetPar = &PPacketIrpEvent->Data[totalLen];
2618 pRetPar[0] = status; /* status */
2619 pRetPar[1] = *((u8 *)pHciCmd->Data);
2620 pRemainLen = (u16 *)&pRetPar[2]; /* AMP_ASSOC_Remaining_Length */
2621 totalLen += 4; /* 0]~[3] */
2624 typeLen = bthci_AssocMACAddr(padapter, &pRetPar[ret_index]);
2625 totalLen += typeLen;
2626 remainLen += typeLen;
2627 ret_index += typeLen;
2628 typeLen = bthci_AssocPreferredChannelList(padapter, &pRetPar[ret_index], EntryNum);
2629 totalLen += typeLen;
2630 remainLen += typeLen;
2631 ret_index += typeLen;
2632 typeLen = bthci_PALCapabilities(padapter, &pRetPar[ret_index]);
2633 totalLen += typeLen;
2634 remainLen += typeLen;
2635 ret_index += typeLen;
2636 typeLen = bthci_AssocPALVer(padapter, &pRetPar[ret_index]);
2637 totalLen += typeLen;
2638 remainLen += typeLen;
2639 PPacketIrpEvent->Length = (u8)totalLen;
2640 *pRemainLen = remainLen; /* AMP_ASSOC_Remaining_Length */
2641 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2642 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("AMP_ASSOC_fragment : \n"), PPacketIrpEvent->Data, totalLen);
2644 bthci_IndicateEvent(padapter, PPacketIrpEvent, totalLen+2);
2650 static enum hci_status bthci_CmdReadFailedContactCounter(struct rtw_adapter *padapter,
2651 struct packet_irp_hcicmd_data *pHciCmd)
2654 enum hci_status status = HCI_STATUS_SUCCESS;
2655 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2656 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2657 u8 localBuf[TmpLocalBufSize] = "";
2660 struct packet_irp_hcievent_data *PPacketIrpEvent;
2663 handle = *((u16 *)pHciCmd->Data);
2664 /* send command complete event here when all data are received. */
2665 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2666 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2668 len += bthci_CommandCompleteHeader(&localBuf[0],
2669 OGF_STATUS_PARAMETERS,
2670 HCI_READ_FAILED_CONTACT_COUNTER,
2673 /* Return parameters starts from here */
2674 pRetPar = &PPacketIrpEvent->Data[len];
2675 pRetPar[0] = status; /* status */
2676 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2677 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2678 pRetPar[3] = TWOBYTE_LOWBYTE(pBtHciInfo->FailContactCount);
2679 pRetPar[4] = TWOBYTE_HIGHTBYTE(pBtHciInfo->FailContactCount);
2681 PPacketIrpEvent->Length = len;
2683 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2688 static enum hci_status
2689 bthci_CmdResetFailedContactCounter(
2690 struct rtw_adapter *padapter,
2691 struct packet_irp_hcicmd_data *pHciCmd
2694 enum hci_status status = HCI_STATUS_SUCCESS;
2695 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2696 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2697 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2699 u8 localBuf[TmpLocalBufSize] = "";
2702 struct packet_irp_hcievent_data *PPacketIrpEvent;
2704 handle = *((u16 *)pHciCmd->Data);
2705 pBtHciInfo->FailContactCount = 0;
2707 /* send command complete event here when all data are received. */
2708 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2709 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2710 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2712 len += bthci_CommandCompleteHeader(&localBuf[0],
2713 OGF_STATUS_PARAMETERS,
2714 HCI_RESET_FAILED_CONTACT_COUNTER,
2717 /* Return parameters starts from here */
2718 pRetPar = &PPacketIrpEvent->Data[len];
2719 pRetPar[0] = status; /* status */
2720 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2721 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2723 PPacketIrpEvent->Length = len;
2725 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2730 /* BT 3.0+HS [Vol 2] 7.4.1 */
2732 static enum hci_status
2733 bthci_CmdReadLocalVersionInformation(
2734 struct rtw_adapter *padapter
2737 enum hci_status status = HCI_STATUS_SUCCESS;
2738 /* send command complete event here when all data are received. */
2739 u8 localBuf[TmpLocalBufSize] = "";
2742 struct packet_irp_hcievent_data *PPacketIrpEvent;
2745 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2746 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2748 len += bthci_CommandCompleteHeader(&localBuf[0],
2749 OGF_INFORMATIONAL_PARAMETERS,
2750 HCI_READ_LOCAL_VERSION_INFORMATION,
2753 /* Return parameters starts from here */
2754 pRetPar = &PPacketIrpEvent->Data[len];
2755 pRetPar[0] = status; /* status */
2756 pRetPar[1] = 0x05; /* HCI_Version */
2757 pu2Temp = (u16 *)&pRetPar[2]; /* HCI_Revision */
2759 pRetPar[4] = 0x05; /* LMP/PAL_Version */
2760 pu2Temp = (u16 *)&pRetPar[5]; /* Manufacturer_Name */
2762 pu2Temp = (u16 *)&pRetPar[7]; /* LMP/PAL_Subversion */
2765 PPacketIrpEvent->Length = len;
2767 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LOCAL_VERSION_INFORMATION\n"));
2768 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Status %x\n", status));
2769 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Version = 0x05\n"));
2770 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Revision = 0x0001\n"));
2771 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Version = 0x05\n"));
2772 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Manufacturer_Name = 0x0001\n"));
2773 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Subversion = 0x0001\n"));
2775 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2781 static enum hci_status bthci_CmdReadDataBlockSize(struct rtw_adapter *padapter)
2783 enum hci_status status = HCI_STATUS_SUCCESS;
2784 u8 localBuf[TmpLocalBufSize] = "";
2787 struct packet_irp_hcievent_data *PPacketIrpEvent;
2790 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2791 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2793 len += bthci_CommandCompleteHeader(&localBuf[0],
2794 OGF_INFORMATIONAL_PARAMETERS,
2795 HCI_READ_DATA_BLOCK_SIZE,
2798 /* Return parameters starts from here */
2799 pRetPar = &PPacketIrpEvent->Data[len];
2800 pRetPar[0] = HCI_STATUS_SUCCESS; /* status */
2801 pu2Temp = (u16 *)&pRetPar[1]; /* Max_ACL_Data_Packet_Length */
2802 *pu2Temp = Max80211PALPDUSize;
2804 pu2Temp = (u16 *)&pRetPar[3]; /* Data_Block_Length */
2805 *pu2Temp = Max80211PALPDUSize;
2806 pu2Temp = (u16 *)&pRetPar[5]; /* Total_Num_Data_Blocks */
2807 *pu2Temp = BTTotalDataBlockNum;
2809 PPacketIrpEvent->Length = len;
2811 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2817 static enum hci_status bthci_CmdReadBufferSize(struct rtw_adapter *padapter)
2819 enum hci_status status = HCI_STATUS_SUCCESS;
2820 u8 localBuf[TmpLocalBufSize] = "";
2823 struct packet_irp_hcievent_data *PPacketIrpEvent;
2826 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2827 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2828 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2830 len += bthci_CommandCompleteHeader(&localBuf[0],
2831 OGF_INFORMATIONAL_PARAMETERS,
2832 HCI_READ_BUFFER_SIZE,
2834 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Synchronous_Data_Packet_Length = 0x%x\n", BTSynDataPacketLength));
2835 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_ACL_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2836 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_Synchronous_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2837 /* Return parameters starts from here */
2838 pRetPar = &PPacketIrpEvent->Data[len];
2839 pRetPar[0] = status; /* status */
2840 pu2Temp = (u16 *)&pRetPar[1]; /* HC_ACL_Data_Packet_Length */
2841 *pu2Temp = Max80211PALPDUSize;
2843 pRetPar[3] = BTSynDataPacketLength; /* HC_Synchronous_Data_Packet_Length */
2844 pu2Temp = (u16 *)&pRetPar[4]; /* HC_Total_Num_ACL_Data_Packets */
2845 *pu2Temp = BTTotalDataBlockNum;
2846 pu2Temp = (u16 *)&pRetPar[6]; /* HC_Total_Num_Synchronous_Data_Packets */
2847 *pu2Temp = BTTotalDataBlockNum;
2849 PPacketIrpEvent->Length = len;
2851 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2856 static enum hci_status bthci_CmdReadLocalAMPInfo(struct rtw_adapter *padapter)
2858 enum hci_status status = HCI_STATUS_SUCCESS;
2859 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
2860 u8 localBuf[TmpLocalBufSize] = "";
2863 struct packet_irp_hcievent_data *PPacketIrpEvent;
2866 u32 TotalBandwidth = BTTOTALBANDWIDTH, MaxBandGUBandwidth = BTMAXBANDGUBANDWIDTH;
2867 u8 ControlType = 0x01, AmpStatus = 0x01;
2868 u32 MaxFlushTimeout = 10000, BestEffortFlushTimeout = 5000;
2869 u16 MaxPDUSize = Max80211PALPDUSize, PalCap = 0x1, AmpAssocLen = Max80211AMPASSOCLen, MinLatency = 20;
2871 if ((ppwrctrl->rfoff_reason & RF_CHANGE_BY_HW) ||
2872 (ppwrctrl->rfoff_reason & RF_CHANGE_BY_SW)) {
2873 AmpStatus = AMP_STATUS_NO_CAPACITY_FOR_BT;
2876 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2877 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2878 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2880 len += bthci_CommandCompleteHeader(&localBuf[0],
2881 OGF_STATUS_PARAMETERS,
2882 HCI_READ_LOCAL_AMP_INFO,
2885 /* Return parameters starts from here */
2886 pRetPar = &PPacketIrpEvent->Data[len];
2887 pRetPar[0] = status; /* status */
2888 pRetPar[1] = AmpStatus; /* AMP_Status */
2889 pu4Temp = (u32 *)&pRetPar[2]; /* Total_Bandwidth */
2890 *pu4Temp = TotalBandwidth; /* 0x19bfcc00;0x7530; */
2891 pu4Temp = (u32 *)&pRetPar[6]; /* Max_Guaranteed_Bandwidth */
2892 *pu4Temp = MaxBandGUBandwidth; /* 0x19bfcc00;0x4e20; */
2893 pu4Temp = (u32 *)&pRetPar[10]; /* Min_Latency */
2894 *pu4Temp = MinLatency; /* 150; */
2895 pu4Temp = (u32 *)&pRetPar[14]; /* Max_PDU_Size */
2896 *pu4Temp = MaxPDUSize;
2897 pRetPar[18] = ControlType; /* Controller_Type */
2898 pu2Temp = (u16 *)&pRetPar[19]; /* PAL_Capabilities */
2900 pu2Temp = (u16 *)&pRetPar[21]; /* AMP_ASSOC_Length */
2901 *pu2Temp = AmpAssocLen;
2902 pu4Temp = (u32 *)&pRetPar[23]; /* Max_Flush_Timeout */
2903 *pu4Temp = MaxFlushTimeout;
2904 pu4Temp = (u32 *)&pRetPar[27]; /* Best_Effort_Flush_Timeout */
2905 *pu4Temp = BestEffortFlushTimeout;
2907 PPacketIrpEvent->Length = len;
2908 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("AmpStatus = 0x%x\n",
2910 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TotalBandwidth = 0x%x, MaxBandGUBandwidth = 0x%x, MinLatency = 0x%x, \n MaxPDUSize = 0x%x, ControlType = 0x%x\n",
2911 TotalBandwidth, MaxBandGUBandwidth, MinLatency, MaxPDUSize, ControlType));
2912 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PalCap = 0x%x, AmpAssocLen = 0x%x, MaxFlushTimeout = 0x%x, BestEffortFlushTimeout = 0x%x\n",
2913 PalCap, AmpAssocLen, MaxFlushTimeout, BestEffortFlushTimeout));
2914 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2918 static enum hci_status
2919 bthci_CmdCreatePhysicalLink(
2920 struct rtw_adapter *padapter,
2921 struct packet_irp_hcicmd_data *pHciCmd
2924 enum hci_status status;
2925 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2926 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2928 pBtDbg->dbgHciInfo.hciCmdCntCreatePhyLink++;
2930 status = bthci_BuildPhysicalLink(padapter,
2931 pHciCmd, HCI_CREATE_PHYSICAL_LINK);
2936 static enum hci_status
2937 bthci_CmdReadLinkQuality(
2938 struct rtw_adapter *padapter,
2939 struct packet_irp_hcicmd_data *pHciCmd
2942 enum hci_status status = HCI_STATUS_SUCCESS;
2943 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2945 u8 EntryNum, LinkQuality = 0x55;
2947 PLH = *((u16 *)&pHciCmd->Data[0]);
2948 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x\n", PLH));
2950 EntryNum = bthci_GetCurrentEntryNum(padapter, (u8)PLH);
2951 if (EntryNum == 0xff) {
2952 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PLH));
2953 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2957 u8 localBuf[11] = "";
2960 struct packet_irp_hcievent_data *PPacketIrpEvent;
2962 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2964 len += bthci_CommandCompleteHeader(&localBuf[0],
2965 OGF_STATUS_PARAMETERS,
2966 HCI_READ_LINK_QUALITY,
2969 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" PLH = 0x%x\n Link Quality = 0x%x\n", PLH, LinkQuality));
2971 /* Return parameters starts from here */
2972 pRetPar = &PPacketIrpEvent->Data[len];
2973 pRetPar[0] = status; /* status */
2974 *((u16 *)&pRetPar[1]) = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle; /* Handle */
2975 pRetPar[3] = 0x55; /* Link Quailty */
2977 PPacketIrpEvent->Length = len;
2979 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2985 static enum hci_status bthci_CmdReadRSSI(struct rtw_adapter *padapter)
2987 enum hci_status status = HCI_STATUS_SUCCESS;
2991 static enum hci_status
2992 bthci_CmdCreateLogicalLink(
2993 struct rtw_adapter *padapter,
2994 struct packet_irp_hcicmd_data *pHciCmd
2997 enum hci_status status = HCI_STATUS_SUCCESS;
2998 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2999 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3001 pBtDbg->dbgHciInfo.hciCmdCntCreateLogLink++;
3003 bthci_BuildLogicalLink(padapter, pHciCmd,
3004 HCI_CREATE_LOGICAL_LINK);
3009 static enum hci_status
3010 bthci_CmdAcceptLogicalLink(
3011 struct rtw_adapter *padapter,
3012 struct packet_irp_hcicmd_data *pHciCmd
3015 enum hci_status status = HCI_STATUS_SUCCESS;
3016 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3017 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3019 pBtDbg->dbgHciInfo.hciCmdCntAcceptLogLink++;
3021 bthci_BuildLogicalLink(padapter, pHciCmd,
3022 HCI_ACCEPT_LOGICAL_LINK);
3027 static enum hci_status
3028 bthci_CmdDisconnectLogicalLink(
3029 struct rtw_adapter *padapter,
3030 struct packet_irp_hcicmd_data *pHciCmd
3033 enum hci_status status = HCI_STATUS_SUCCESS;
3034 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3035 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3036 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3037 struct bt_dgb *pBtDbg = &pBTinfo->BtDbg;
3039 u8 i, j, find = 0, LogLinkCount = 0;
3041 pBtDbg->dbgHciInfo.hciCmdCntDisconnectLogLink++;
3043 logicHandle = *((u16 *)pHciCmd->Data);
3044 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle = 0x%x\n", logicHandle));
3046 /* find an created logical link index and clear the data */
3047 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3048 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3049 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3050 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle is matched 0x%x\n", logicHandle));
3051 bthci_ResetFlowSpec(padapter, j, i);
3053 pBtMgnt->DisconnectEntryNum = j;
3060 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3063 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3064 if (pBTinfo->BtAsocEntry[pBtMgnt->DisconnectEntryNum].LogLinkCmdData[i].BtLogLinkhandle != 0)
3068 /* When we receive Create logical link command, we should send command status event first. */
3069 bthci_EventCommandStatus(padapter,
3070 LINK_CONTROL_COMMANDS,
3071 HCI_DISCONNECT_LOGICAL_LINK,
3074 /* When we determines the logical link is established, we should send command complete event. */
3076 if (status == HCI_STATUS_SUCCESS) {
3077 bthci_EventDisconnectLogicalLinkComplete(padapter, status,
3078 logicHandle, HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST);
3081 if (LogLinkCount == 0)
3082 mod_timer(&pBTinfo->BTDisconnectPhyLinkTimer,
3083 jiffies + msecs_to_jiffies(100));
3088 static enum hci_status
3089 bthci_CmdLogicalLinkCancel(struct rtw_adapter *padapter,
3090 struct packet_irp_hcicmd_data *pHciCmd)
3092 enum hci_status status = HCI_STATUS_SUCCESS;
3093 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3094 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3095 u8 CurrentEntryNum, CurrentLogEntryNum;
3097 u8 physicalLinkHandle, TxFlowSpecID, i;
3098 u16 CurrentLogicalHandle;
3100 physicalLinkHandle = *((u8 *)pHciCmd->Data);
3101 TxFlowSpecID = *(((u8 *)pHciCmd->Data)+1);
3103 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, physicalLinkHandle = 0x%x, TxFlowSpecID = 0x%x\n",
3104 physicalLinkHandle, TxFlowSpecID));
3106 CurrentEntryNum = pBtMgnt->CurrentConnectEntryNum;
3107 CurrentLogicalHandle = pBtMgnt->BtCurrentLogLinkhandle;
3109 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("CurrentEntryNum = 0x%x, CurrentLogicalHandle = 0x%x\n",
3110 CurrentEntryNum, CurrentLogicalHandle));
3112 CurrentLogEntryNum = 0xff;
3113 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3114 if ((CurrentLogicalHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtLogLinkhandle) &&
3115 (physicalLinkHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtPhyLinkhandle)) {
3116 CurrentLogEntryNum = i;
3121 if (CurrentLogEntryNum == 0xff) {
3122 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, CurrentLogEntryNum == 0xff !!!!\n"));
3123 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3126 if (pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCompleteEventIsSet) {
3127 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, LLCompleteEventIsSet!!!!\n"));
3128 status = HCI_STATUS_ACL_CONNECT_EXISTS;
3133 u8 localBuf[8] = "";
3136 struct packet_irp_hcievent_data *PPacketIrpEvent;
3138 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3140 len += bthci_CommandCompleteHeader(&localBuf[0],
3141 LINK_CONTROL_COMMANDS,
3142 HCI_LOGICAL_LINK_CANCEL,
3145 /* Return parameters starts from here */
3146 pRetPar = &PPacketIrpEvent->Data[len];
3147 pRetPar[0] = status; /* status */
3148 pRetPar[1] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtPhyLinkhandle;
3149 pRetPar[2] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtTxFlowSpecID;
3151 PPacketIrpEvent->Length = len;
3153 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3156 pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCancelCMDIsSetandComplete = true;
3161 static enum hci_status
3162 bthci_CmdFlowSpecModify(struct rtw_adapter *padapter,
3163 struct packet_irp_hcicmd_data *pHciCmd)
3165 enum hci_status status = HCI_STATUS_SUCCESS;
3166 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3167 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3171 logicHandle = *((u16 *)pHciCmd->Data);
3172 /* find an matched logical link index and copy the data */
3173 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3174 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3175 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3176 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec,
3177 &pHciCmd->Data[2], sizeof(struct hci_flow_spec));
3178 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Rx_Flow_Spec,
3179 &pHciCmd->Data[18], sizeof(struct hci_flow_spec));
3181 bthci_CheckLogLinkBehavior(padapter, pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec);
3187 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("FlowSpecModify, LLH = 0x%x, \n", logicHandle));
3189 /* When we receive Flow Spec Modify command, we should send command status event first. */
3190 bthci_EventCommandStatus(padapter,
3191 LINK_CONTROL_COMMANDS,
3192 HCI_FLOW_SPEC_MODIFY,
3193 HCI_STATUS_SUCCESS);
3196 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3198 bthci_EventSendFlowSpecModifyComplete(padapter, status, logicHandle);
3203 static enum hci_status
3204 bthci_CmdAcceptPhysicalLink(struct rtw_adapter *padapter,
3205 struct packet_irp_hcicmd_data *pHciCmd)
3207 enum hci_status status;
3208 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3209 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3211 pBtDbg->dbgHciInfo.hciCmdCntAcceptPhyLink++;
3213 status = bthci_BuildPhysicalLink(padapter,
3214 pHciCmd, HCI_ACCEPT_PHYSICAL_LINK);
3219 static enum hci_status
3220 bthci_CmdDisconnectPhysicalLink(struct rtw_adapter *padapter,
3221 struct packet_irp_hcicmd_data *pHciCmd)
3223 enum hci_status status = HCI_STATUS_SUCCESS;
3224 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3225 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3226 u8 PLH, CurrentEntryNum, PhysLinkDisconnectReason;
3228 pBtDbg->dbgHciInfo.hciCmdCntDisconnectPhyLink++;
3230 PLH = *((u8 *)pHciCmd->Data);
3231 PhysLinkDisconnectReason = (*((u8 *)pHciCmd->Data+1));
3232 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK PhyHandle = 0x%x, Reason = 0x%x\n",
3233 PLH, PhysLinkDisconnectReason));
3235 CurrentEntryNum = bthci_GetCurrentEntryNum(padapter, PLH);
3237 if (CurrentEntryNum == 0xff) {
3238 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
3239 ("DisconnectPhysicalLink, No such Handle in the Entry\n"));
3240 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3242 pBTInfo->BtAsocEntry[CurrentEntryNum].PhyLinkDisconnectReason =
3243 (enum hci_status)PhysLinkDisconnectReason;
3245 /* Send HCI Command status event to AMP. */
3246 bthci_EventCommandStatus(padapter, LINK_CONTROL_COMMANDS,
3247 HCI_DISCONNECT_PHYSICAL_LINK, status);
3249 if (status != HCI_STATUS_SUCCESS)
3252 /* The macros below require { and } in the if statement */
3253 if (pBTInfo->BtAsocEntry[CurrentEntryNum].BtCurrentState == HCI_STATE_DISCONNECTED) {
3254 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3256 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3261 static enum hci_status
3262 bthci_CmdSetACLLinkDataFlowMode(struct rtw_adapter *padapter,
3263 struct packet_irp_hcicmd_data *pHciCmd)
3265 enum hci_status status = HCI_STATUS_SUCCESS;
3266 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3267 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3268 u8 localBuf[8] = "";
3271 struct packet_irp_hcievent_data *PPacketIrpEvent;
3274 pBtMgnt->ExtConfig.CurrentConnectHandle = *((u16 *)pHciCmd->Data);
3275 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = *((u8 *)pHciCmd->Data)+2;
3276 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = *((u8 *)pHciCmd->Data)+3;
3277 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Connection Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic mode = 0x%x",
3278 pBtMgnt->ExtConfig.CurrentConnectHandle,
3279 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode,
3280 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode));
3283 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3285 len += bthci_CommandCompleteHeader(&localBuf[0],
3287 HCI_SET_ACL_LINK_DATA_FLOW_MODE,
3290 /* Return parameters starts from here */
3291 pRetPar = &PPacketIrpEvent->Data[len];
3292 pRetPar[0] = status; /* status */
3294 pu2Temp = (u16 *)&pRetPar[1];
3295 *pu2Temp = pBtMgnt->ExtConfig.CurrentConnectHandle;
3297 PPacketIrpEvent->Length = len;
3299 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3303 static enum hci_status
3304 bthci_CmdSetACLLinkStatus(struct rtw_adapter *padapter,
3305 struct packet_irp_hcicmd_data *pHciCmd)
3307 enum hci_status status = HCI_STATUS_SUCCESS;
3308 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3309 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3310 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3314 pBtDbg->dbgHciInfo.hciCmdCntSetAclLinkStatus++;
3315 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "SetACLLinkStatus, Hex Data :\n",
3316 &pHciCmd->Data[0], pHciCmd->Length);
3318 /* Only Core Stack v251 and later version support this command. */
3319 pBtMgnt->bSupportProfile = true;
3321 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3322 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3324 pTriple = &pHciCmd->Data[1];
3325 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3326 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3327 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = pTriple[2];
3328 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = pTriple[3];
3329 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3330 ("Connection_Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic Mode = 0x%x\n",
3331 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3332 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode,
3333 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode));
3338 u8 localBuf[6] = "";
3341 struct packet_irp_hcievent_data *PPacketIrpEvent;
3343 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3345 len += bthci_CommandCompleteHeader(&localBuf[0],
3347 HCI_SET_ACL_LINK_STATUS,
3350 /* Return parameters starts from here */
3351 pRetPar = &PPacketIrpEvent->Data[len];
3352 pRetPar[0] = status; /* status */
3355 PPacketIrpEvent->Length = len;
3357 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3363 static enum hci_status
3364 bthci_CmdSetSCOLinkStatus(
3365 struct rtw_adapter *padapter,
3366 struct packet_irp_hcicmd_data *pHciCmd
3369 enum hci_status status = HCI_STATUS_SUCCESS;
3370 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3371 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3372 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3374 pBtDbg->dbgHciInfo.hciCmdCntSetScoLinkStatus++;
3375 pBtMgnt->ExtConfig.NumberOfSCO = *((u8 *)pHciCmd->Data);
3376 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfSCO = 0x%x\n",
3377 pBtMgnt->ExtConfig.NumberOfSCO));
3380 u8 localBuf[6] = "";
3383 struct packet_irp_hcievent_data *PPacketIrpEvent;
3385 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3387 len += bthci_CommandCompleteHeader(&localBuf[0],
3389 HCI_SET_SCO_LINK_STATUS,
3392 /* Return parameters starts from here */
3393 pRetPar = &PPacketIrpEvent->Data[len];
3394 pRetPar[0] = status; /* status */
3397 PPacketIrpEvent->Length = len;
3399 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3405 static enum hci_status
3406 bthci_CmdSetRSSIValue(
3407 struct rtw_adapter *padapter,
3408 struct packet_irp_hcicmd_data *pHciCmd
3411 enum hci_status status = HCI_STATUS_SUCCESS;
3412 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3413 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3416 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3417 if (pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle == *((u16 *)&pHciCmd->Data[0])) {
3418 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = (s8)(pHciCmd->Data[2]);
3419 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL,
3420 ("Connection_Handle = 0x%x, RSSI = %d \n",
3421 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3422 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI));
3424 /* get the minimum bt rssi value */
3425 if (pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI <= min_bt_rssi)
3426 min_bt_rssi = pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI;
3429 pBtMgnt->ExtConfig.MIN_BT_RSSI = min_bt_rssi;
3430 RTPRINT(FBT, BT_TRACE, ("[bt rssi], the min rssi is %d\n", min_bt_rssi));
3433 u8 localBuf[6] = "";
3436 struct packet_irp_hcievent_data *PPacketIrpEvent;
3438 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3440 len += bthci_CommandCompleteHeader(&localBuf[0],
3445 /* Return parameters starts from here */
3446 pRetPar = &PPacketIrpEvent->Data[len];
3447 pRetPar[0] = status; /* status */
3450 PPacketIrpEvent->Length = len;
3452 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3458 static enum hci_status
3459 bthci_CmdSetCurrentBluetoothStatus(
3460 struct rtw_adapter *padapter,
3461 struct packet_irp_hcicmd_data *pHciCmd
3464 enum hci_status status = HCI_STATUS_SUCCESS;
3465 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3466 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3467 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3469 pBtMgnt->ExtConfig.CurrentBTStatus = *((u8 *)&pHciCmd->Data[0]);
3470 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("SetCurrentBluetoothStatus, CurrentBTStatus = 0x%x\n",
3471 pBtMgnt->ExtConfig.CurrentBTStatus));
3474 u8 localBuf[6] = "";
3477 struct packet_irp_hcievent_data *PPacketIrpEvent;
3479 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3481 len += bthci_CommandCompleteHeader(&localBuf[0],
3483 HCI_SET_CURRENT_BLUETOOTH_STATUS,
3486 /* Return parameters starts from here */
3487 pRetPar = &PPacketIrpEvent->Data[len];
3488 pRetPar[0] = status; /* status */
3491 PPacketIrpEvent->Length = len;
3493 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3499 static enum hci_status
3500 bthci_CmdExtensionVersionNotify(
3501 struct rtw_adapter *padapter,
3502 struct packet_irp_hcicmd_data *pHciCmd
3505 enum hci_status status = HCI_STATUS_SUCCESS;
3506 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3507 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3508 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3510 pBtDbg->dbgHciInfo.hciCmdCntExtensionVersionNotify++;
3511 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "ExtensionVersionNotify, Hex Data :\n",
3512 &pHciCmd->Data[0], pHciCmd->Length);
3514 pBtMgnt->ExtConfig.HCIExtensionVer = *((u16 *)&pHciCmd->Data[0]);
3515 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = 0x%x\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3518 u8 localBuf[6] = "";
3521 struct packet_irp_hcievent_data *PPacketIrpEvent;
3523 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3525 len += bthci_CommandCompleteHeader(&localBuf[0],
3527 HCI_EXTENSION_VERSION_NOTIFY,
3530 /* Return parameters starts from here */
3531 pRetPar = &PPacketIrpEvent->Data[len];
3532 pRetPar[0] = status; /* status */
3535 PPacketIrpEvent->Length = len;
3537 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3543 static enum hci_status
3544 bthci_CmdLinkStatusNotify(
3545 struct rtw_adapter *padapter,
3546 struct packet_irp_hcicmd_data *pHciCmd
3549 enum hci_status status = HCI_STATUS_SUCCESS;
3550 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3551 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3552 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3556 pBtDbg->dbgHciInfo.hciCmdCntLinkStatusNotify++;
3557 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "LinkStatusNotify, Hex Data :\n",
3558 &pHciCmd->Data[0], pHciCmd->Length);
3560 /* Current only RTL8723 support this command. */
3561 pBtMgnt->bSupportProfile = true;
3563 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3564 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3565 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = %d\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3567 pTriple = &pHciCmd->Data[1];
3568 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3569 if (pBtMgnt->ExtConfig.HCIExtensionVer < 1) {
3570 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3571 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3572 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3573 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3574 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d\n",
3575 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3576 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3577 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec));
3579 } else if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
3580 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3581 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3582 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3583 pBtMgnt->ExtConfig.linkInfo[i].linkRole = pTriple[4];
3584 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3585 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d, LinkRole =%d\n",
3586 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3587 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3588 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec,
3589 pBtMgnt->ExtConfig.linkInfo[i].linkRole));
3594 BTHCI_UpdateBTProfileRTKToMoto(padapter);
3596 u8 localBuf[6] = "";
3599 struct packet_irp_hcievent_data *PPacketIrpEvent;
3601 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3603 len += bthci_CommandCompleteHeader(&localBuf[0],
3605 HCI_LINK_STATUS_NOTIFY,
3608 /* Return parameters starts from here */
3609 pRetPar = &PPacketIrpEvent->Data[len];
3610 pRetPar[0] = status; /* status */
3613 PPacketIrpEvent->Length = len;
3615 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3621 static enum hci_status
3622 bthci_CmdBtOperationNotify(
3623 struct rtw_adapter *padapter,
3624 struct packet_irp_hcicmd_data *pHciCmd
3627 enum hci_status status = HCI_STATUS_SUCCESS;
3628 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3629 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3631 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Bt Operation notify, Hex Data :\n",
3632 &pHciCmd->Data[0], pHciCmd->Length);
3634 pBtMgnt->ExtConfig.btOperationCode = *((u8 *)pHciCmd->Data);
3635 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("btOperationCode = 0x%x\n", pBtMgnt->ExtConfig.btOperationCode));
3636 switch (pBtMgnt->ExtConfig.btOperationCode) {
3637 case HCI_BT_OP_NONE:
3638 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Operation None!!\n"));
3640 case HCI_BT_OP_INQUIRY_START:
3641 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire start!!\n"));
3643 case HCI_BT_OP_INQUIRY_FINISH:
3644 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire finished!!\n"));
3646 case HCI_BT_OP_PAGING_START:
3647 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging is started!!\n"));
3649 case HCI_BT_OP_PAGING_SUCCESS:
3650 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete successfully!!\n"));
3652 case HCI_BT_OP_PAGING_UNSUCCESS:
3653 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete unsuccessfully!!\n"));
3655 case HCI_BT_OP_PAIRING_START:
3656 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing start!!\n"));
3658 case HCI_BT_OP_PAIRING_FINISH:
3659 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing finished!!\n"));
3661 case HCI_BT_OP_BT_DEV_ENABLE:
3662 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is enabled!!\n"));
3664 case HCI_BT_OP_BT_DEV_DISABLE:
3665 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is disabled!!\n"));
3668 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Unknown, error!!\n"));
3671 BTDM_AdjustForBtOperation(padapter);
3673 u8 localBuf[6] = "";
3676 struct packet_irp_hcievent_data *PPacketIrpEvent;
3678 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3680 len += bthci_CommandCompleteHeader(&localBuf[0],
3682 HCI_BT_OPERATION_NOTIFY,
3685 /* Return parameters starts from here */
3686 pRetPar = &PPacketIrpEvent->Data[len];
3687 pRetPar[0] = status; /* status */
3690 PPacketIrpEvent->Length = len;
3692 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3698 static enum hci_status
3699 bthci_CmdEnableWifiScanNotify(struct rtw_adapter *padapter,
3700 struct packet_irp_hcicmd_data *pHciCmd)
3702 enum hci_status status = HCI_STATUS_SUCCESS;
3703 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3704 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3706 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Enable Wifi scan notify, Hex Data :\n",
3707 &pHciCmd->Data[0], pHciCmd->Length);
3709 pBtMgnt->ExtConfig.bEnableWifiScanNotify = *((u8 *)pHciCmd->Data);
3710 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("bEnableWifiScanNotify = %d\n", pBtMgnt->ExtConfig.bEnableWifiScanNotify));
3713 u8 localBuf[6] = "";
3716 struct packet_irp_hcievent_data *PPacketIrpEvent;
3718 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3720 len += bthci_CommandCompleteHeader(&localBuf[0],
3722 HCI_ENABLE_WIFI_SCAN_NOTIFY,
3725 /* Return parameters starts from here */
3726 pRetPar = &PPacketIrpEvent->Data[len];
3727 pRetPar[0] = status; /* status */
3730 PPacketIrpEvent->Length = len;
3732 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3738 static enum hci_status
3739 bthci_CmdWIFICurrentChannel(struct rtw_adapter *padapter,
3740 struct packet_irp_hcicmd_data *pHciCmd)
3742 enum hci_status status = HCI_STATUS_SUCCESS;
3743 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3744 u8 chnl = pmlmeext->cur_channel;
3746 if (pmlmeext->cur_bwmode == HT_CHANNEL_WIDTH_40) {
3747 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
3749 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
3753 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current Channel = 0x%x\n", chnl));
3756 u8 localBuf[8] = "";
3759 struct packet_irp_hcievent_data *PPacketIrpEvent;
3761 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3763 len += bthci_CommandCompleteHeader(&localBuf[0],
3765 HCI_WIFI_CURRENT_CHANNEL,
3768 /* Return parameters starts from here */
3769 pRetPar = &PPacketIrpEvent->Data[len];
3770 pRetPar[0] = status; /* status */
3771 pRetPar[1] = chnl; /* current channel */
3773 PPacketIrpEvent->Length = len;
3775 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3781 static enum hci_status
3782 bthci_CmdWIFICurrentBandwidth(struct rtw_adapter *padapter,
3783 struct packet_irp_hcicmd_data *pHciCmd)
3785 enum hci_status status = HCI_STATUS_SUCCESS;
3786 enum ht_channel_width bw;
3789 bw = padapter->mlmeextpriv.cur_bwmode;
3791 if (bw == HT_CHANNEL_WIDTH_20)
3793 else if (bw == HT_CHANNEL_WIDTH_40)
3796 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current BW = 0x%x\n",
3800 u8 localBuf[8] = "";
3803 struct packet_irp_hcievent_data *PPacketIrpEvent;
3805 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3807 len += bthci_CommandCompleteHeader(&localBuf[0],
3809 HCI_WIFI_CURRENT_BANDWIDTH,
3812 /* Return parameters starts from here */
3813 pRetPar = &PPacketIrpEvent->Data[len];
3814 pRetPar[0] = status; /* status */
3815 pRetPar[1] = CurrentBW; /* current BW */
3817 PPacketIrpEvent->Length = len;
3819 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3825 static enum hci_status
3826 bthci_CmdWIFIConnectionStatus(
3827 struct rtw_adapter *padapter,
3828 struct packet_irp_hcicmd_data *pHciCmd
3831 enum hci_status status = HCI_STATUS_SUCCESS;
3832 u8 connectStatus = HCI_WIFI_NOT_CONNECTED;
3834 if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) {
3835 if (padapter->stapriv.asoc_sta_count >= 3)
3836 connectStatus = HCI_WIFI_CONNECTED;
3838 connectStatus = HCI_WIFI_NOT_CONNECTED;
3839 } else if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE|WIFI_ASOC_STATE)) {
3840 connectStatus = HCI_WIFI_CONNECTED;
3841 } else if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING)) {
3842 connectStatus = HCI_WIFI_CONNECT_IN_PROGRESS;
3844 connectStatus = HCI_WIFI_NOT_CONNECTED;
3848 u8 localBuf[8] = "";
3851 struct packet_irp_hcievent_data *PPacketIrpEvent;
3853 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3855 len += bthci_CommandCompleteHeader(&localBuf[0],
3857 HCI_WIFI_CONNECTION_STATUS,
3860 /* Return parameters starts from here */
3861 pRetPar = &PPacketIrpEvent->Data[len];
3862 pRetPar[0] = status; /* status */
3863 pRetPar[1] = connectStatus; /* connect status */
3865 PPacketIrpEvent->Length = len;
3867 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3873 static enum hci_status
3874 bthci_CmdEnableDeviceUnderTestMode(
3875 struct rtw_adapter *padapter,
3876 struct packet_irp_hcicmd_data *pHciCmd
3879 enum hci_status status = HCI_STATUS_SUCCESS;
3880 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3881 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3883 pBtHciInfo->bInTestMode = true;
3884 pBtHciInfo->bTestIsEnd = false;
3886 /* send command complete event here when all data are received. */
3888 u8 localBuf[6] = "";
3891 struct packet_irp_hcievent_data *PPacketIrpEvent;
3893 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3895 len += bthci_CommandCompleteHeader(&localBuf[0],
3896 OGF_TESTING_COMMANDS,
3897 HCI_ENABLE_DEVICE_UNDER_TEST_MODE,
3900 /* Return parameters starts from here */
3901 pRetPar = &PPacketIrpEvent->Data[len];
3902 pRetPar[0] = status; /* status */
3904 PPacketIrpEvent->Length = len;
3906 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3912 static enum hci_status
3913 bthci_CmdAMPTestEnd(struct rtw_adapter *padapter,
3914 struct packet_irp_hcicmd_data *pHciCmd)
3916 enum hci_status status = HCI_STATUS_SUCCESS;
3917 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3918 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3920 if (!pBtHciInfo->bInTestMode) {
3921 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3922 status = HCI_STATUS_CMD_DISALLOW;
3926 pBtHciInfo->bTestIsEnd = true;
3928 del_timer_sync(&pBTInfo->BTTestSendPacketTimer);
3930 rtl8723a_check_bssid(padapter, true);
3932 /* send command complete event here when all data are received. */
3934 u8 localBuf[4] = "";
3935 struct packet_irp_hcievent_data *PPacketIrpEvent;
3937 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3938 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3939 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3940 PPacketIrpEvent->Length = 2;
3942 PPacketIrpEvent->Data[0] = status;
3943 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario;
3945 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3948 bthci_EventAMPReceiverReport(padapter, 0x01);
3953 static enum hci_status
3954 bthci_CmdAMPTestCommand(struct rtw_adapter *padapter,
3955 struct packet_irp_hcicmd_data *pHciCmd)
3957 enum hci_status status = HCI_STATUS_SUCCESS;
3958 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3959 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3961 if (!pBtHciInfo->bInTestMode) {
3962 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3963 status = HCI_STATUS_CMD_DISALLOW;
3967 pBtHciInfo->TestScenario = *((u8 *)pHciCmd->Data);
3969 if (pBtHciInfo->TestScenario == 0x01)
3970 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
3971 else if (pBtHciInfo->TestScenario == 0x02)
3972 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
3974 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("No Such Test !!!!!!!!!!!!!!!!!! \n"));
3976 if (pBtHciInfo->bTestIsEnd) {
3977 u8 localBuf[5] = "";
3978 struct packet_irp_hcievent_data *PPacketIrpEvent;
3980 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3981 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3982 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3983 PPacketIrpEvent->Length = 2;
3985 PPacketIrpEvent->Data[0] = status;
3986 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
3988 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3990 /* Return to Idel state with RX and TX off. */
3995 /* should send command status event */
3996 bthci_EventCommandStatus(padapter,
3997 OGF_TESTING_COMMANDS,
3998 HCI_AMP_TEST_COMMAND,
4001 /* The HCI_AMP_Start Test Event shall be generated when the */
4002 /* HCI_AMP_Test_Command has completed and the first data is ready to be sent */
4006 u8 localBuf[5] = "";
4007 struct packet_irp_hcievent_data *PPacketIrpEvent;
4009 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_AMP_Start Test Event \n"));
4010 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4011 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_START_TEST;
4012 PPacketIrpEvent->Length = 2;
4014 PPacketIrpEvent->Data[0] = status;
4015 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
4017 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
4019 /* Return to Idel state with RX and TX off. */
4022 if (pBtHciInfo->TestScenario == 0x01) {
4024 When in a transmitter test scenario and the frames/bursts count have been
4025 transmitted the HCI_AMP_Test_End event shall be sent.
4027 mod_timer(&pBTInfo->BTTestSendPacketTimer,
4028 jiffies + msecs_to_jiffies(50));
4029 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
4030 } else if (pBtHciInfo->TestScenario == 0x02) {
4031 rtl8723a_check_bssid(padapter, false);
4032 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
4038 static enum hci_status
4039 bthci_CmdEnableAMPReceiverReports(struct rtw_adapter *padapter,
4040 struct packet_irp_hcicmd_data *pHciCmd)
4042 enum hci_status status = HCI_STATUS_SUCCESS;
4043 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4044 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4046 if (!pBtHciInfo->bInTestMode) {
4047 status = HCI_STATUS_CMD_DISALLOW;
4048 /* send command complete event here when all data are received. */
4050 u8 localBuf[6] = "";
4053 struct packet_irp_hcievent_data *PPacketIrpEvent;
4055 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4057 len += bthci_CommandCompleteHeader(&localBuf[0],
4058 OGF_TESTING_COMMANDS,
4059 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4062 /* Return parameters starts from here */
4063 pRetPar = &PPacketIrpEvent->Data[len];
4064 pRetPar[0] = status; /* status */
4066 PPacketIrpEvent->Length = len;
4068 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4073 pBtHciInfo->bTestNeedReport = *((u8 *)pHciCmd->Data);
4074 pBtHciInfo->TestReportInterval = (*((u8 *)pHciCmd->Data+2));
4076 bthci_EventAMPReceiverReport(padapter, 0x00);
4078 /* send command complete event here when all data are received. */
4080 u8 localBuf[6] = "";
4083 struct packet_irp_hcievent_data *PPacketIrpEvent;
4085 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4087 len += bthci_CommandCompleteHeader(&localBuf[0],
4088 OGF_TESTING_COMMANDS,
4089 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4092 /* Return parameters starts from here */
4093 pRetPar = &PPacketIrpEvent->Data[len];
4094 pRetPar[0] = status; /* status */
4096 PPacketIrpEvent->Length = len;
4098 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4104 static enum hci_status
4105 bthci_CmdHostBufferSize(struct rtw_adapter *padapter,
4106 struct packet_irp_hcicmd_data *pHciCmd)
4108 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4109 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4110 struct packet_irp_hcievent_data *PPacketIrpEvent;
4111 enum hci_status status = HCI_STATUS_SUCCESS;
4112 u8 localBuf[6] = "";
4116 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].ACLPacketsData.ACLDataPacketLen = *((u16 *)pHciCmd->Data);
4117 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].SyncDataPacketLen = *((u8 *)(pHciCmd->Data+2));
4118 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalNumACLDataPackets = *((u16 *)(pHciCmd->Data+3));
4119 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalSyncNumDataPackets = *((u16 *)(pHciCmd->Data+5));
4121 /* send command complete event here when all data are received. */
4122 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4124 len += bthci_CommandCompleteHeader(&localBuf[0],
4125 OGF_SET_EVENT_MASK_COMMAND,
4126 HCI_HOST_BUFFER_SIZE,
4129 /* Return parameters starts from here */
4130 pRetPar = &PPacketIrpEvent->Data[len];
4131 pRetPar[0] = status; /* status */
4133 PPacketIrpEvent->Length = len;
4135 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4140 static enum hci_status
4141 bthci_CmdHostNumberOfCompletedPackets(struct rtw_adapter *padapter,
4142 struct packet_irp_hcicmd_data *pHciCmd)
4144 enum hci_status status = HCI_STATUS_SUCCESS;
4149 static enum hci_status
4150 bthci_UnknownCMD(struct rtw_adapter *padapter, struct packet_irp_hcicmd_data *pHciCmd)
4152 enum hci_status status = HCI_STATUS_UNKNOW_HCI_CMD;
4153 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4154 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
4156 pBtDbg->dbgHciInfo.hciCmdCntUnknown++;
4157 bthci_EventCommandStatus(padapter,
4165 static enum hci_status
4166 bthci_HandleOGFInformationalParameters(struct rtw_adapter *padapter,
4167 struct packet_irp_hcicmd_data *pHciCmd)
4169 enum hci_status status = HCI_STATUS_SUCCESS;
4171 switch (pHciCmd->OCF) {
4172 case HCI_READ_LOCAL_VERSION_INFORMATION:
4173 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_VERSION_INFORMATION\n"));
4174 status = bthci_CmdReadLocalVersionInformation(padapter);
4176 case HCI_READ_LOCAL_SUPPORTED_COMMANDS:
4177 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_COMMANDS\n"));
4178 status = bthci_CmdReadLocalSupportedCommands(padapter);
4180 case HCI_READ_LOCAL_SUPPORTED_FEATURES:
4181 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_FEATURES\n"));
4182 status = bthci_CmdReadLocalSupportedFeatures(padapter);
4184 case HCI_READ_BUFFER_SIZE:
4185 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BUFFER_SIZE\n"));
4186 status = bthci_CmdReadBufferSize(padapter);
4188 case HCI_READ_DATA_BLOCK_SIZE:
4189 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_DATA_BLOCK_SIZE\n"));
4190 status = bthci_CmdReadDataBlockSize(padapter);
4193 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFInformationalParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4194 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4195 status = bthci_UnknownCMD(padapter, pHciCmd);
4201 static enum hci_status
4202 bthci_HandleOGFSetEventMaskCMD(struct rtw_adapter *padapter,
4203 struct packet_irp_hcicmd_data *pHciCmd)
4205 enum hci_status status = HCI_STATUS_SUCCESS;
4207 switch (pHciCmd->OCF) {
4208 case HCI_SET_EVENT_MASK:
4209 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK\n"));
4210 status = bthci_CmdSetEventMask(padapter, pHciCmd);
4213 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET\n"));
4214 status = bthci_CmdReset(padapter, true);
4216 case HCI_READ_CONNECTION_ACCEPT_TIMEOUT:
4217 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_CONNECTION_ACCEPT_TIMEOUT\n"));
4218 status = bthci_CmdReadConnectionAcceptTimeout(padapter);
4220 case HCI_SET_EVENT_FILTER:
4221 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_FILTER\n"));
4222 status = bthci_CmdSetEventFilter(padapter, pHciCmd);
4224 case HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT:
4225 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT\n"));
4226 status = bthci_CmdWriteConnectionAcceptTimeout(padapter, pHciCmd);
4228 case HCI_READ_PAGE_TIMEOUT:
4229 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_PAGE_TIMEOUT\n"));
4230 status = bthci_CmdReadPageTimeout(padapter, pHciCmd);
4232 case HCI_WRITE_PAGE_TIMEOUT:
4233 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_PAGE_TIMEOUT\n"));
4234 status = bthci_CmdWritePageTimeout(padapter, pHciCmd);
4236 case HCI_HOST_NUMBER_OF_COMPLETED_PACKETS:
4237 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_NUMBER_OF_COMPLETED_PACKETS\n"));
4238 status = bthci_CmdHostNumberOfCompletedPackets(padapter, pHciCmd);
4240 case HCI_READ_LINK_SUPERVISION_TIMEOUT:
4241 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_SUPERVISION_TIMEOUT\n"));
4242 status = bthci_CmdReadLinkSupervisionTimeout(padapter, pHciCmd);
4244 case HCI_WRITE_LINK_SUPERVISION_TIMEOUT:
4245 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LINK_SUPERVISION_TIMEOUT\n"));
4246 status = bthci_CmdWriteLinkSupervisionTimeout(padapter, pHciCmd);
4248 case HCI_ENHANCED_FLUSH:
4249 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENHANCED_FLUSH\n"));
4250 status = bthci_CmdEnhancedFlush(padapter, pHciCmd);
4252 case HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT:
4253 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4254 status = bthci_CmdReadLogicalLinkAcceptTimeout(padapter, pHciCmd);
4256 case HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT:
4257 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4258 status = bthci_CmdWriteLogicalLinkAcceptTimeout(padapter, pHciCmd);
4260 case HCI_SET_EVENT_MASK_PAGE_2:
4261 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK_PAGE_2\n"));
4262 status = bthci_CmdSetEventMaskPage2(padapter, pHciCmd);
4264 case HCI_READ_LOCATION_DATA:
4265 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCATION_DATA\n"));
4266 status = bthci_CmdReadLocationData(padapter, pHciCmd);
4268 case HCI_WRITE_LOCATION_DATA:
4269 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOCATION_DATA\n"));
4270 status = bthci_CmdWriteLocationData(padapter, pHciCmd);
4272 case HCI_READ_FLOW_CONTROL_MODE:
4273 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FLOW_CONTROL_MODE\n"));
4274 status = bthci_CmdReadFlowControlMode(padapter, pHciCmd);
4276 case HCI_WRITE_FLOW_CONTROL_MODE:
4277 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_FLOW_CONTROL_MODE\n"));
4278 status = bthci_CmdWriteFlowControlMode(padapter, pHciCmd);
4280 case HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT:
4281 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4282 status = bthci_CmdReadBestEffortFlushTimeout(padapter, pHciCmd);
4284 case HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT:
4285 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4286 status = bthci_CmdWriteBestEffortFlushTimeout(padapter, pHciCmd);
4288 case HCI_SHORT_RANGE_MODE:
4289 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SHORT_RANGE_MODE\n"));
4290 status = bthci_CmdShortRangeMode(padapter, pHciCmd);
4292 case HCI_HOST_BUFFER_SIZE:
4293 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_BUFFER_SIZE\n"));
4294 status = bthci_CmdHostBufferSize(padapter, pHciCmd);
4297 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFSetEventMaskCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4298 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4299 status = bthci_UnknownCMD(padapter, pHciCmd);
4305 static enum hci_status
4306 bthci_HandleOGFStatusParameters(struct rtw_adapter *padapter,
4307 struct packet_irp_hcicmd_data *pHciCmd)
4309 enum hci_status status = HCI_STATUS_SUCCESS;
4311 switch (pHciCmd->OCF) {
4312 case HCI_READ_FAILED_CONTACT_COUNTER:
4313 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FAILED_CONTACT_COUNTER\n"));
4314 status = bthci_CmdReadFailedContactCounter(padapter, pHciCmd);
4316 case HCI_RESET_FAILED_CONTACT_COUNTER:
4317 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET_FAILED_CONTACT_COUNTER\n"));
4318 status = bthci_CmdResetFailedContactCounter(padapter, pHciCmd);
4320 case HCI_READ_LINK_QUALITY:
4321 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_QUALITY\n"));
4322 status = bthci_CmdReadLinkQuality(padapter, pHciCmd);
4325 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_RSSI\n"));
4326 status = bthci_CmdReadRSSI(padapter);
4328 case HCI_READ_LOCAL_AMP_INFO:
4329 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_INFO\n"));
4330 status = bthci_CmdReadLocalAMPInfo(padapter);
4332 case HCI_READ_LOCAL_AMP_ASSOC:
4333 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_ASSOC\n"));
4334 status = bthci_CmdReadLocalAMPAssoc(padapter, pHciCmd);
4336 case HCI_WRITE_REMOTE_AMP_ASSOC:
4337 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_REMOTE_AMP_ASSOC\n"));
4338 status = bthci_CmdWriteRemoteAMPAssoc(padapter, pHciCmd);
4341 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFStatusParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4342 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4343 status = bthci_UnknownCMD(padapter, pHciCmd);
4349 static enum hci_status
4350 bthci_HandleOGFLinkControlCMD(struct rtw_adapter *padapter,
4351 struct packet_irp_hcicmd_data *pHciCmd)
4353 enum hci_status status = HCI_STATUS_SUCCESS;
4355 switch (pHciCmd->OCF) {
4356 case HCI_CREATE_PHYSICAL_LINK:
4357 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_PHYSICAL_LINK\n"));
4358 status = bthci_CmdCreatePhysicalLink(padapter, pHciCmd);
4360 case HCI_ACCEPT_PHYSICAL_LINK:
4361 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_PHYSICAL_LINK\n"));
4362 status = bthci_CmdAcceptPhysicalLink(padapter, pHciCmd);
4364 case HCI_DISCONNECT_PHYSICAL_LINK:
4365 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK\n"));
4366 status = bthci_CmdDisconnectPhysicalLink(padapter, pHciCmd);
4368 case HCI_CREATE_LOGICAL_LINK:
4369 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_LOGICAL_LINK\n"));
4370 status = bthci_CmdCreateLogicalLink(padapter, pHciCmd);
4372 case HCI_ACCEPT_LOGICAL_LINK:
4373 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_LOGICAL_LINK\n"));
4374 status = bthci_CmdAcceptLogicalLink(padapter, pHciCmd);
4376 case HCI_DISCONNECT_LOGICAL_LINK:
4377 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_LOGICAL_LINK\n"));
4378 status = bthci_CmdDisconnectLogicalLink(padapter, pHciCmd);
4380 case HCI_LOGICAL_LINK_CANCEL:
4381 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_LOGICAL_LINK_CANCEL\n"));
4382 status = bthci_CmdLogicalLinkCancel(padapter, pHciCmd);
4384 case HCI_FLOW_SPEC_MODIFY:
4385 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_FLOW_SPEC_MODIFY\n"));
4386 status = bthci_CmdFlowSpecModify(padapter, pHciCmd);
4389 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFLinkControlCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4390 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4391 status = bthci_UnknownCMD(padapter, pHciCmd);
4397 static enum hci_status
4398 bthci_HandleOGFTestingCMD(struct rtw_adapter *padapter,
4399 struct packet_irp_hcicmd_data *pHciCmd)
4401 enum hci_status status = HCI_STATUS_SUCCESS;
4402 switch (pHciCmd->OCF) {
4403 case HCI_ENABLE_DEVICE_UNDER_TEST_MODE:
4404 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_DEVICE_UNDER_TEST_MODE\n"));
4405 bthci_CmdEnableDeviceUnderTestMode(padapter, pHciCmd);
4407 case HCI_AMP_TEST_END:
4408 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_END\n"));
4409 bthci_CmdAMPTestEnd(padapter, pHciCmd);
4411 case HCI_AMP_TEST_COMMAND:
4412 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_COMMAND\n"));
4413 bthci_CmdAMPTestCommand(padapter, pHciCmd);
4415 case HCI_ENABLE_AMP_RECEIVER_REPORTS:
4416 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_AMP_RECEIVER_REPORTS\n"));
4417 bthci_CmdEnableAMPReceiverReports(padapter, pHciCmd);
4420 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4421 status = bthci_UnknownCMD(padapter, pHciCmd);
4427 static enum hci_status
4428 bthci_HandleOGFExtension(struct rtw_adapter *padapter,
4429 struct packet_irp_hcicmd_data *pHciCmd)
4431 enum hci_status status = HCI_STATUS_SUCCESS;
4432 switch (pHciCmd->OCF) {
4433 case HCI_SET_ACL_LINK_DATA_FLOW_MODE:
4434 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_DATA_FLOW_MODE\n"));
4435 status = bthci_CmdSetACLLinkDataFlowMode(padapter, pHciCmd);
4437 case HCI_SET_ACL_LINK_STATUS:
4438 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_STATUS\n"));
4439 status = bthci_CmdSetACLLinkStatus(padapter, pHciCmd);
4441 case HCI_SET_SCO_LINK_STATUS:
4442 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_SCO_LINK_STATUS\n"));
4443 status = bthci_CmdSetSCOLinkStatus(padapter, pHciCmd);
4445 case HCI_SET_RSSI_VALUE:
4446 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("HCI_SET_RSSI_VALUE\n"));
4447 status = bthci_CmdSetRSSIValue(padapter, pHciCmd);
4449 case HCI_SET_CURRENT_BLUETOOTH_STATUS:
4450 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_CURRENT_BLUETOOTH_STATUS\n"));
4451 status = bthci_CmdSetCurrentBluetoothStatus(padapter, pHciCmd);
4453 /* The following is for RTK8723 */
4455 case HCI_EXTENSION_VERSION_NOTIFY:
4456 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_EXTENSION_VERSION_NOTIFY\n"));
4457 status = bthci_CmdExtensionVersionNotify(padapter, pHciCmd);
4459 case HCI_LINK_STATUS_NOTIFY:
4460 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_LINK_STATUS_NOTIFY\n"));
4461 status = bthci_CmdLinkStatusNotify(padapter, pHciCmd);
4463 case HCI_BT_OPERATION_NOTIFY:
4464 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_BT_OPERATION_NOTIFY\n"));
4465 status = bthci_CmdBtOperationNotify(padapter, pHciCmd);
4467 case HCI_ENABLE_WIFI_SCAN_NOTIFY:
4468 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_ENABLE_WIFI_SCAN_NOTIFY\n"));
4469 status = bthci_CmdEnableWifiScanNotify(padapter, pHciCmd);
4472 /* The following is for IVT */
4473 case HCI_WIFI_CURRENT_CHANNEL:
4474 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_CHANNEL\n"));
4475 status = bthci_CmdWIFICurrentChannel(padapter, pHciCmd);
4477 case HCI_WIFI_CURRENT_BANDWIDTH:
4478 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_BANDWIDTH\n"));
4479 status = bthci_CmdWIFICurrentBandwidth(padapter, pHciCmd);
4481 case HCI_WIFI_CONNECTION_STATUS:
4482 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CONNECTION_STATUS\n"));
4483 status = bthci_CmdWIFIConnectionStatus(padapter, pHciCmd);
4487 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_UNKNOWN_COMMAND\n"));
4488 status = bthci_UnknownCMD(padapter, pHciCmd);
4495 bthci_StateStarting(struct rtw_adapter *padapter,
4496 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4498 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4499 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4501 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Starting], "));
4503 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4504 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4505 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4506 pBtMgnt->bNeedNotifyAMPNoCap = true;
4507 BTHCI_DisconnectPeer(padapter, EntryNum);
4509 case STATE_CMD_DISCONNECT_PHY_LINK:
4510 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4512 bthci_EventDisconnectPhyLinkComplete(padapter,
4514 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4517 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4519 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4521 BTHCI_DisconnectPeer(padapter, EntryNum);
4523 case STATE_CMD_MAC_START_COMPLETE:
4524 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_START_COMPLETE\n"));
4525 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR)
4526 bthci_EventChannelSelected(padapter, EntryNum);
4529 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4535 bthci_StateConnecting(struct rtw_adapter *padapter,
4536 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4538 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4539 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4541 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connecting], "));
4543 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4544 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4545 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4546 pBtMgnt->bNeedNotifyAMPNoCap = true;
4547 BTHCI_DisconnectPeer(padapter, EntryNum);
4549 case STATE_CMD_MAC_CONNECT_COMPLETE:
4550 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_COMPLETE\n"));
4552 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_JOINER) {
4553 RT_TRACE(_module_rtl871x_security_c_,
4554 _drv_info_, ("StateConnecting \n"));
4557 case STATE_CMD_DISCONNECT_PHY_LINK:
4558 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4560 bthci_EventDisconnectPhyLinkComplete(padapter,
4562 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4565 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4567 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4569 BTHCI_DisconnectPeer(padapter, EntryNum);
4572 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4573 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4574 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONTROLLER_BUSY;
4575 /* Because this state cmd is caused by the BTHCI_EventAMPStatusChange(), */
4576 /* we don't need to send event in the following BTHCI_DisconnectPeer() again. */
4577 pBtMgnt->bNeedNotifyAMPNoCap = false;
4578 BTHCI_DisconnectPeer(padapter, EntryNum);
4581 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4587 bthci_StateConnected(struct rtw_adapter *padapter,
4588 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4590 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4591 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4592 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4594 u16 logicHandle = 0;
4596 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connected], "));
4598 case STATE_CMD_DISCONNECT_PHY_LINK:
4599 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4601 /* When we are trying to disconnect the phy link, we should disconnect log link first, */
4602 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
4603 if (pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle != 0) {
4604 logicHandle = pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle;
4606 bthci_EventDisconnectLogicalLinkComplete(padapter, HCI_STATUS_SUCCESS,
4607 logicHandle, pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason);
4609 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle = 0;
4613 bthci_EventDisconnectPhyLinkComplete(padapter,
4615 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4618 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4620 BTHCI_DisconnectPeer(padapter, EntryNum);
4623 case STATE_CMD_MAC_DISCONNECT_INDICATE:
4624 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_DISCONNECT_INDICATE\n"));
4626 bthci_EventDisconnectPhyLinkComplete(padapter,
4628 /* TODO: Remote Host not local host */
4629 HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST,
4631 BTHCI_DisconnectPeer(padapter, EntryNum);
4634 case STATE_CMD_ENTER_STATE:
4635 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4637 if (pBtMgnt->bBTConnectInProgress) {
4638 pBtMgnt->bBTConnectInProgress = false;
4639 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4641 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_CONNECTED;
4642 pBTInfo->BtAsocEntry[EntryNum].b4waySuccess = true;
4643 pBtMgnt->bStartSendSupervisionPkt = true;
4645 /* for rate adaptive */
4647 rtl8723a_update_ramask(padapter,
4648 MAX_FW_SUPPORT_MACID_NUM-1-EntryNum, 0);
4650 HalSetBrateCfg23a(padapter, padapter->mlmepriv.cur_network.network.SupportedRates);
4651 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
4654 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4660 bthci_StateAuth(struct rtw_adapter *padapter, enum hci_state_with_cmd StateCmd,
4663 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4664 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4666 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Authenticating], "));
4668 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4669 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4670 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4671 pBtMgnt->bNeedNotifyAMPNoCap = true;
4672 BTHCI_DisconnectPeer(padapter, EntryNum);
4674 case STATE_CMD_DISCONNECT_PHY_LINK:
4675 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4676 bthci_EventDisconnectPhyLinkComplete(padapter,
4678 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4681 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4683 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4685 BTHCI_DisconnectPeer(padapter, EntryNum);
4687 case STATE_CMD_4WAY_FAILED:
4688 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_FAILED\n"));
4690 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_AUTH_FAIL;
4691 pBtMgnt->bNeedNotifyAMPNoCap = true;
4693 BTHCI_DisconnectPeer(padapter, EntryNum);
4695 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4697 case STATE_CMD_4WAY_SUCCESSED:
4698 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_SUCCESSED\n"));
4700 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_SUCCESS, EntryNum, INVALID_PL_HANDLE);
4702 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4704 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4707 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4713 bthci_StateDisconnecting(struct rtw_adapter *padapter,
4714 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4716 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4717 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4719 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnecting], "));
4721 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4722 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4723 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4724 bthci_EventPhysicalLinkComplete(padapter,
4725 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus,
4726 EntryNum, INVALID_PL_HANDLE);
4729 if (pBtMgnt->bBTConnectInProgress) {
4730 pBtMgnt->bBTConnectInProgress = false;
4731 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4734 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4736 case STATE_CMD_DISCONNECT_PHY_LINK:
4737 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4739 bthci_EventDisconnectPhyLinkComplete(padapter,
4741 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4744 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4746 BTHCI_DisconnectPeer(padapter, EntryNum);
4749 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4755 bthci_StateDisconnected(struct rtw_adapter *padapter,
4756 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4758 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4759 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4760 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4761 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4763 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnected], "));
4765 case STATE_CMD_CREATE_PHY_LINK:
4766 case STATE_CMD_ACCEPT_PHY_LINK:
4767 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4768 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CREATE_PHY_LINK\n"));
4770 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ACCEPT_PHY_LINK\n"));
4772 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], Disable IPS and LPS\n"));
4773 ips_leave23a(padapter);
4774 LPS_Leave23a(padapter);
4776 pBtMgnt->bPhyLinkInProgress = true;
4777 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
4778 pBtMgnt->CurrentBTConnectionCnt++;
4779 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d\n",
4780 pBtMgnt->CurrentBTConnectionCnt));
4781 pBtMgnt->BtOperationOn = true;
4782 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation ON!! CurrentConnectEntryNum = %d\n",
4783 pBtMgnt->CurrentConnectEntryNum));
4785 if (pBtMgnt->bBTConnectInProgress) {
4786 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONTROLLER_BUSY, INVALID_ENTRY_NUM, pBtMgnt->BtCurrentPhyLinkhandle);
4787 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4791 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4792 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_CREATOR;
4794 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_JOINER;
4796 /* 1. MAC not yet in selected channel */
4797 while (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)) {
4798 RTPRINT(FIOCTL, IOCTL_STATE, ("Scan/Roaming/Wifi Link is in Progress, wait 200 ms\n"));
4801 /* 2. MAC already in selected channel */
4802 RTPRINT(FIOCTL, IOCTL_STATE, ("Channel is Ready\n"));
4803 mod_timer(&pBTInfo->BTHCIJoinTimeoutTimer,
4804 jiffies + msecs_to_jiffies(pBtHciInfo->ConnAcceptTimeout));
4806 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = true;
4808 case STATE_CMD_DISCONNECT_PHY_LINK:
4809 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4811 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4813 bthci_EventDisconnectPhyLinkComplete(padapter,
4815 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4818 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4819 bthci_EventPhysicalLinkComplete(padapter,
4820 HCI_STATUS_UNKNOW_CONNECT_ID,
4821 EntryNum, INVALID_PL_HANDLE);
4824 if (pBtMgnt->bBTConnectInProgress) {
4825 pBtMgnt->bBTConnectInProgress = false;
4826 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4828 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4829 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4831 case STATE_CMD_ENTER_STATE:
4832 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4835 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4840 void BTHCI_EventParse(struct rtw_adapter *padapter, void *pEvntData, u32 dataLen)
4844 u8 BTHCI_HsConnectionEstablished(struct rtw_adapter *padapter)
4846 u8 bBtConnectionExist = false;
4847 struct bt_30info *pBtinfo = GET_BT_INFO(padapter);
4850 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
4851 if (pBtinfo->BtAsocEntry[i].b4waySuccess) {
4852 bBtConnectionExist = true;
4857 /*RTPRINT(FIOCTL, IOCTL_STATE, (" BTHCI_HsConnectionEstablished(), connection exist = %d\n", bBtConnectionExist)); */
4859 return bBtConnectionExist;
4863 BTHCI_CheckProfileExist(struct rtw_adapter *padapter,
4864 enum bt_traffic_mode_profile Profile)
4866 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4867 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4868 u8 IsPRofile = false;
4871 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4872 if (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile == Profile) {
4881 void BTHCI_UpdateBTProfileRTKToMoto(struct rtw_adapter *padapter)
4883 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4884 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4887 pBtMgnt->ExtConfig.NumberOfSCO = 0;
4889 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4890 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
4892 if (pBtMgnt->ExtConfig.linkInfo[i].BTProfile == BT_PROFILE_SCO)
4893 pBtMgnt->ExtConfig.NumberOfSCO++;
4895 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = pBtMgnt->ExtConfig.linkInfo[i].BTProfile;
4896 switch (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile) {
4897 case BT_PROFILE_SCO:
4899 case BT_PROFILE_PAN:
4900 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_BE;
4901 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4903 case BT_PROFILE_A2DP:
4904 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GULB;
4905 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_GULB;
4907 case BT_PROFILE_HID:
4908 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GUL;
4909 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4916 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RTK, NumberOfHandle = %d, NumberOfSCO = %d\n",
4917 pBtMgnt->ExtConfig.NumberOfHandle, pBtMgnt->ExtConfig.NumberOfSCO));
4920 void BTHCI_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
4922 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4923 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4925 if (pBtMgnt->ExtConfig.bEnableWifiScanNotify)
4926 bthci_EventExtWifiScanNotify(padapter, scanType);
4931 struct rtw_adapter *padapter,
4933 enum hci_state_with_cmd StateCmd,
4937 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4938 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4940 if (EntryNum == 0xff) {
4941 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, error EntryNum = 0x%x \n", EntryNum));
4944 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, EntryNum = 0x%x, CurrentState = 0x%x, BtNextState = 0x%x, StateCmd = 0x%x , StateToEnter = 0x%x\n",
4945 EntryNum, pBTInfo->BtAsocEntry[EntryNum].BtCurrentState, pBTInfo->BtAsocEntry[EntryNum].BtNextState, StateCmd, StateToEnter));
4947 if (pBTInfo->BtAsocEntry[EntryNum].BtNextState & StateToEnter) {
4948 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = StateToEnter;
4950 switch (StateToEnter) {
4951 case HCI_STATE_STARTING:
4952 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTING;
4953 bthci_StateStarting(padapter, StateCmd, EntryNum);
4955 case HCI_STATE_CONNECTING:
4956 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTING | HCI_STATE_DISCONNECTING | HCI_STATE_AUTHENTICATING;
4957 bthci_StateConnecting(padapter, StateCmd, EntryNum);
4959 case HCI_STATE_AUTHENTICATING:
4960 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTED;
4961 bthci_StateAuth(padapter, StateCmd, EntryNum);
4963 case HCI_STATE_CONNECTED:
4964 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTED | HCI_STATE_DISCONNECTING;
4965 bthci_StateConnected(padapter, StateCmd, EntryNum);
4967 case HCI_STATE_DISCONNECTING:
4968 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_DISCONNECTING;
4969 bthci_StateDisconnecting(padapter, StateCmd, EntryNum);
4971 case HCI_STATE_DISCONNECTED:
4972 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_STARTING | HCI_STATE_CONNECTING;
4973 bthci_StateDisconnected(padapter, StateCmd, EntryNum);
4976 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Unknown state to enter!!!\n"));
4980 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Wrong state to enter\n"));
4983 /* 20100325 Joseph: Disable/Enable IPS/LPS according to BT status. */
4984 if (!pBtMgnt->bBTConnectInProgress && !pBtMgnt->BtOperationOn) {
4985 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], ips_enter23a()\n"));
4986 ips_enter23a(padapter);
4990 void BTHCI_DisconnectPeer(struct rtw_adapter *padapter, u8 EntryNum)
4992 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4993 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4995 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" BTHCI_DisconnectPeer()\n"));
4997 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, EntryNum);
4999 if (pBTInfo->BtAsocEntry[EntryNum].bUsed) {
5000 /*BTPKT_SendDeauthentication(padapter, pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, unspec_reason); not porting yet */
5003 if (pBtMgnt->bBTConnectInProgress) {
5004 pBtMgnt->bBTConnectInProgress = false;
5005 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
5008 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
5010 if (pBtMgnt->bNeedNotifyAMPNoCap) {
5011 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT AMPStatus], set to invalid in BTHCI_DisconnectPeer()\n"));
5012 BTHCI_EventAMPStatusChange(padapter, AMP_STATUS_NO_CAPACITY_FOR_BT);
5016 void BTHCI_EventNumOfCompletedDataBlocks(struct rtw_adapter *padapter)
5018 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
5019 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5020 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
5021 u8 localBuf[TmpLocalBufSize] = "";
5022 u8 *pRetPar, *pTriple;
5023 u8 len = 0, i, j, handleNum = 0;
5024 struct packet_irp_hcievent_data *PPacketIrpEvent;
5025 u16 *pu2Temp, *pPackets, *pHandle, *pDblocks;
5028 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5030 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS)) {
5031 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Num Of Completed DataBlocks, Ignore to send NumOfCompletedDataBlocksEvent due to event mask page 2\n"));
5035 /* Return parameters starts from here */
5036 pRetPar = &PPacketIrpEvent->Data[0];
5037 pTriple = &pRetPar[3];
5038 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
5040 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
5041 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle) {
5043 pHandle = (u16 *)&pTriple[0]; /* Handle[i] */
5044 pPackets = (u16 *)&pTriple[2]; /* Num_Of_Completed_Packets[i] */
5045 pDblocks = (u16 *)&pTriple[4]; /* Num_Of_Completed_Blocks[i] */
5046 *pHandle = pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle;
5047 *pPackets = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5048 *pDblocks = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5049 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount) {
5051 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL,
5052 ("[BT event], Num Of Completed DataBlocks, Handle = 0x%x, Num_Of_Completed_Packets = 0x%x, Num_Of_Completed_Blocks = 0x%x\n",
5053 *pHandle, *pPackets, *pDblocks));
5055 pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount = 0;
5062 pRetPar[2] = handleNum; /* Number_of_Handles */
5064 pu2Temp = (u16 *)&pRetPar[0];
5065 *pu2Temp = BTTotalDataBlockNum;
5068 PPacketIrpEvent->EventCode = HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS;
5069 PPacketIrpEvent->Length = len;
5070 if (handleNum && sent)
5071 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
5074 void BTHCI_EventAMPStatusChange(struct rtw_adapter *padapter, u8 AMP_Status)
5076 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5077 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
5078 struct packet_irp_hcievent_data *PPacketIrpEvent;
5080 u8 localBuf[7] = "";
5083 if (AMP_Status == AMP_STATUS_NO_CAPACITY_FOR_BT) {
5084 pBtMgnt->BTNeedAMPStatusChg = true;
5085 pBtMgnt->bNeedNotifyAMPNoCap = false;
5087 BTHCI_DisconnectAll(padapter);
5088 } else if (AMP_Status == AMP_STATUS_FULL_CAPACITY_FOR_BT) {
5089 pBtMgnt->BTNeedAMPStatusChg = false;
5092 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5093 /* Return parameters starts from here */
5094 pRetPar = &PPacketIrpEvent->Data[0];
5096 pRetPar[0] = 0; /* Status */
5098 pRetPar[1] = AMP_Status; /* AMP_Status */
5101 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_STATUS_CHANGE;
5102 PPacketIrpEvent->Length = len;
5103 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS)
5104 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_STATE), ("[BT event], AMP Status Change, AMP_Status = %d\n", AMP_Status));
5107 void BTHCI_DisconnectAll(struct rtw_adapter *padapter)
5109 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5112 RTPRINT(FIOCTL, IOCTL_STATE, (" DisconnectALL()\n"));
5114 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
5115 if (pBTInfo->BtAsocEntry[i].b4waySuccess) {
5116 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, i);
5117 } else if (pBTInfo->BtAsocEntry[i].bUsed) {
5118 if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_CONNECTING) {
5119 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5120 } else if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_DISCONNECTING) {
5121 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5129 struct rtw_adapter *padapter,
5130 struct packet_irp_hcicmd_data *pHciCmd
5133 enum hci_status status = HCI_STATUS_SUCCESS;
5134 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5135 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
5137 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("\n"));
5138 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI Command start, OGF = 0x%x, OCF = 0x%x, Length = 0x%x\n",
5139 pHciCmd->OGF, pHciCmd->OCF, pHciCmd->Length));
5140 if (pHciCmd->Length) {
5141 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "HCI Command, Hex Data :\n",
5142 &pHciCmd->Data[0], pHciCmd->Length);
5144 if (pHciCmd->OGF == OGF_EXTENSION) {
5145 if (pHciCmd->OCF == HCI_SET_RSSI_VALUE)
5146 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("[BT cmd], "));
5148 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[BT cmd], "));
5150 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("[BT cmd], "));
5153 pBtDbg->dbgHciInfo.hciCmdCnt++;
5155 switch (pHciCmd->OGF) {
5156 case LINK_CONTROL_COMMANDS:
5157 status = bthci_HandleOGFLinkControlCMD(padapter, pHciCmd);
5159 case HOLD_MODE_COMMAND:
5161 case OGF_SET_EVENT_MASK_COMMAND:
5162 status = bthci_HandleOGFSetEventMaskCMD(padapter, pHciCmd);
5164 case OGF_INFORMATIONAL_PARAMETERS:
5165 status = bthci_HandleOGFInformationalParameters(padapter, pHciCmd);
5167 case OGF_STATUS_PARAMETERS:
5168 status = bthci_HandleOGFStatusParameters(padapter, pHciCmd);
5170 case OGF_TESTING_COMMANDS:
5171 status = bthci_HandleOGFTestingCMD(padapter, pHciCmd);
5174 status = bthci_HandleOGFExtension(padapter, pHciCmd);
5177 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI Command(), Unknown OGF = 0x%x\n", pHciCmd->OGF));
5178 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
5179 status = bthci_UnknownCMD(padapter, pHciCmd);
5182 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("HCI Command execution end!!\n"));
5187 /* ===== End of sync from SD7 driver COMMOM/bt_hci.c ===== */
5189 static const char *const BtStateString[] = {
5197 "BT_ACL_INQ_OR_PAG",
5198 "BT_STATE_NOT_DEFINED"
5201 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
5203 static void btdm_SetFwIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
5205 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5206 u8 H2C_Parameter[1] = {0};
5209 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Ignore Wlan_Act !!\n"));
5210 H2C_Parameter[0] |= BIT(0); /* function enable */
5211 pHalData->bt_coexist.bFWCoexistAllOff = false;
5213 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT don't ignore Wlan_Act !!\n"));
5216 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, write 0x25 = 0x%02x\n",
5219 FillH2CCmd(padapter, BT_IGNORE_WLAN_ACT_EID, 1, H2C_Parameter);
5222 static void btdm_NotifyFwScan(struct rtw_adapter *padapter, u8 scanType)
5224 u8 H2C_Parameter[1] = {0};
5226 if (scanType == true)
5227 H2C_Parameter[0] = 0x1;
5229 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Notify FW for wifi scan, write 0x3b = 0x%02x\n",
5232 FillH2CCmd(padapter, 0x3b, 1, H2C_Parameter);
5235 static void btdm_1AntSetPSMode(struct rtw_adapter *padapter,
5236 u8 enable, u8 smartps, u8 mode)
5238 struct pwrctrl_priv *pwrctrl;
5240 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current LPS(%s, %d), smartps =%d\n", enable == true?"ON":"OFF", mode, smartps));
5242 pwrctrl = &padapter->pwrctrlpriv;
5244 if (enable == true) {
5245 rtw_set_ps_mode23a(padapter, PS_MODE_MIN, smartps, mode);
5247 rtw_set_ps_mode23a(padapter, PS_MODE_ACTIVE, 0, 0);
5248 LPS_RF_ON_check23a(padapter, 100);
5252 static void btdm_1AntTSFSwitch(struct rtw_adapter *padapter, u8 enable)
5256 oldVal = rtl8723au_read8(padapter, 0x550);
5259 newVal = oldVal | EN_BCN_FUNCTION;
5261 newVal = oldVal & ~EN_BCN_FUNCTION;
5263 if (oldVal != newVal)
5264 rtl8723au_write8(padapter, 0x550, newVal);
5267 static u8 btdm_Is1AntPsTdmaStateChange(struct rtw_adapter *padapter)
5269 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5270 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5272 if ((pBtdm8723->bPrePsTdmaOn != pBtdm8723->bCurPsTdmaOn) ||
5273 (pBtdm8723->prePsTdma != pBtdm8723->curPsTdma))
5279 /* Before enter TDMA, make sure Power Saving is enable! */
5282 struct rtw_adapter *padapter,
5287 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5288 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5290 pBtdm8723->bCurPsTdmaOn = bTurnOn;
5291 pBtdm8723->curPsTdma = type;
5294 case 1: /* A2DP Level-1 or FTP/OPP */
5296 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5297 /* wide duration for WiFi */
5298 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x0, 0x58);
5301 case 2: /* A2DP Level-2 */
5302 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5303 /* normal duration for WiFi */
5304 BTDM_SetFw3a(padapter, 0xd3, 0x12, 0x12, 0x0, 0x58);
5307 case 3: /* BT FTP/OPP */
5308 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5309 /* normal duration for WiFi */
5310 BTDM_SetFw3a(padapter, 0xd3, 0x30, 0x03, 0x10, 0x58);
5314 case 4: /* for wifi scan & BT is connected */
5315 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5316 /* protect 3 beacons in 3-beacon period & no Tx pause at BT slot */
5317 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x0);
5320 case 5: /* for WiFi connected-busy & BT is Non-Connected-Idle */
5321 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5322 /* SCO mode, Ant fixed at WiFi, WLAN_Act toggle */
5323 BTDM_SetFw3a(padapter, 0x61, 0x15, 0x03, 0x31, 0x00);
5326 case 9: /* ACL high-retry type - 2 */
5327 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5328 /* narrow duration for WiFi */
5329 BTDM_SetFw3a(padapter, 0xd3, 0xa, 0xa, 0x0, 0x58); /* narrow duration for WiFi */
5332 case 10: /* for WiFi connect idle & BT ACL busy or WiFi Connected-Busy & BT is Inquiry */
5333 if (btdm_Is1AntPsTdmaStateChange(padapter))
5334 BTDM_SetFw3a(padapter, 0x13, 0xa, 0xa, 0x0, 0x40);
5336 case 11: /* ACL high-retry type - 3 */
5337 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5338 /* narrow duration for WiFi */
5339 BTDM_SetFw3a(padapter, 0xd3, 0x05, 0x05, 0x00, 0x58);
5342 case 12: /* for WiFi Connected-Busy & BT is Connected-Idle */
5343 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5344 /* Allow High-Pri BT */
5345 BTDM_SetFw3a(padapter, 0xeb, 0x0a, 0x03, 0x31, 0x18);
5348 case 20: /* WiFi only busy , TDMA mode for power saving */
5349 if (btdm_Is1AntPsTdmaStateChange(padapter))
5350 BTDM_SetFw3a(padapter, 0x13, 0x25, 0x25, 0x00, 0x00);
5352 case 27: /* WiFi DHCP/Site Survey & BT SCO busy */
5353 if (btdm_Is1AntPsTdmaStateChange(padapter))
5354 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x31, 0x98);
5356 case 28: /* WiFi DHCP/Site Survey & BT idle */
5357 if (btdm_Is1AntPsTdmaStateChange(padapter))
5358 BTDM_SetFw3a(padapter, 0x69, 0x25, 0x03, 0x31, 0x00);
5360 case 29: /* WiFi DHCP/Site Survey & BT ACL busy */
5361 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5362 BTDM_SetFw3a(padapter, 0xeb, 0x1a, 0x1a, 0x01, 0x18);
5363 rtl8723au_write32(padapter, 0x6c0, 0x5afa5afa);
5364 rtl8723au_write32(padapter, 0x6c4, 0x5afa5afa);
5367 case 30: /* WiFi idle & BT Inquiry */
5368 if (btdm_Is1AntPsTdmaStateChange(padapter))
5369 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x00);
5371 case 31: /* BT HID */
5372 if (btdm_Is1AntPsTdmaStateChange(padapter))
5373 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x58);
5375 case 32: /* BT SCO & Inquiry */
5376 if (btdm_Is1AntPsTdmaStateChange(padapter))
5377 BTDM_SetFw3a(padapter, 0xab, 0x0a, 0x03, 0x11, 0x98);
5379 case 33: /* BT SCO & WiFi site survey */
5380 if (btdm_Is1AntPsTdmaStateChange(padapter))
5381 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x30, 0x98);
5383 case 34: /* BT HID & WiFi site survey */
5384 if (btdm_Is1AntPsTdmaStateChange(padapter))
5385 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x18);
5387 case 35: /* BT HID & WiFi Connecting */
5388 if (btdm_Is1AntPsTdmaStateChange(padapter))
5389 BTDM_SetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x00, 0x18);
5393 /* disable PS-TDMA */
5396 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5397 /* Antenna control by PTA, 0x870 = 0x310 */
5398 BTDM_SetFw3a(padapter, 0x8, 0x0, 0x0, 0x0, 0x0);
5403 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5404 /* Antenna control by PTA, 0x870 = 0x310 */
5405 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5407 /* Switch Antenna to BT */
5408 rtl8723au_write16(padapter, 0x860, 0x210);
5409 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x210, Switch Antenna to BT\n"));
5412 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5413 /* Antenna control by PTA, 0x870 = 0x310 */
5414 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5416 /* Switch Antenna to WiFi */
5417 rtl8723au_write16(padapter, 0x860, 0x110);
5418 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x110, Switch Antenna to WiFi\n"));
5423 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current TDMA(%s, %d)\n",
5424 pBtdm8723->bCurPsTdmaOn?"ON":"OFF", pBtdm8723->curPsTdma));
5426 /* update pre state */
5427 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
5428 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
5432 _btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn, u8 smartps,
5433 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5435 struct pwrctrl_priv *pwrctrl;
5436 struct hal_data_8723a *pHalData;
5437 struct btdm_8723a_1ant *pBtdm8723;
5441 if (!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) &&
5442 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
5443 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5446 psOption &= ~BIT(0);
5448 RTPRINT(FBT, BT_TRACE,
5449 ("[BTCoex], Set LPS(%s, %d) TDMA(%s, %d)\n",
5450 bPSEn == true?"ON":"OFF", psOption,
5451 bTDMAOn == true?"ON":"OFF", tdmaType));
5453 pwrctrl = &padapter->pwrctrlpriv;
5454 pHalData = GET_HAL_DATA(padapter);
5455 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5458 if (pBtdm8723->bWiFiHalt) {
5459 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Halt!!\n"));
5463 if (pwrctrl->bInSuspend) {
5464 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Suspend!!\n"));
5468 if (padapter->bDriverStopped) {
5469 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi driver stopped!!\n"));
5473 if (padapter->bSurpriseRemoved) {
5474 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi Surprise Removed!!\n"));
5478 psMode = PS_MODE_MIN;
5480 psMode = PS_MODE_ACTIVE;
5484 if (psMode != pwrctrl->pwr_mode) {
5486 } else if (psMode != PS_MODE_ACTIVE) {
5487 if (psOption != pwrctrl->bcn_ant_mode)
5489 else if (smartps != pwrctrl->smart_ps)
5499 if (pBtdm8723->bCurPsTdmaOn) {
5501 btdm_1AntPsTdma(padapter, false, tdmaType);
5503 if (!rtl8723a_BT_enabled(padapter) ||
5504 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_NO_CONNECTION) ||
5505 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_CONNECT_IDLE) ||
5507 btdm_1AntPsTdma(padapter, false, 9);
5509 btdm_1AntPsTdma(padapter, false, 0);
5513 /* change Power Save State */
5514 btdm_1AntSetPSMode(padapter, bPSEn, smartps, psOption);
5517 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5521 btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn,
5522 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5524 _btdm_1AntSetPSTDMA(padapter, bPSEn, 0, psOption, bTDMAOn, tdmaType);
5527 static void btdm_1AntWifiParaAdjust(struct rtw_adapter *padapter, u8 bEnable)
5529 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5530 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5533 pBtdm8723->curWifiPara = 1;
5534 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5535 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_LOW_PENALTY);
5537 pBtdm8723->curWifiPara = 2;
5538 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5539 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_NORMAL);
5544 static void btdm_1AntPtaParaReload(struct rtw_adapter *padapter)
5547 rtl8723au_write8(padapter, 0x6cc, 0x0); /* 1-Ant coex */
5548 rtl8723au_write32(padapter, 0x6c8, 0xffff); /* wifi break table */
5549 rtl8723au_write32(padapter, 0x6c4, 0x55555555); /* coex table */
5551 /* Antenna switch control parameter */
5552 rtl8723au_write32(padapter, 0x858, 0xaaaaaaaa);
5553 if (IS_8723A_A_CUT(GET_HAL_DATA(padapter)->VersionID)) {
5554 /* SPDT(connected with TRSW) control by hardware PTA */
5555 rtl8723au_write32(padapter, 0x870, 0x0);
5556 rtl8723au_write8(padapter, 0x40, 0x24);
5558 rtl8723au_write8(padapter, 0x40, 0x20);
5559 /* set antenna at bt side if ANTSW is software control */
5560 rtl8723au_write16(padapter, 0x860, 0x210);
5561 /* SPDT(connected with TRSW) control by hardware PTA */
5562 rtl8723au_write32(padapter, 0x870, 0x300);
5563 /* ANTSW keep by GNT_BT */
5564 rtl8723au_write32(padapter, 0x874, 0x22804000);
5567 /* coexistence parameters */
5568 rtl8723au_write8(padapter, 0x778, 0x1); /* enable RTK mode PTA */
5570 /* BT don't ignore WLAN_Act */
5571 btdm_SetFwIgnoreWlanAct(padapter, false);
5576 *1: upgrade (add WiFi duration time)
5578 *-1: downgrade (add BT duration time)
5580 static s8 btdm_1AntTdmaJudgement(struct rtw_adapter *padapter, u8 retry)
5582 struct hal_data_8723a *pHalData;
5583 struct btdm_8723a_1ant *pBtdm8723;
5584 static s8 up, dn, m = 1, n = 3, WaitCount;
5587 pHalData = GET_HAL_DATA(padapter);
5588 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5591 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5602 /* no retry in the last 2-second duration */
5608 /* retry = 0 in consecutive 3m*(2s), add WiFi duration */
5616 } else if (retry <= 3) {
5617 /* retry<= 3 in the last 2-second duration */
5624 /* retry<= 3 in consecutive 2*(2s), minus WiFi duration (add BT duration) */
5627 /* record how many time downgrad WiFi duration */
5632 /* the max number of m is 20 */
5633 /* the longest time of upgrade WiFi duration is 20*3*2s = 120s */
5641 /* retry count > 3 */
5642 /* retry>3, minus WiFi duration (add BT duration) */
5645 /* record how many time downgrad WiFi duration */
5660 static void btdm_1AntTdmaDurationAdjustForACL(struct rtw_adapter *padapter)
5662 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5663 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5665 if (pBtdm8723->psTdmaGlobalCnt != pBtdm8723->psTdmaMonitorCnt) {
5666 pBtdm8723->psTdmaMonitorCnt = 0;
5667 pBtdm8723->psTdmaGlobalCnt = 0;
5669 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5670 btdm_1AntSetPSTDMA(padapter, true, 0, true, 2);
5671 pBtdm8723->psTdmaDuAdjType = 2;
5673 /* Now we only have 4 level Ps Tdma, */
5674 /* if that's not the following 4 level(will changed by wifi scan, dhcp...), */
5675 /* then we have to adjust it back to the previous record one. */
5676 if ((pBtdm8723->curPsTdma != 1) &&
5677 (pBtdm8723->curPsTdma != 2) &&
5678 (pBtdm8723->curPsTdma != 9) &&
5679 (pBtdm8723->curPsTdma != 11)) {
5680 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5684 judge = btdm_1AntTdmaJudgement(padapter, pHalData->bt_coexist.halCoex8723.btRetryCnt);
5686 if (pBtdm8723->curPsTdma == 1) {
5687 /* Decrease WiFi duration for high BT retry */
5688 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5689 pBtdm8723->psTdmaDuAdjType = 9;
5691 pBtdm8723->psTdmaDuAdjType = 2;
5692 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5693 } else if (pBtdm8723->curPsTdma == 2) {
5694 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5695 pBtdm8723->psTdmaDuAdjType = 9;
5696 } else if (pBtdm8723->curPsTdma == 9) {
5697 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5698 pBtdm8723->psTdmaDuAdjType = 11;
5700 } else if (judge == 1) {
5701 if (pBtdm8723->curPsTdma == 11) {
5702 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5703 pBtdm8723->psTdmaDuAdjType = 9;
5704 } else if (pBtdm8723->curPsTdma == 9) {
5705 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5706 pBtdm8723->psTdmaDuAdjType = 9;
5708 pBtdm8723->psTdmaDuAdjType = 2;
5709 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5710 } else if (pBtdm8723->curPsTdma == 2) {
5711 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5712 pBtdm8723->psTdmaDuAdjType = 9;
5714 pBtdm8723->psTdmaDuAdjType = 1;
5715 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5719 RTPRINT(FBT, BT_TRACE,
5720 ("[BTCoex], ACL current TDMA(%s, %d)\n",
5721 (pBtdm8723->bCurPsTdmaOn ? "ON" : "OFF"), pBtdm8723->curPsTdma));
5723 pBtdm8723->psTdmaMonitorCnt++;
5726 static void btdm_1AntCoexProcessForWifiConnect(struct rtw_adapter *padapter)
5728 struct mlme_priv *pmlmepriv;
5729 struct hal_data_8723a *pHalData;
5730 struct bt_coexist_8723a *pBtCoex;
5731 struct btdm_8723a_1ant *pBtdm8723;
5734 pmlmepriv = &padapter->mlmepriv;
5735 pHalData = GET_HAL_DATA(padapter);
5736 pBtCoex = &pHalData->bt_coexist.halCoex8723;
5737 pBtdm8723 = &pBtCoex->btdm1Ant;
5738 BtState = pBtCoex->c2hBtInfo;
5740 RTPRINT(FBT, BT_TRACE, ("[BTCoex], WiFi is %s\n",
5741 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
5742 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is %s\n",
5743 BtStateString[BtState]));
5745 padapter->pwrctrlpriv.btcoex_rfon = false;
5747 if (!BTDM_IsWifiBusy(padapter) &&
5748 !check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) &&
5749 (BtState == BT_INFO_STATE_NO_CONNECTION ||
5750 BtState == BT_INFO_STATE_CONNECT_IDLE)) {
5752 case BT_INFO_STATE_NO_CONNECTION:
5753 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 9);
5755 case BT_INFO_STATE_CONNECT_IDLE:
5756 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 0);
5761 case BT_INFO_STATE_NO_CONNECTION:
5762 case BT_INFO_STATE_CONNECT_IDLE:
5764 btdm_1AntSetPSTDMA(padapter, false, 0, true, 5);
5765 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5766 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5768 case BT_INFO_STATE_ACL_INQ_OR_PAG:
5769 RTPRINT(FBT, BT_TRACE,
5770 ("[BTCoex], BT PROFILE is "
5771 "BT_INFO_STATE_ACL_INQ_OR_PAG\n"));
5772 case BT_INFO_STATE_INQ_OR_PAG:
5773 padapter->pwrctrlpriv.btcoex_rfon = true;
5774 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
5776 case BT_INFO_STATE_SCO_ONLY_BUSY:
5777 case BT_INFO_STATE_ACL_SCO_BUSY:
5778 if (true == pBtCoex->bC2hBtInquiryPage)
5779 btdm_1AntSetPSTDMA(padapter, false, 0,
5782 #ifdef BTCOEX_CMCC_TEST
5783 btdm_1AntSetPSTDMA(padapter, false, 0,
5785 #else /* !BTCOEX_CMCC_TEST */
5786 btdm_1AntSetPSTDMA(padapter, false, 0,
5788 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5789 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5790 #endif /* !BTCOEX_CMCC_TEST */
5793 case BT_INFO_STATE_ACL_ONLY_BUSY:
5794 padapter->pwrctrlpriv.btcoex_rfon = true;
5795 if (pBtCoex->c2hBtProfile == BT_INFO_HID) {
5796 RTPRINT(FBT, BT_TRACE,
5797 ("[BTCoex], BT PROFILE is HID\n"));
5798 btdm_1AntSetPSTDMA(padapter, true, 0, true, 31);
5799 } else if (pBtCoex->c2hBtProfile == BT_INFO_FTP) {
5800 RTPRINT(FBT, BT_TRACE,
5801 ("[BTCoex], BT PROFILE is FTP/OPP\n"));
5802 btdm_1AntSetPSTDMA(padapter, true, 0, true, 3);
5803 } else if (pBtCoex->c2hBtProfile == (BT_INFO_A2DP|BT_INFO_FTP)) {
5804 RTPRINT(FBT, BT_TRACE,
5805 ("[BTCoex], BT PROFILE is A2DP_FTP\n"));
5806 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5808 if (pBtCoex->c2hBtProfile == BT_INFO_A2DP)
5809 RTPRINT(FBT, BT_TRACE,
5810 ("[BTCoex], BT PROFILE is "
5813 RTPRINT(FBT, BT_TRACE,
5814 ("[BTCoex], BT PROFILE is "
5815 "UNKNOWN(0x%02X)! Use A2DP "
5817 pBtCoex->c2hBtProfile));
5818 btdm_1AntTdmaDurationAdjustForACL(padapter);
5824 pBtdm8723->psTdmaGlobalCnt++;
5828 btdm_1AntUpdateHalRAMask(struct rtw_adapter *padapter, u32 mac_id, u32 filter)
5833 u8 shortGIrate = false;
5834 int supportRateNum = 0;
5835 struct sta_info *psta;
5836 struct hal_data_8723a *pHalData;
5837 struct dm_priv *pdmpriv;
5838 struct mlme_ext_priv *pmlmeext;
5839 struct mlme_ext_info *pmlmeinfo;
5840 struct wlan_bssid_ex *cur_network;
5842 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d, filter = 0x%08x!!\n",
5843 __func__, mac_id, filter));
5845 pHalData = GET_HAL_DATA(padapter);
5846 pdmpriv = &pHalData->dmpriv;
5847 pmlmeext = &padapter->mlmeextpriv;
5848 pmlmeinfo = &pmlmeext->mlmext_info;
5849 cur_network = &pmlmeinfo->network;
5851 if (mac_id >= NUM_STA) { /* CAM_SIZE */
5852 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d illegal!!\n",
5857 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
5859 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, Can't find station!!\n",
5867 case 0:/* for infra mode */
5869 rtw_get_rateset_len23a(cur_network->SupportedRates);
5870 mask = update_supported_rate23a(cur_network->SupportedRates,
5872 mask |= (pmlmeinfo->HT_enable) ?
5873 update_MSC_rate23a(&pmlmeinfo->ht_cap):0;
5874 if (support_short_GI23a(padapter, &pmlmeinfo->ht_cap))
5877 case 1:/* for broadcast/multicast */
5878 supportRateNum = rtw_get_rateset_len23a(
5879 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5880 mask = update_basic_rate23a(cur_network->SupportedRates,
5883 default: /* for each sta in IBSS */
5884 supportRateNum = rtw_get_rateset_len23a(
5885 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5886 mask = update_supported_rate23a(cur_network->SupportedRates,
5890 mask |= ((raid<<28)&0xf0000000);
5893 init_rate = get_highest_rate_idx23a(mask)&0x3f;
5895 if (pHalData->fw_ractrl) {
5898 arg = mac_id&0x1f;/* MACID */
5900 if (true == shortGIrate)
5903 RTPRINT(FBT, BT_TRACE,
5904 ("[BTCoex], Update FW RAID entry, MASK = 0x%08x, "
5905 "arg = 0x%02x\n", mask, arg));
5907 rtl8723a_set_raid_cmd(padapter, mask, arg);
5910 init_rate |= BIT(6);
5912 rtl8723au_write8(padapter, REG_INIDATA_RATE_SEL + mac_id,
5916 psta->init_rate = init_rate;
5917 pdmpriv->INIDATA_RATE[mac_id] = init_rate;
5921 btdm_1AntUpdateHalRAMaskForSCO(struct rtw_adapter *padapter, u8 forceUpdate)
5923 struct btdm_8723a_1ant *pBtdm8723;
5924 struct sta_priv *pstapriv;
5925 struct wlan_bssid_ex *cur_network;
5926 struct sta_info *psta;
5930 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5932 if (pBtdm8723->bRAChanged == true && forceUpdate == false)
5935 pstapriv = &padapter->stapriv;
5936 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5937 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5938 macid = psta->mac_id;
5940 filter |= BIT(_1M_RATE_);
5941 filter |= BIT(_2M_RATE_);
5942 filter |= BIT(_5M_RATE_);
5943 filter |= BIT(_11M_RATE_);
5944 filter |= BIT(_6M_RATE_);
5945 filter |= BIT(_9M_RATE_);
5947 btdm_1AntUpdateHalRAMask(padapter, macid, filter);
5949 pBtdm8723->bRAChanged = true;
5952 static void btdm_1AntRecoverHalRAMask(struct rtw_adapter *padapter)
5954 struct btdm_8723a_1ant *pBtdm8723;
5955 struct sta_priv *pstapriv;
5956 struct wlan_bssid_ex *cur_network;
5957 struct sta_info *psta;
5959 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5961 if (pBtdm8723->bRAChanged == false)
5964 pstapriv = &padapter->stapriv;
5965 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5966 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5968 Update_RA_Entry23a(padapter, psta);
5970 pBtdm8723->bRAChanged = false;
5974 btdm_1AntBTStateChangeHandler(struct rtw_adapter *padapter,
5975 enum bt_state_1ant oldState,
5976 enum bt_state_1ant newState)
5978 struct hal_data_8723a *phaldata;
5979 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT state change, %s => %s\n",
5980 BtStateString[oldState],
5981 BtStateString[newState]));
5983 /* BT default ignore wlan active, */
5984 /* WiFi MUST disable this when BT is enable */
5985 if (newState > BT_INFO_STATE_DISABLED)
5986 btdm_SetFwIgnoreWlanAct(padapter, false);
5988 if ((check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
5989 (BTDM_IsWifiConnectionExist(padapter))) {
5990 if ((newState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
5991 (newState == BT_INFO_STATE_ACL_SCO_BUSY)) {
5992 btdm_1AntUpdateHalRAMaskForSCO(padapter, false);
5994 /* Recover original RA setting */
5995 btdm_1AntRecoverHalRAMask(padapter);
5998 phaldata = GET_HAL_DATA(padapter);
5999 phaldata->bt_coexist.halCoex8723.btdm1Ant.bRAChanged = false;
6002 if (oldState == newState)
6005 if (oldState == BT_INFO_STATE_ACL_ONLY_BUSY) {
6006 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
6007 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCnt = 0;
6008 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
6011 if ((oldState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6012 (oldState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6013 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
6014 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
6017 /* Active 2Ant mechanism when BT Connected */
6018 if ((oldState == BT_INFO_STATE_DISABLED) ||
6019 (oldState == BT_INFO_STATE_NO_CONNECTION)) {
6020 if ((newState != BT_INFO_STATE_DISABLED) &&
6021 (newState != BT_INFO_STATE_NO_CONNECTION)) {
6022 BTDM_SetSwRfRxLpfCorner(padapter,
6023 BT_RF_RX_LPF_CORNER_SHRINK);
6024 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6025 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6028 if ((newState == BT_INFO_STATE_DISABLED) ||
6029 (newState == BT_INFO_STATE_NO_CONNECTION)) {
6030 BTDM_SetSwRfRxLpfCorner(padapter,
6031 BT_RF_RX_LPF_CORNER_RESUME);
6032 BTDM_AGCTable(padapter, BT_AGCTABLE_OFF);
6033 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_OFF);
6038 static void btdm_1AntBtCoexistHandler(struct rtw_adapter *padapter)
6040 struct hal_data_8723a *pHalData;
6041 struct bt_coexist_8723a *pBtCoex8723;
6042 struct btdm_8723a_1ant *pBtdm8723;
6044 pHalData = GET_HAL_DATA(padapter);
6045 pBtCoex8723 = &pHalData->bt_coexist.halCoex8723;
6046 pBtdm8723 = &pBtCoex8723->btdm1Ant;
6047 padapter->pwrctrlpriv.btcoex_rfon = false;
6048 if (!rtl8723a_BT_enabled(padapter)) {
6049 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is disabled\n"));
6051 if (BTDM_IsWifiConnectionExist(padapter)) {
6052 RTPRINT(FBT, BT_TRACE,
6053 ("[BTCoex], wifi is connected\n"));
6055 if (BTDM_IsWifiBusy(padapter)) {
6056 RTPRINT(FBT, BT_TRACE,
6057 ("[BTCoex], Wifi is busy\n"));
6058 btdm_1AntSetPSTDMA(padapter, false, 0,
6061 RTPRINT(FBT, BT_TRACE,
6062 ("[BTCoex], Wifi is idle\n"));
6063 _btdm_1AntSetPSTDMA(padapter, true, 2, 1,
6067 RTPRINT(FBT, BT_TRACE,
6068 ("[BTCoex], wifi is disconnected\n"));
6070 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6073 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is enabled\n"));
6075 if (BTDM_IsWifiConnectionExist(padapter)) {
6076 RTPRINT(FBT, BT_TRACE,
6077 ("[BTCoex], wifi is connected\n"));
6079 btdm_1AntWifiParaAdjust(padapter, true);
6080 btdm_1AntCoexProcessForWifiConnect(padapter);
6082 RTPRINT(FBT, BT_TRACE,
6083 ("[BTCoex], wifi is disconnected\n"));
6085 /* Antenna switch at BT side(0x870 = 0x300,
6086 0x860 = 0x210) after PSTDMA off */
6087 btdm_1AntWifiParaAdjust(padapter, false);
6088 btdm_1AntSetPSTDMA(padapter, false, 0, false, 0);
6092 btdm_1AntBTStateChangeHandler(padapter, pBtCoex8723->prec2hBtInfo,
6093 pBtCoex8723->c2hBtInfo);
6094 pBtCoex8723->prec2hBtInfo = pBtCoex8723->c2hBtInfo;
6097 void BTDM_1AntSignalCompensation(struct rtw_adapter *padapter,
6098 u8 *rssi_wifi, u8 *rssi_bt)
6100 struct hal_data_8723a *pHalData;
6101 struct btdm_8723a_1ant *pBtdm8723;
6102 u8 RSSI_WiFi_Cmpnstn, RSSI_BT_Cmpnstn;
6104 pHalData = GET_HAL_DATA(padapter);
6105 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
6106 RSSI_WiFi_Cmpnstn = 0;
6107 RSSI_BT_Cmpnstn = 0;
6109 switch (pBtdm8723->curPsTdma) {
6110 case 1: /* WiFi 52ms */
6111 RSSI_WiFi_Cmpnstn = 11; /* 22*0.48 */
6113 case 2: /* WiFi 36ms */
6114 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6116 case 9: /* WiFi 20ms */
6117 RSSI_WiFi_Cmpnstn = 18; /* 22*0.80 */
6119 case 11: /* WiFi 10ms */
6120 RSSI_WiFi_Cmpnstn = 20; /* 22*0.90 */
6122 case 4: /* WiFi 21ms */
6123 RSSI_WiFi_Cmpnstn = 17; /* 22*0.79 */
6125 case 16: /* WiFi 24ms */
6126 RSSI_WiFi_Cmpnstn = 18; /* 22*0.76 */
6128 case 18: /* WiFi 37ms */
6129 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6131 case 23: /* Level-1, Antenna switch to BT at all time */
6132 case 24: /* Level-2, Antenna switch to BT at all time */
6133 case 25: /* Level-3a, Antenna switch to BT at all time */
6134 case 26: /* Level-3b, Antenna switch to BT at all time */
6135 case 27: /* Level-3b, Antenna switch to BT at all time */
6136 case 33: /* BT SCO & WiFi site survey */
6137 RSSI_WiFi_Cmpnstn = 22;
6143 if (rssi_wifi && RSSI_WiFi_Cmpnstn) {
6144 RTPRINT(FBT, BT_TRACE,
6145 ("[BTCoex], 1AntSgnlCmpnstn, case %d, WiFiCmpnstn "
6146 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6147 RSSI_WiFi_Cmpnstn, *rssi_wifi,
6148 *rssi_wifi+RSSI_WiFi_Cmpnstn));
6149 *rssi_wifi += RSSI_WiFi_Cmpnstn;
6152 if (rssi_bt && RSSI_BT_Cmpnstn) {
6153 RTPRINT(FBT, BT_TRACE,
6154 ("[BTCoex], 1AntSgnlCmpnstn, case %d, BTCmpnstn "
6155 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6156 RSSI_BT_Cmpnstn, *rssi_bt, *rssi_bt+RSSI_BT_Cmpnstn));
6157 *rssi_bt += RSSI_BT_Cmpnstn;
6161 static void BTDM_1AntParaInit(struct rtw_adapter *padapter)
6163 struct hal_data_8723a *pHalData;
6164 struct bt_coexist_8723a *pBtCoex;
6165 struct btdm_8723a_1ant *pBtdm8723;
6167 pHalData = GET_HAL_DATA(padapter);
6168 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6169 pBtdm8723 = &pBtCoex->btdm1Ant;
6171 /* Enable counter statistics */
6172 rtl8723au_write8(padapter, 0x76e, 0x4);
6173 btdm_1AntPtaParaReload(padapter);
6175 pBtdm8723->wifiRssiThresh = 48;
6177 pBtdm8723->bWiFiHalt = false;
6178 pBtdm8723->bRAChanged = false;
6180 if ((pBtCoex->c2hBtInfo != BT_INFO_STATE_DISABLED) &&
6181 (pBtCoex->c2hBtInfo != BT_INFO_STATE_NO_CONNECTION)) {
6182 BTDM_SetSwRfRxLpfCorner(padapter, BT_RF_RX_LPF_CORNER_SHRINK);
6183 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6184 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6188 static void BTDM_1AntForHalt(struct rtw_adapter *padapter)
6190 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for halt\n"));
6192 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6195 btdm_1AntWifiParaAdjust(padapter, false);
6197 /* don't use btdm_1AntSetPSTDMA() here */
6198 /* it will call rtw_set_ps_mode23a() and request pwrpriv->lock. */
6199 /* This will lead to deadlock, if this function is called in IPS */
6200 /* Lucas@20130205 */
6201 btdm_1AntPsTdma(padapter, false, 0);
6203 btdm_SetFwIgnoreWlanAct(padapter, true);
6206 static void BTDM_1AntLpsLeave(struct rtw_adapter *padapter)
6208 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for LPS Leave\n"));
6210 /* Prevent from entering LPS again */
6211 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6214 btdm_1AntSetPSTDMA(padapter, false, 0, false, 8);
6215 /*btdm_1AntPsTdma(padapter, false, 8); */
6218 static void BTDM_1AntWifiAssociateNotify(struct rtw_adapter *padapter, u8 type)
6220 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6222 RTPRINT(FBT, BT_TRACE,
6223 ("\n[BTCoex], 1Ant for associate, type =%d\n", type));
6226 rtl8723a_CheckAntenna_Selection(padapter);
6227 if (!rtl8723a_BT_enabled(padapter))
6228 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6230 struct bt_coexist_8723a *pBtCoex;
6233 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6234 BtState = pBtCoex->c2hBtInfo;
6236 btdm_1AntTSFSwitch(padapter, true);
6238 if (BtState == BT_INFO_STATE_NO_CONNECTION ||
6239 BtState == BT_INFO_STATE_CONNECT_IDLE) {
6240 btdm_1AntSetPSTDMA(padapter, false, 0,
6242 } else if (BtState == BT_INFO_STATE_SCO_ONLY_BUSY ||
6243 BtState == BT_INFO_STATE_ACL_SCO_BUSY) {
6244 btdm_1AntSetPSTDMA(padapter, false, 0,
6246 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
6247 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
6248 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY ||
6249 BtState == BT_INFO_STATE_ACL_INQ_OR_PAG) {
6250 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6251 btdm_1AntSetPSTDMA(padapter, false, 0,
6254 btdm_1AntSetPSTDMA(padapter, false, 0,
6259 if (!rtl8723a_BT_enabled(padapter)) {
6260 if (!BTDM_IsWifiConnectionExist(padapter)) {
6261 btdm_1AntPsTdma(padapter, false, 0);
6262 btdm_1AntTSFSwitch(padapter, false);
6266 btdm_1AntBtCoexistHandler(padapter);
6271 BTDM_1AntMediaStatusNotify(struct rtw_adapter *padapter,
6272 enum rt_media_status mstatus)
6274 struct bt_coexist_8723a *pBtCoex;
6276 pBtCoex = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723;
6278 RTPRINT(FBT, BT_TRACE,
6279 ("\n\n[BTCoex]******************************\n"));
6280 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatus, WiFi %s !!\n",
6281 mstatus == RT_MEDIA_CONNECT?"CONNECT":"DISCONNECT"));
6282 RTPRINT(FBT, BT_TRACE, ("[BTCoex]******************************\n"));
6284 if (RT_MEDIA_CONNECT == mstatus) {
6285 if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) {
6286 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_SCO_ONLY_BUSY ||
6287 pBtCoex->c2hBtInfo == BT_INFO_STATE_ACL_SCO_BUSY)
6288 btdm_1AntUpdateHalRAMaskForSCO(padapter, true);
6291 padapter->pwrctrlpriv.DelayLPSLastTimeStamp = jiffies;
6292 BTDM_1AntForDhcp(padapter);
6294 /* DBG_8723A("%s rtl8723a_DeinitAntenna_Selection\n",
6296 rtl8723a_DeinitAntenna_Selection(padapter);
6297 btdm_1AntBtCoexistHandler(padapter);
6298 pBtCoex->btdm1Ant.bRAChanged = false;
6302 void BTDM_1AntForDhcp(struct rtw_adapter *padapter)
6304 struct hal_data_8723a *pHalData;
6306 struct bt_coexist_8723a *pBtCoex;
6307 struct btdm_8723a_1ant *pBtdm8723;
6309 pHalData = GET_HAL_DATA(padapter);
6310 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6311 BtState = pBtCoex->c2hBtInfo;
6312 pBtdm8723 = &pBtCoex->btdm1Ant;
6314 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for DHCP\n"));
6315 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, WiFi is %s\n",
6316 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6317 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, %s\n",
6318 BtStateString[BtState]));
6320 BTDM_1AntWifiAssociateNotify(padapter, true);
6323 static void BTDM_1AntWifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
6325 struct hal_data_8723a *pHalData;
6327 struct bt_coexist_8723a *pBtCoex;
6328 struct btdm_8723a_1ant *pBtdm8723;
6330 pHalData = GET_HAL_DATA(padapter);
6331 BtState = pHalData->bt_coexist.halCoex8723.c2hBtInfo;
6332 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6333 pBtdm8723 = &pBtCoex->btdm1Ant;
6335 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for wifi scan =%d!!\n",
6337 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, WiFi is %s\n",
6338 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6339 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, %s\n",
6340 BtStateString[BtState]));
6343 rtl8723a_CheckAntenna_Selection(padapter);
6344 if (!rtl8723a_BT_enabled(padapter)) {
6345 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6346 } else if (BTDM_IsWifiConnectionExist(padapter) == false) {
6347 BTDM_1AntWifiAssociateNotify(padapter, true);
6349 if ((BtState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6350 (BtState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6351 if (pBtCoex->bC2hBtInquiryPage) {
6352 btdm_1AntSetPSTDMA(padapter, false, 0,
6355 padapter->pwrctrlpriv.btcoex_rfon =
6357 btdm_1AntSetPSTDMA(padapter, true, 0,
6360 } else if (true == pBtCoex->bC2hBtInquiryPage) {
6361 padapter->pwrctrlpriv.btcoex_rfon = true;
6362 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
6363 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY) {
6364 padapter->pwrctrlpriv.btcoex_rfon = true;
6365 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6366 btdm_1AntSetPSTDMA(padapter, true, 0,
6369 btdm_1AntSetPSTDMA(padapter, true, 0,
6372 padapter->pwrctrlpriv.btcoex_rfon = true;
6373 btdm_1AntSetPSTDMA(padapter, true, 0, true, 5);
6377 btdm_NotifyFwScan(padapter, 1);
6379 /* WiFi_Finish_Scan */
6380 btdm_NotifyFwScan(padapter, 0);
6381 btdm_1AntBtCoexistHandler(padapter);
6385 static void BTDM_1AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
6387 struct hal_data_8723a *pHalData;
6388 struct bt_30info *pBTInfo;
6389 struct bt_mgnt *pBtMgnt;
6390 struct bt_coexist_8723a *pBtCoex;
6393 pHalData = GET_HAL_DATA(padapter);
6394 pBTInfo = GET_BT_INFO(padapter);
6395 pBtMgnt = &pBTInfo->BtMgnt;
6396 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6398 u1tmp = pBtCoex->c2hBtInfoOriginal;
6399 /* sco BUSY bit is not used on voice over PCM platform */
6400 btState = u1tmp & 0xF;
6401 pBtCoex->c2hBtProfile = u1tmp & 0xE0;
6403 /* default set bt to idle state. */
6404 pBtMgnt->ExtConfig.bBTBusy = false;
6405 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
6407 /* check BIT2 first ==> check if bt is under inquiry or page scan */
6408 if (btState & BIT(2))
6409 pBtCoex->bC2hBtInquiryPage = true;
6411 pBtCoex->bC2hBtInquiryPage = false;
6414 if (!(btState & BIT(0)))
6415 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
6418 pBtCoex->c2hBtInfo = BT_INFO_STATE_CONNECT_IDLE;
6419 else if (btState == 0x9) {
6420 if (pBtCoex->bC2hBtInquiryPage == true)
6421 pBtCoex->c2hBtInfo =
6422 BT_INFO_STATE_ACL_INQ_OR_PAG;
6424 pBtCoex->c2hBtInfo =
6425 BT_INFO_STATE_ACL_ONLY_BUSY;
6426 pBtMgnt->ExtConfig.bBTBusy = true;
6427 } else if (btState == 0x3) {
6428 pBtCoex->c2hBtInfo = BT_INFO_STATE_SCO_ONLY_BUSY;
6429 pBtMgnt->ExtConfig.bBTBusy = true;
6430 } else if (btState == 0xb) {
6431 pBtCoex->c2hBtInfo = BT_INFO_STATE_ACL_SCO_BUSY;
6432 pBtMgnt->ExtConfig.bBTBusy = true;
6434 pBtCoex->c2hBtInfo = BT_INFO_STATE_MAX;
6435 if (pBtMgnt->ExtConfig.bBTBusy)
6436 pHalData->bt_coexist.CurrentState &=
6437 ~BT_COEX_STATE_BT_IDLE;
6440 if (BT_INFO_STATE_NO_CONNECTION == pBtCoex->c2hBtInfo ||
6441 BT_INFO_STATE_CONNECT_IDLE == pBtCoex->c2hBtInfo) {
6442 if (pBtCoex->bC2hBtInquiryPage)
6443 pBtCoex->c2hBtInfo = BT_INFO_STATE_INQ_OR_PAG;
6446 RTPRINT(FBT, BT_TRACE, ("[BTC2H], %s(%d)\n",
6447 BtStateString[pBtCoex->c2hBtInfo], pBtCoex->c2hBtInfo));
6449 if (pBtCoex->c2hBtProfile != BT_INFO_HID)
6450 pBtCoex->c2hBtProfile &= ~BT_INFO_HID;
6453 void BTDM_1AntBtCoexist8723A(struct rtw_adapter *padapter)
6455 struct mlme_priv *pmlmepriv;
6456 struct hal_data_8723a *pHalData;
6457 unsigned long delta_time;
6459 pmlmepriv = &padapter->mlmepriv;
6460 pHalData = GET_HAL_DATA(padapter);
6462 if (check_fwstate(pmlmepriv, WIFI_SITE_MONITOR)) {
6463 /* already done in BTDM_1AntForScan() */
6464 RTPRINT(FBT, BT_TRACE,
6465 ("[BTCoex], wifi is under scan progress!!\n"));
6469 if (check_fwstate(pmlmepriv, WIFI_UNDER_LINKING)) {
6470 RTPRINT(FBT, BT_TRACE,
6471 ("[BTCoex], wifi is under link progress!!\n"));
6475 /* under DHCP(Special packet) */
6476 delta_time = jiffies - padapter->pwrctrlpriv.DelayLPSLastTimeStamp;
6477 delta_time = jiffies_to_msecs(delta_time);
6478 if (delta_time < 500) {
6479 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is under DHCP "
6480 "progress(%li ms)!!\n", delta_time));
6484 BTDM_CheckWiFiState(padapter);
6486 btdm_1AntBtCoexistHandler(padapter);
6489 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
6491 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
6493 /* local function start with btdm_ */
6494 static u8 btdm_ActionAlgorithm(struct rtw_adapter *padapter)
6496 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
6497 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
6498 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6499 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6500 u8 bScoExist = false, bBtLinkExist = false, bBtHsModeExist = false;
6501 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
6503 if (pBtMgnt->ExtConfig.NumberOfHandle)
6504 bBtLinkExist = true;
6505 if (pBtMgnt->ExtConfig.NumberOfSCO)
6507 if (BT_HsConnectionEstablished(padapter))
6508 bBtHsModeExist = true;
6510 /* here we get BT status first */
6512 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
6514 if ((bScoExist) || (bBtHsModeExist) ||
6515 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID))) {
6516 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO or HID or HS exists, set BT non-idle !!!\n"));
6517 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6520 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6521 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP))) {
6522 if (BTDM_BtTxRxCounterL(padapter) < 100) {
6523 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx < 100, set BT connected-idle!!!\n"));
6524 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6526 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx >= 100, set BT non-idle!!!\n"));
6527 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6531 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6532 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6533 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6534 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6535 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6537 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6538 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6539 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6540 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6541 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6545 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6546 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, set BT non-idle!!!\n"));
6547 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6550 /* Pan+A2dp profile */
6551 if ((pBtMgnt->ExtConfig.NumberOfHandle == 2) &&
6552 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) &&
6553 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6554 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6555 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6556 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6558 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6559 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6560 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6561 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6562 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6566 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6567 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, set BT non-idle!!!\n"));
6568 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6572 if (BT_2ANT_BT_STATUS_IDLE != pBtdm8723->btStatus)
6573 pBtMgnt->ExtConfig.bBTBusy = true;
6575 pBtMgnt->ExtConfig.bBTBusy = false;
6577 if (!bBtLinkExist) {
6578 RTPRINT(FBT, BT_TRACE, ("[BTCoex], No profile exists!!!\n"));
6582 if (pBtMgnt->ExtConfig.NumberOfHandle == 1) {
6584 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
6585 algorithm = BT_2ANT_COEX_ALGO_SCO;
6587 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6588 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID only\n"));
6589 algorithm = BT_2ANT_COEX_ALGO_HID;
6590 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6591 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP only\n"));
6592 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6593 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6594 if (bBtHsModeExist) {
6595 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(HS) only\n"));
6596 algorithm = BT_2ANT_COEX_ALGO_PANHS;
6598 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR) only\n"));
6599 algorithm = BT_2ANT_COEX_ALGO_PANEDR;
6602 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d \n",
6603 pBtMgnt->ExtConfig.NumberOfHandle));
6606 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 2) {
6608 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6609 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
6610 algorithm = BT_2ANT_COEX_ALGO_HID;
6611 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6612 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
6613 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6614 if (bBtHsModeExist) {
6615 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
6616 algorithm = BT_2ANT_COEX_ALGO_SCO;
6618 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
6619 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6622 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched ACL profile for NumberOfHandle =%d\n",
6623 pBtMgnt->ExtConfig.NumberOfHandle));
6626 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6627 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6628 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
6629 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6630 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6631 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6632 if (bBtHsModeExist) {
6633 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
6634 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6636 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
6637 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6639 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6640 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6641 if (bBtHsModeExist) {
6642 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
6643 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6645 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
6646 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
6649 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6650 pBtMgnt->ExtConfig.NumberOfHandle));
6653 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 3) {
6655 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6656 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6657 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP\n"));
6658 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6659 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6660 if (bBtHsModeExist) {
6661 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));
6662 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6664 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));
6665 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6667 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6668 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6669 if (bBtHsModeExist) {
6670 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(HS)\n"));
6671 algorithm = BT_2ANT_COEX_ALGO_SCO;
6673 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(EDR)\n"));
6676 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6677 pBtMgnt->ExtConfig.NumberOfHandle));
6680 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6681 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6682 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6683 if (bBtHsModeExist) {
6684 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
6685 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANHS;
6687 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
6688 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
6691 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6692 pBtMgnt->ExtConfig.NumberOfHandle));
6695 } else if (pBtMgnt->ExtConfig.NumberOfHandle >= 3) {
6697 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6698 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6699 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6701 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
6703 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(EDR)\n"));
6705 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6706 pBtMgnt->ExtConfig.NumberOfHandle));
6709 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6710 pBtMgnt->ExtConfig.NumberOfHandle));
6716 static u8 btdm_NeedToDecBtPwr(struct rtw_adapter *padapter)
6718 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6721 if (BT_Operation(padapter)) {
6722 if (pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB > 47) {
6723 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for HS mode!!\n"));
6726 RTPRINT(FBT, BT_TRACE, ("NO Need to decrease bt power for HS mode!!\n"));
6729 if (BTDM_IsWifiConnectionExist(padapter)) {
6730 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for Wifi is connected!!\n"));
6738 btdm_SetCoexTable(struct rtw_adapter *padapter, u32 val0x6c0,
6739 u32 val0x6c8, u8 val0x6cc)
6741 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c0 = 0x%x\n", val0x6c0));
6742 rtl8723au_write32(padapter, 0x6c0, val0x6c0);
6744 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c8 = 0x%x\n", val0x6c8));
6745 rtl8723au_write32(padapter, 0x6c8, val0x6c8);
6747 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6cc = 0x%x\n", val0x6cc));
6748 rtl8723au_write8(padapter, 0x6cc, val0x6cc);
6752 btdm_SetSwFullTimeDacSwing(struct rtw_adapter *padapter, u8 bSwDacSwingOn,
6755 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6757 if (bSwDacSwingOn) {
6758 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing = 0x%x\n", swDacSwingLvl));
6759 PHY_SetBBReg(padapter, 0x880, 0xff000000, swDacSwingLvl);
6760 pHalData->bt_coexist.bSWCoexistAllOff = false;
6762 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing Off!\n"));
6763 PHY_SetBBReg(padapter, 0x880, 0xff000000, 0xc0);
6768 btdm_SetFwDacSwingLevel(struct rtw_adapter *padapter, u8 dacSwingLvl)
6770 u8 H2C_Parameter[1] = {0};
6772 H2C_Parameter[0] = dacSwingLvl;
6774 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Set Dac Swing Level = 0x%x\n", dacSwingLvl));
6775 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write 0x29 = 0x%x\n", H2C_Parameter[0]));
6777 FillH2CCmd(padapter, 0x29, 1, H2C_Parameter);
6780 static void btdm_2AntDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
6782 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6783 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6785 RTPRINT(FBT, BT_TRACE,
6786 ("[BTCoex], Dec BT power = %s\n",
6787 ((bDecBtPwr) ? "ON" : "OFF")));
6788 pBtdm8723->bCurDecBtPwr = bDecBtPwr;
6790 if (pBtdm8723->bPreDecBtPwr == pBtdm8723->bCurDecBtPwr)
6793 BTDM_SetFwDecBtPwr(padapter, pBtdm8723->bCurDecBtPwr);
6795 pBtdm8723->bPreDecBtPwr = pBtdm8723->bCurDecBtPwr;
6799 btdm_2AntFwDacSwingLvl(struct rtw_adapter *padapter, u8 fwDacSwingLvl)
6801 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6802 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6804 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW Dac Swing level = %d\n", fwDacSwingLvl));
6805 pBtdm8723->curFwDacSwingLvl = fwDacSwingLvl;
6807 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preFwDacSwingLvl =%d, curFwDacSwingLvl =%d\n", */
6808 /*pBtdm8723->preFwDacSwingLvl, pBtdm8723->curFwDacSwingLvl)); */
6810 if (pBtdm8723->preFwDacSwingLvl == pBtdm8723->curFwDacSwingLvl)
6813 btdm_SetFwDacSwingLevel(padapter, pBtdm8723->curFwDacSwingLvl);
6815 pBtdm8723->preFwDacSwingLvl = pBtdm8723->curFwDacSwingLvl;
6819 btdm_2AntRfShrink(struct rtw_adapter *padapter, u8 bRxRfShrinkOn)
6821 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6822 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6824 RTPRINT(FBT, BT_TRACE,
6825 ("[BTCoex], turn Rx RF Shrink = %s\n",
6826 ((bRxRfShrinkOn) ? "ON" : "OFF")));
6827 pBtdm8723->bCurRfRxLpfShrink = bRxRfShrinkOn;
6829 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreRfRxLpfShrink =%d, bCurRfRxLpfShrink =%d\n", */
6830 /*pBtdm8723->bPreRfRxLpfShrink, pBtdm8723->bCurRfRxLpfShrink)); */
6832 if (pBtdm8723->bPreRfRxLpfShrink == pBtdm8723->bCurRfRxLpfShrink)
6835 BTDM_SetSwRfRxLpfCorner(padapter, (u8)pBtdm8723->bCurRfRxLpfShrink);
6837 pBtdm8723->bPreRfRxLpfShrink = pBtdm8723->bCurRfRxLpfShrink;
6841 btdm_2AntLowPenaltyRa(struct rtw_adapter *padapter, u8 bLowPenaltyRa)
6843 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6844 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6846 RTPRINT(FBT, BT_TRACE,
6847 ("[BTCoex], turn LowPenaltyRA = %s\n",
6848 ((bLowPenaltyRa) ? "ON" : "OFF")));
6849 pBtdm8723->bCurLowPenaltyRa = bLowPenaltyRa;
6851 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreLowPenaltyRa =%d, bCurLowPenaltyRa =%d\n", */
6852 /*pBtdm8723->bPreLowPenaltyRa, pBtdm8723->bCurLowPenaltyRa)); */
6854 if (pBtdm8723->bPreLowPenaltyRa == pBtdm8723->bCurLowPenaltyRa)
6857 BTDM_SetSwPenaltyTxRateAdaptive(padapter, (u8)pBtdm8723->bCurLowPenaltyRa);
6859 pBtdm8723->bPreLowPenaltyRa = pBtdm8723->bCurLowPenaltyRa;
6863 btdm_2AntDacSwing(struct rtw_adapter *padapter,
6864 u8 bDacSwingOn, u32 dacSwingLvl)
6866 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6867 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6869 RTPRINT(FBT, BT_TRACE,
6870 ("[BTCoex], turn DacSwing =%s, dacSwingLvl = 0x%x\n",
6871 (bDacSwingOn ? "ON" : "OFF"), dacSwingLvl));
6872 pBtdm8723->bCurDacSwingOn = bDacSwingOn;
6873 pBtdm8723->curDacSwingLvl = dacSwingLvl;
6875 if ((pBtdm8723->bPreDacSwingOn == pBtdm8723->bCurDacSwingOn) &&
6876 (pBtdm8723->preDacSwingLvl == pBtdm8723->curDacSwingLvl))
6880 btdm_SetSwFullTimeDacSwing(padapter, bDacSwingOn, dacSwingLvl);
6882 pBtdm8723->bPreDacSwingOn = pBtdm8723->bCurDacSwingOn;
6883 pBtdm8723->preDacSwingLvl = pBtdm8723->curDacSwingLvl;
6886 static void btdm_2AntAdcBackOff(struct rtw_adapter *padapter, u8 bAdcBackOff)
6888 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6889 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6891 RTPRINT(FBT, BT_TRACE,
6892 ("[BTCoex], turn AdcBackOff = %s\n",
6893 ((bAdcBackOff) ? "ON" : "OFF")));
6894 pBtdm8723->bCurAdcBackOff = bAdcBackOff;
6896 if (pBtdm8723->bPreAdcBackOff == pBtdm8723->bCurAdcBackOff)
6899 BTDM_BBBackOffLevel(padapter, (u8)pBtdm8723->bCurAdcBackOff);
6901 pBtdm8723->bPreAdcBackOff = pBtdm8723->bCurAdcBackOff;
6904 static void btdm_2AntAgcTable(struct rtw_adapter *padapter, u8 bAgcTableEn)
6906 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6907 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6909 RTPRINT(FBT, BT_TRACE,
6910 ("[BTCoex], %s Agc Table\n", ((bAgcTableEn) ? "Enable" : "Disable")));
6911 pBtdm8723->bCurAgcTableEn = bAgcTableEn;
6913 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreAgcTableEn =%d, bCurAgcTableEn =%d\n", */
6914 /*pBtdm8723->bPreAgcTableEn, pBtdm8723->bCurAgcTableEn)); */
6916 if (pBtdm8723->bPreAgcTableEn == pBtdm8723->bCurAgcTableEn)
6919 BTDM_AGCTable(padapter, (u8)bAgcTableEn);
6921 pBtdm8723->bPreAgcTableEn = pBtdm8723->bCurAgcTableEn;
6925 btdm_2AntCoexTable(struct rtw_adapter *padapter,
6926 u32 val0x6c0, u32 val0x6c8, u8 val0x6cc)
6928 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6929 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6931 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write Coex Table 0x6c0 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
6932 val0x6c0, val0x6c8, val0x6cc));
6933 pBtdm8723->curVal0x6c0 = val0x6c0;
6934 pBtdm8723->curVal0x6c8 = val0x6c8;
6935 pBtdm8723->curVal0x6cc = val0x6cc;
6937 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n", */
6938 /*pBtdm8723->preVal0x6c0, pBtdm8723->preVal0x6c8, pBtdm8723->preVal0x6cc)); */
6939 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n", */
6940 /*pBtdm8723->curVal0x6c0, pBtdm8723->curVal0x6c8, pBtdm8723->curVal0x6cc)); */
6942 if ((pBtdm8723->preVal0x6c0 == pBtdm8723->curVal0x6c0) &&
6943 (pBtdm8723->preVal0x6c8 == pBtdm8723->curVal0x6c8) &&
6944 (pBtdm8723->preVal0x6cc == pBtdm8723->curVal0x6cc))
6947 btdm_SetCoexTable(padapter, val0x6c0, val0x6c8, val0x6cc);
6949 pBtdm8723->preVal0x6c0 = pBtdm8723->curVal0x6c0;
6950 pBtdm8723->preVal0x6c8 = pBtdm8723->curVal0x6c8;
6951 pBtdm8723->preVal0x6cc = pBtdm8723->curVal0x6cc;
6954 static void btdm_2AntIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
6956 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6957 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6959 RTPRINT(FBT, BT_TRACE,
6960 ("[BTCoex], turn Ignore WlanAct %s\n", (bEnable ? "ON" : "OFF")));
6961 pBtdm8723->bCurIgnoreWlanAct = bEnable;
6964 if (pBtdm8723->bPreIgnoreWlanAct == pBtdm8723->bCurIgnoreWlanAct)
6967 btdm_SetFwIgnoreWlanAct(padapter, bEnable);
6968 pBtdm8723->bPreIgnoreWlanAct = pBtdm8723->bCurIgnoreWlanAct;
6972 btdm_2AntSetFw3a(struct rtw_adapter *padapter, u8 byte1, u8 byte2,
6973 u8 byte3, u8 byte4, u8 byte5)
6975 u8 H2C_Parameter[5] = {0};
6977 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6979 /* byte1[1:0] != 0 means enable pstdma */
6980 /* for 2Ant bt coexist, if byte1 != 0 means enable pstdma */
6982 pHalData->bt_coexist.bFWCoexistAllOff = false;
6983 H2C_Parameter[0] = byte1;
6984 H2C_Parameter[1] = byte2;
6985 H2C_Parameter[2] = byte3;
6986 H2C_Parameter[3] = byte4;
6987 H2C_Parameter[4] = byte5;
6989 pHalData->bt_coexist.fw3aVal[0] = byte1;
6990 pHalData->bt_coexist.fw3aVal[1] = byte2;
6991 pHalData->bt_coexist.fw3aVal[2] = byte3;
6992 pHalData->bt_coexist.fw3aVal[3] = byte4;
6993 pHalData->bt_coexist.fw3aVal[4] = byte5;
6995 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%x%08x\n",
6997 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
6999 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
7002 static void btdm_2AntPsTdma(struct rtw_adapter *padapter, u8 bTurnOn, u8 type)
7004 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7005 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7007 u8 bTurnOnByCnt = false;
7008 u8 psTdmaTypeByCnt = 0;
7010 btTxRxCnt = BTDM_BtTxRxCounterH(padapter)+BTDM_BtTxRxCounterL(padapter);
7011 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT TxRx Counters = %d\n", btTxRxCnt));
7012 if (btTxRxCnt > 3000) {
7013 bTurnOnByCnt = true;
7014 psTdmaTypeByCnt = 8;
7016 RTPRINT(FBT, BT_TRACE,
7017 ("[BTCoex], For BTTxRxCounters, turn %s PS TDMA, type =%d\n",
7018 (bTurnOnByCnt ? "ON" : "OFF"), psTdmaTypeByCnt));
7019 pBtdm8723->bCurPsTdmaOn = bTurnOnByCnt;
7020 pBtdm8723->curPsTdma = psTdmaTypeByCnt;
7022 RTPRINT(FBT, BT_TRACE,
7023 ("[BTCoex], turn %s PS TDMA, type =%d\n",
7024 (bTurnOn ? "ON" : "OFF"), type));
7025 pBtdm8723->bCurPsTdmaOn = bTurnOn;
7026 pBtdm8723->curPsTdma = type;
7029 if ((pBtdm8723->bPrePsTdmaOn == pBtdm8723->bCurPsTdmaOn) &&
7030 (pBtdm8723->prePsTdma == pBtdm8723->curPsTdma))
7037 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
7040 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
7043 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
7046 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0xa1, 0x80);
7049 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7052 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7055 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7058 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0x20, 0x80);
7061 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
7064 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
7067 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
7070 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7073 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7076 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7079 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7082 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0x20, 0x98);
7085 btdm_2AntSetFw3a(padapter, 0xa3, 0x2f, 0x2f, 0x20, 0x80);
7088 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7091 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0xa1, 0x98);
7094 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0x20, 0x98);
7098 /* disable PS tdma */
7101 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7104 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x0, 0x0);
7107 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7112 /* update pre state */
7113 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
7114 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
7117 static void btdm_2AntBtInquiryPage(struct rtw_adapter *padapter)
7119 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7120 btdm_2AntIgnoreWlanAct(padapter, false);
7121 btdm_2AntPsTdma(padapter, true, 8);
7124 static u8 btdm_HoldForBtInqPage(struct rtw_adapter *padapter)
7126 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7127 u32 curTime = jiffies;
7129 if (pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
7130 /* bt inquiry or page is started. */
7131 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime == 0) {
7132 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = curTime;
7133 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page is started at time : 0x%lx \n",
7134 pHalData->bt_coexist.halCoex8723.btInqPageStartTime));
7137 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page started time : 0x%lx, curTime : 0x%x \n",
7138 pHalData->bt_coexist.halCoex8723.btInqPageStartTime, curTime));
7140 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7141 if (((curTime - pHalData->bt_coexist.halCoex8723.btInqPageStartTime)/1000000) >= 10) {
7142 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page >= 10sec!!!"));
7143 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = 0;
7147 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7148 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7149 btdm_2AntIgnoreWlanAct(padapter, false);
7150 btdm_2AntPsTdma(padapter, true, 8);
7157 static u8 btdm_Is2Ant8723ACommonAction(struct rtw_adapter *padapter)
7159 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7160 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7163 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));
7165 if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7166 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7167 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7168 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt idle!!\n"));
7170 btdm_2AntLowPenaltyRa(padapter, false);
7171 btdm_2AntRfShrink(padapter, false);
7172 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7174 btdm_2AntIgnoreWlanAct(padapter, false);
7175 btdm_2AntPsTdma(padapter, false, 0);
7176 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7177 btdm_2AntDecBtPwr(padapter, false);
7179 btdm_2AntAgcTable(padapter, false);
7180 btdm_2AntAdcBackOff(padapter, false);
7181 btdm_2AntDacSwing(padapter, false, 0xc0);
7184 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7185 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7186 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7187 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT idle!!\n"));
7189 btdm_2AntLowPenaltyRa(padapter, true);
7190 btdm_2AntRfShrink(padapter, false);
7191 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7193 btdm_2AntIgnoreWlanAct(padapter, false);
7194 btdm_2AntPsTdma(padapter, false, 0);
7195 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7196 btdm_2AntDecBtPwr(padapter, true);
7198 btdm_2AntAgcTable(padapter, false);
7199 btdm_2AntAdcBackOff(padapter, false);
7200 btdm_2AntDacSwing(padapter, false, 0xc0);
7203 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7204 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7205 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7206 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt connected idle!!\n"));
7208 btdm_2AntLowPenaltyRa(padapter, true);
7209 btdm_2AntRfShrink(padapter, true);
7210 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7212 btdm_2AntIgnoreWlanAct(padapter, false);
7213 btdm_2AntPsTdma(padapter, false, 0);
7214 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7215 btdm_2AntDecBtPwr(padapter, false);
7217 btdm_2AntAgcTable(padapter, false);
7218 btdm_2AntAdcBackOff(padapter, false);
7219 btdm_2AntDacSwing(padapter, false, 0xc0);
7222 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7223 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7224 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7225 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + Bt connected idle!!\n"));
7227 btdm_2AntLowPenaltyRa(padapter, true);
7228 btdm_2AntRfShrink(padapter, true);
7229 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7231 btdm_2AntIgnoreWlanAct(padapter, false);
7232 btdm_2AntPsTdma(padapter, false, 0);
7233 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7234 btdm_2AntDecBtPwr(padapter, true);
7236 btdm_2AntAgcTable(padapter, false);
7237 btdm_2AntAdcBackOff(padapter, false);
7238 btdm_2AntDacSwing(padapter, false, 0xc0);
7241 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7242 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7243 (BT_2ANT_BT_STATUS_NON_IDLE == pBtdm8723->btStatus)) {
7244 RTPRINT(FBT, BT_TRACE, ("Wifi idle + BT non-idle!!\n"));
7246 btdm_2AntLowPenaltyRa(padapter, true);
7247 btdm_2AntRfShrink(padapter, true);
7248 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7250 btdm_2AntIgnoreWlanAct(padapter, false);
7251 btdm_2AntPsTdma(padapter, false, 0);
7252 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7253 btdm_2AntDecBtPwr(padapter, false);
7255 btdm_2AntAgcTable(padapter, false);
7256 btdm_2AntAdcBackOff(padapter, false);
7257 btdm_2AntDacSwing(padapter, false, 0xc0);
7261 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT non-idle!!\n"));
7262 btdm_2AntLowPenaltyRa(padapter, true);
7263 btdm_2AntRfShrink(padapter, true);
7264 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7265 btdm_2AntIgnoreWlanAct(padapter, false);
7266 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7274 btdm_2AntTdmaDurationAdjust(struct rtw_adapter *padapter, u8 bScoHid,
7275 u8 bTxPause, u8 maxInterval)
7277 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7278 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7279 static s32 up, dn, m, n, WaitCount;
7280 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
7283 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));
7285 if (pBtdm8723->bResetTdmaAdjust) {
7286 pBtdm8723->bResetTdmaAdjust = false;
7287 RTPRINT(FBT, BT_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
7290 if (maxInterval == 1) {
7291 btdm_2AntPsTdma(padapter, true, 15);
7292 pBtdm8723->psTdmaDuAdjType = 15;
7293 } else if (maxInterval == 2) {
7294 btdm_2AntPsTdma(padapter, true, 15);
7295 pBtdm8723->psTdmaDuAdjType = 15;
7296 } else if (maxInterval == 3) {
7297 btdm_2AntPsTdma(padapter, true, 15);
7298 pBtdm8723->psTdmaDuAdjType = 15;
7300 btdm_2AntPsTdma(padapter, true, 15);
7301 pBtdm8723->psTdmaDuAdjType = 15;
7304 if (maxInterval == 1) {
7305 btdm_2AntPsTdma(padapter, true, 11);
7306 pBtdm8723->psTdmaDuAdjType = 11;
7307 } else if (maxInterval == 2) {
7308 btdm_2AntPsTdma(padapter, true, 11);
7309 pBtdm8723->psTdmaDuAdjType = 11;
7310 } else if (maxInterval == 3) {
7311 btdm_2AntPsTdma(padapter, true, 11);
7312 pBtdm8723->psTdmaDuAdjType = 11;
7314 btdm_2AntPsTdma(padapter, true, 11);
7315 pBtdm8723->psTdmaDuAdjType = 11;
7320 if (maxInterval == 1) {
7321 btdm_2AntPsTdma(padapter, true, 7);
7322 pBtdm8723->psTdmaDuAdjType = 7;
7323 } else if (maxInterval == 2) {
7324 btdm_2AntPsTdma(padapter, true, 7);
7325 pBtdm8723->psTdmaDuAdjType = 7;
7326 } else if (maxInterval == 3) {
7327 btdm_2AntPsTdma(padapter, true, 7);
7328 pBtdm8723->psTdmaDuAdjType = 7;
7330 btdm_2AntPsTdma(padapter, true, 7);
7331 pBtdm8723->psTdmaDuAdjType = 7;
7334 if (maxInterval == 1) {
7335 btdm_2AntPsTdma(padapter, true, 3);
7336 pBtdm8723->psTdmaDuAdjType = 3;
7337 } else if (maxInterval == 2) {
7338 btdm_2AntPsTdma(padapter, true, 3);
7339 pBtdm8723->psTdmaDuAdjType = 3;
7340 } else if (maxInterval == 3) {
7341 btdm_2AntPsTdma(padapter, true, 3);
7342 pBtdm8723->psTdmaDuAdjType = 3;
7344 btdm_2AntPsTdma(padapter, true, 3);
7345 pBtdm8723->psTdmaDuAdjType = 3;
7356 /* accquire the BT TRx retry count from BT_Info byte2 */
7357 retryCount = pHalData->bt_coexist.halCoex8723.btRetryCnt;
7358 RTPRINT(FBT, BT_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));
7362 if (retryCount == 0) { /* no retry in the last 2-second duration */
7369 if (up >= n) { /* if ³sÄò n Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */
7375 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
7377 } else if (retryCount <= 3) { /* <= 3 retry in the last 2-second duration */
7384 if (dn == 2) { /* if ³sÄò 2 Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */
7386 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7390 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7398 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
7400 } else { /* retry count > 3, ¥un1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */
7402 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7406 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7413 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
7416 RTPRINT(FBT, BT_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));
7417 if (maxInterval == 1) {
7419 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7420 if (pBtdm8723->curPsTdma == 1) {
7421 btdm_2AntPsTdma(padapter, true, 5);
7422 pBtdm8723->psTdmaDuAdjType = 5;
7423 } else if (pBtdm8723->curPsTdma == 2) {
7424 btdm_2AntPsTdma(padapter, true, 6);
7425 pBtdm8723->psTdmaDuAdjType = 6;
7426 } else if (pBtdm8723->curPsTdma == 3) {
7427 btdm_2AntPsTdma(padapter, true, 7);
7428 pBtdm8723->psTdmaDuAdjType = 7;
7429 } else if (pBtdm8723->curPsTdma == 4) {
7430 btdm_2AntPsTdma(padapter, true, 8);
7431 pBtdm8723->psTdmaDuAdjType = 8;
7433 if (pBtdm8723->curPsTdma == 9) {
7434 btdm_2AntPsTdma(padapter, true, 13);
7435 pBtdm8723->psTdmaDuAdjType = 13;
7436 } else if (pBtdm8723->curPsTdma == 10) {
7437 btdm_2AntPsTdma(padapter, true, 14);
7438 pBtdm8723->psTdmaDuAdjType = 14;
7439 } else if (pBtdm8723->curPsTdma == 11) {
7440 btdm_2AntPsTdma(padapter, true, 15);
7441 pBtdm8723->psTdmaDuAdjType = 15;
7442 } else if (pBtdm8723->curPsTdma == 12) {
7443 btdm_2AntPsTdma(padapter, true, 16);
7444 pBtdm8723->psTdmaDuAdjType = 16;
7448 if (pBtdm8723->curPsTdma == 5) {
7449 btdm_2AntPsTdma(padapter, true, 6);
7450 pBtdm8723->psTdmaDuAdjType = 6;
7451 } else if (pBtdm8723->curPsTdma == 6) {
7452 btdm_2AntPsTdma(padapter, true, 7);
7453 pBtdm8723->psTdmaDuAdjType = 7;
7454 } else if (pBtdm8723->curPsTdma == 7) {
7455 btdm_2AntPsTdma(padapter, true, 8);
7456 pBtdm8723->psTdmaDuAdjType = 8;
7457 } else if (pBtdm8723->curPsTdma == 13) {
7458 btdm_2AntPsTdma(padapter, true, 14);
7459 pBtdm8723->psTdmaDuAdjType = 14;
7460 } else if (pBtdm8723->curPsTdma == 14) {
7461 btdm_2AntPsTdma(padapter, true, 15);
7462 pBtdm8723->psTdmaDuAdjType = 15;
7463 } else if (pBtdm8723->curPsTdma == 15) {
7464 btdm_2AntPsTdma(padapter, true, 16);
7465 pBtdm8723->psTdmaDuAdjType = 16;
7467 } else if (result == 1) {
7468 if (pBtdm8723->curPsTdma == 8) {
7469 btdm_2AntPsTdma(padapter, true, 7);
7470 pBtdm8723->psTdmaDuAdjType = 7;
7471 } else if (pBtdm8723->curPsTdma == 7) {
7472 btdm_2AntPsTdma(padapter, true, 6);
7473 pBtdm8723->psTdmaDuAdjType = 6;
7474 } else if (pBtdm8723->curPsTdma == 6) {
7475 btdm_2AntPsTdma(padapter, true, 5);
7476 pBtdm8723->psTdmaDuAdjType = 5;
7477 } else if (pBtdm8723->curPsTdma == 16) {
7478 btdm_2AntPsTdma(padapter, true, 15);
7479 pBtdm8723->psTdmaDuAdjType = 15;
7480 } else if (pBtdm8723->curPsTdma == 15) {
7481 btdm_2AntPsTdma(padapter, true, 14);
7482 pBtdm8723->psTdmaDuAdjType = 14;
7483 } else if (pBtdm8723->curPsTdma == 14) {
7484 btdm_2AntPsTdma(padapter, true, 13);
7485 pBtdm8723->psTdmaDuAdjType = 13;
7489 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7490 if (pBtdm8723->curPsTdma == 5) {
7491 btdm_2AntPsTdma(padapter, true, 1);
7492 pBtdm8723->psTdmaDuAdjType = 1;
7493 } else if (pBtdm8723->curPsTdma == 6) {
7494 btdm_2AntPsTdma(padapter, true, 2);
7495 pBtdm8723->psTdmaDuAdjType = 2;
7496 } else if (pBtdm8723->curPsTdma == 7) {
7497 btdm_2AntPsTdma(padapter, true, 3);
7498 pBtdm8723->psTdmaDuAdjType = 3;
7499 } else if (pBtdm8723->curPsTdma == 8) {
7500 btdm_2AntPsTdma(padapter, true, 4);
7501 pBtdm8723->psTdmaDuAdjType = 4;
7503 if (pBtdm8723->curPsTdma == 13) {
7504 btdm_2AntPsTdma(padapter, true, 9);
7505 pBtdm8723->psTdmaDuAdjType = 9;
7506 } else if (pBtdm8723->curPsTdma == 14) {
7507 btdm_2AntPsTdma(padapter, true, 10);
7508 pBtdm8723->psTdmaDuAdjType = 10;
7509 } else if (pBtdm8723->curPsTdma == 15) {
7510 btdm_2AntPsTdma(padapter, true, 11);
7511 pBtdm8723->psTdmaDuAdjType = 11;
7512 } else if (pBtdm8723->curPsTdma == 16) {
7513 btdm_2AntPsTdma(padapter, true, 12);
7514 pBtdm8723->psTdmaDuAdjType = 12;
7518 if (pBtdm8723->curPsTdma == 1) {
7519 btdm_2AntPsTdma(padapter, true, 2);
7520 pBtdm8723->psTdmaDuAdjType = 2;
7521 } else if (pBtdm8723->curPsTdma == 2) {
7522 btdm_2AntPsTdma(padapter, true, 3);
7523 pBtdm8723->psTdmaDuAdjType = 3;
7524 } else if (pBtdm8723->curPsTdma == 3) {
7525 btdm_2AntPsTdma(padapter, true, 4);
7526 pBtdm8723->psTdmaDuAdjType = 4;
7527 } else if (pBtdm8723->curPsTdma == 9) {
7528 btdm_2AntPsTdma(padapter, true, 10);
7529 pBtdm8723->psTdmaDuAdjType = 10;
7530 } else if (pBtdm8723->curPsTdma == 10) {
7531 btdm_2AntPsTdma(padapter, true, 11);
7532 pBtdm8723->psTdmaDuAdjType = 11;
7533 } else if (pBtdm8723->curPsTdma == 11) {
7534 btdm_2AntPsTdma(padapter, true, 12);
7535 pBtdm8723->psTdmaDuAdjType = 12;
7537 } else if (result == 1) {
7538 if (pBtdm8723->curPsTdma == 4) {
7539 btdm_2AntPsTdma(padapter, true, 3);
7540 pBtdm8723->psTdmaDuAdjType = 3;
7541 } else if (pBtdm8723->curPsTdma == 3) {
7542 btdm_2AntPsTdma(padapter, true, 2);
7543 pBtdm8723->psTdmaDuAdjType = 2;
7544 } else if (pBtdm8723->curPsTdma == 2) {
7545 btdm_2AntPsTdma(padapter, true, 1);
7546 pBtdm8723->psTdmaDuAdjType = 1;
7547 } else if (pBtdm8723->curPsTdma == 12) {
7548 btdm_2AntPsTdma(padapter, true, 11);
7549 pBtdm8723->psTdmaDuAdjType = 11;
7550 } else if (pBtdm8723->curPsTdma == 11) {
7551 btdm_2AntPsTdma(padapter, true, 10);
7552 pBtdm8723->psTdmaDuAdjType = 10;
7553 } else if (pBtdm8723->curPsTdma == 10) {
7554 btdm_2AntPsTdma(padapter, true, 9);
7555 pBtdm8723->psTdmaDuAdjType = 9;
7559 } else if (maxInterval == 2) {
7561 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7562 if (pBtdm8723->curPsTdma == 1) {
7563 btdm_2AntPsTdma(padapter, true, 6);
7564 pBtdm8723->psTdmaDuAdjType = 6;
7565 } else if (pBtdm8723->curPsTdma == 2) {
7566 btdm_2AntPsTdma(padapter, true, 6);
7567 pBtdm8723->psTdmaDuAdjType = 6;
7568 } else if (pBtdm8723->curPsTdma == 3) {
7569 btdm_2AntPsTdma(padapter, true, 7);
7570 pBtdm8723->psTdmaDuAdjType = 7;
7571 } else if (pBtdm8723->curPsTdma == 4) {
7572 btdm_2AntPsTdma(padapter, true, 8);
7573 pBtdm8723->psTdmaDuAdjType = 8;
7575 if (pBtdm8723->curPsTdma == 9) {
7576 btdm_2AntPsTdma(padapter, true, 14);
7577 pBtdm8723->psTdmaDuAdjType = 14;
7578 } else if (pBtdm8723->curPsTdma == 10) {
7579 btdm_2AntPsTdma(padapter, true, 14);
7580 pBtdm8723->psTdmaDuAdjType = 14;
7581 } else if (pBtdm8723->curPsTdma == 11) {
7582 btdm_2AntPsTdma(padapter, true, 15);
7583 pBtdm8723->psTdmaDuAdjType = 15;
7584 } else if (pBtdm8723->curPsTdma == 12) {
7585 btdm_2AntPsTdma(padapter, true, 16);
7586 pBtdm8723->psTdmaDuAdjType = 16;
7589 if (pBtdm8723->curPsTdma == 5) {
7590 btdm_2AntPsTdma(padapter, true, 6);
7591 pBtdm8723->psTdmaDuAdjType = 6;
7592 } else if (pBtdm8723->curPsTdma == 6) {
7593 btdm_2AntPsTdma(padapter, true, 7);
7594 pBtdm8723->psTdmaDuAdjType = 7;
7595 } else if (pBtdm8723->curPsTdma == 7) {
7596 btdm_2AntPsTdma(padapter, true, 8);
7597 pBtdm8723->psTdmaDuAdjType = 8;
7598 } else if (pBtdm8723->curPsTdma == 13) {
7599 btdm_2AntPsTdma(padapter, true, 14);
7600 pBtdm8723->psTdmaDuAdjType = 14;
7601 } else if (pBtdm8723->curPsTdma == 14) {
7602 btdm_2AntPsTdma(padapter, true, 15);
7603 pBtdm8723->psTdmaDuAdjType = 15;
7604 } else if (pBtdm8723->curPsTdma == 15) {
7605 btdm_2AntPsTdma(padapter, true, 16);
7606 pBtdm8723->psTdmaDuAdjType = 16;
7608 } else if (result == 1) {
7609 if (pBtdm8723->curPsTdma == 8) {
7610 btdm_2AntPsTdma(padapter, true, 7);
7611 pBtdm8723->psTdmaDuAdjType = 7;
7612 } else if (pBtdm8723->curPsTdma == 7) {
7613 btdm_2AntPsTdma(padapter, true, 6);
7614 pBtdm8723->psTdmaDuAdjType = 6;
7615 } else if (pBtdm8723->curPsTdma == 6) {
7616 btdm_2AntPsTdma(padapter, true, 6);
7617 pBtdm8723->psTdmaDuAdjType = 6;
7618 } else if (pBtdm8723->curPsTdma == 16) {
7619 btdm_2AntPsTdma(padapter, true, 15);
7620 pBtdm8723->psTdmaDuAdjType = 15;
7621 } else if (pBtdm8723->curPsTdma == 15) {
7622 btdm_2AntPsTdma(padapter, true, 14);
7623 pBtdm8723->psTdmaDuAdjType = 14;
7624 } else if (pBtdm8723->curPsTdma == 14) {
7625 btdm_2AntPsTdma(padapter, true, 14);
7626 pBtdm8723->psTdmaDuAdjType = 14;
7630 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7631 if (pBtdm8723->curPsTdma == 5) {
7632 btdm_2AntPsTdma(padapter, true, 2);
7633 pBtdm8723->psTdmaDuAdjType = 2;
7634 } else if (pBtdm8723->curPsTdma == 6) {
7635 btdm_2AntPsTdma(padapter, true, 2);
7636 pBtdm8723->psTdmaDuAdjType = 2;
7637 } else if (pBtdm8723->curPsTdma == 7) {
7638 btdm_2AntPsTdma(padapter, true, 3);
7639 pBtdm8723->psTdmaDuAdjType = 3;
7640 } else if (pBtdm8723->curPsTdma == 8) {
7641 btdm_2AntPsTdma(padapter, true, 4);
7642 pBtdm8723->psTdmaDuAdjType = 4;
7644 if (pBtdm8723->curPsTdma == 13) {
7645 btdm_2AntPsTdma(padapter, true, 10);
7646 pBtdm8723->psTdmaDuAdjType = 10;
7647 } else if (pBtdm8723->curPsTdma == 14) {
7648 btdm_2AntPsTdma(padapter, true, 10);
7649 pBtdm8723->psTdmaDuAdjType = 10;
7650 } else if (pBtdm8723->curPsTdma == 15) {
7651 btdm_2AntPsTdma(padapter, true, 11);
7652 pBtdm8723->psTdmaDuAdjType = 11;
7653 } else if (pBtdm8723->curPsTdma == 16) {
7654 btdm_2AntPsTdma(padapter, true, 12);
7655 pBtdm8723->psTdmaDuAdjType = 12;
7658 if (pBtdm8723->curPsTdma == 1) {
7659 btdm_2AntPsTdma(padapter, true, 2);
7660 pBtdm8723->psTdmaDuAdjType = 2;
7661 } else if (pBtdm8723->curPsTdma == 2) {
7662 btdm_2AntPsTdma(padapter, true, 3);
7663 pBtdm8723->psTdmaDuAdjType = 3;
7664 } else if (pBtdm8723->curPsTdma == 3) {
7665 btdm_2AntPsTdma(padapter, true, 4);
7666 pBtdm8723->psTdmaDuAdjType = 4;
7667 } else if (pBtdm8723->curPsTdma == 9) {
7668 btdm_2AntPsTdma(padapter, true, 10);
7669 pBtdm8723->psTdmaDuAdjType = 10;
7670 } else if (pBtdm8723->curPsTdma == 10) {
7671 btdm_2AntPsTdma(padapter, true, 11);
7672 pBtdm8723->psTdmaDuAdjType = 11;
7673 } else if (pBtdm8723->curPsTdma == 11) {
7674 btdm_2AntPsTdma(padapter, true, 12);
7675 pBtdm8723->psTdmaDuAdjType = 12;
7677 } else if (result == 1) {
7678 if (pBtdm8723->curPsTdma == 4) {
7679 btdm_2AntPsTdma(padapter, true, 3);
7680 pBtdm8723->psTdmaDuAdjType = 3;
7681 } else if (pBtdm8723->curPsTdma == 3) {
7682 btdm_2AntPsTdma(padapter, true, 2);
7683 pBtdm8723->psTdmaDuAdjType = 2;
7684 } else if (pBtdm8723->curPsTdma == 2) {
7685 btdm_2AntPsTdma(padapter, true, 2);
7686 pBtdm8723->psTdmaDuAdjType = 2;
7687 } else if (pBtdm8723->curPsTdma == 12) {
7688 btdm_2AntPsTdma(padapter, true, 11);
7689 pBtdm8723->psTdmaDuAdjType = 11;
7690 } else if (pBtdm8723->curPsTdma == 11) {
7691 btdm_2AntPsTdma(padapter, true, 10);
7692 pBtdm8723->psTdmaDuAdjType = 10;
7693 } else if (pBtdm8723->curPsTdma == 10) {
7694 btdm_2AntPsTdma(padapter, true, 10);
7695 pBtdm8723->psTdmaDuAdjType = 10;
7699 } else if (maxInterval == 3) {
7701 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7702 if (pBtdm8723->curPsTdma == 1) {
7703 btdm_2AntPsTdma(padapter, true, 7);
7704 pBtdm8723->psTdmaDuAdjType = 7;
7705 } else if (pBtdm8723->curPsTdma == 2) {
7706 btdm_2AntPsTdma(padapter, true, 7);
7707 pBtdm8723->psTdmaDuAdjType = 7;
7708 } else if (pBtdm8723->curPsTdma == 3) {
7709 btdm_2AntPsTdma(padapter, true, 7);
7710 pBtdm8723->psTdmaDuAdjType = 7;
7711 } else if (pBtdm8723->curPsTdma == 4) {
7712 btdm_2AntPsTdma(padapter, true, 8);
7713 pBtdm8723->psTdmaDuAdjType = 8;
7715 if (pBtdm8723->curPsTdma == 9) {
7716 btdm_2AntPsTdma(padapter, true, 15);
7717 pBtdm8723->psTdmaDuAdjType = 15;
7718 } else if (pBtdm8723->curPsTdma == 10) {
7719 btdm_2AntPsTdma(padapter, true, 15);
7720 pBtdm8723->psTdmaDuAdjType = 15;
7721 } else if (pBtdm8723->curPsTdma == 11) {
7722 btdm_2AntPsTdma(padapter, true, 15);
7723 pBtdm8723->psTdmaDuAdjType = 15;
7724 } else if (pBtdm8723->curPsTdma == 12) {
7725 btdm_2AntPsTdma(padapter, true, 16);
7726 pBtdm8723->psTdmaDuAdjType = 16;
7729 if (pBtdm8723->curPsTdma == 5) {
7730 btdm_2AntPsTdma(padapter, true, 7);
7731 pBtdm8723->psTdmaDuAdjType = 7;
7732 } else if (pBtdm8723->curPsTdma == 6) {
7733 btdm_2AntPsTdma(padapter, true, 7);
7734 pBtdm8723->psTdmaDuAdjType = 7;
7735 } else if (pBtdm8723->curPsTdma == 7) {
7736 btdm_2AntPsTdma(padapter, true, 8);
7737 pBtdm8723->psTdmaDuAdjType = 8;
7738 } else if (pBtdm8723->curPsTdma == 13) {
7739 btdm_2AntPsTdma(padapter, true, 15);
7740 pBtdm8723->psTdmaDuAdjType = 15;
7741 } else if (pBtdm8723->curPsTdma == 14) {
7742 btdm_2AntPsTdma(padapter, true, 15);
7743 pBtdm8723->psTdmaDuAdjType = 15;
7744 } else if (pBtdm8723->curPsTdma == 15) {
7745 btdm_2AntPsTdma(padapter, true, 16);
7746 pBtdm8723->psTdmaDuAdjType = 16;
7748 } else if (result == 1) {
7749 if (pBtdm8723->curPsTdma == 8) {
7750 btdm_2AntPsTdma(padapter, true, 7);
7751 pBtdm8723->psTdmaDuAdjType = 7;
7752 } else if (pBtdm8723->curPsTdma == 7) {
7753 btdm_2AntPsTdma(padapter, true, 7);
7754 pBtdm8723->psTdmaDuAdjType = 7;
7755 } else if (pBtdm8723->curPsTdma == 6) {
7756 btdm_2AntPsTdma(padapter, true, 7);
7757 pBtdm8723->psTdmaDuAdjType = 7;
7758 } else if (pBtdm8723->curPsTdma == 16) {
7759 btdm_2AntPsTdma(padapter, true, 15);
7760 pBtdm8723->psTdmaDuAdjType = 15;
7761 } else if (pBtdm8723->curPsTdma == 15) {
7762 btdm_2AntPsTdma(padapter, true, 15);
7763 pBtdm8723->psTdmaDuAdjType = 15;
7764 } else if (pBtdm8723->curPsTdma == 14) {
7765 btdm_2AntPsTdma(padapter, true, 15);
7766 pBtdm8723->psTdmaDuAdjType = 15;
7770 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7771 if (pBtdm8723->curPsTdma == 5) {
7772 btdm_2AntPsTdma(padapter, true, 3);
7773 pBtdm8723->psTdmaDuAdjType = 3;
7774 } else if (pBtdm8723->curPsTdma == 6) {
7775 btdm_2AntPsTdma(padapter, true, 3);
7776 pBtdm8723->psTdmaDuAdjType = 3;
7777 } else if (pBtdm8723->curPsTdma == 7) {
7778 btdm_2AntPsTdma(padapter, true, 3);
7779 pBtdm8723->psTdmaDuAdjType = 3;
7780 } else if (pBtdm8723->curPsTdma == 8) {
7781 btdm_2AntPsTdma(padapter, true, 4);
7782 pBtdm8723->psTdmaDuAdjType = 4;
7784 if (pBtdm8723->curPsTdma == 13) {
7785 btdm_2AntPsTdma(padapter, true, 11);
7786 pBtdm8723->psTdmaDuAdjType = 11;
7787 } else if (pBtdm8723->curPsTdma == 14) {
7788 btdm_2AntPsTdma(padapter, true, 11);
7789 pBtdm8723->psTdmaDuAdjType = 11;
7790 } else if (pBtdm8723->curPsTdma == 15) {
7791 btdm_2AntPsTdma(padapter, true, 11);
7792 pBtdm8723->psTdmaDuAdjType = 11;
7793 } else if (pBtdm8723->curPsTdma == 16) {
7794 btdm_2AntPsTdma(padapter, true, 12);
7795 pBtdm8723->psTdmaDuAdjType = 12;
7798 if (pBtdm8723->curPsTdma == 1) {
7799 btdm_2AntPsTdma(padapter, true, 3);
7800 pBtdm8723->psTdmaDuAdjType = 3;
7801 } else if (pBtdm8723->curPsTdma == 2) {
7802 btdm_2AntPsTdma(padapter, true, 3);
7803 pBtdm8723->psTdmaDuAdjType = 3;
7804 } else if (pBtdm8723->curPsTdma == 3) {
7805 btdm_2AntPsTdma(padapter, true, 4);
7806 pBtdm8723->psTdmaDuAdjType = 4;
7807 } else if (pBtdm8723->curPsTdma == 9) {
7808 btdm_2AntPsTdma(padapter, true, 11);
7809 pBtdm8723->psTdmaDuAdjType = 11;
7810 } else if (pBtdm8723->curPsTdma == 10) {
7811 btdm_2AntPsTdma(padapter, true, 11);
7812 pBtdm8723->psTdmaDuAdjType = 11;
7813 } else if (pBtdm8723->curPsTdma == 11) {
7814 btdm_2AntPsTdma(padapter, true, 12);
7815 pBtdm8723->psTdmaDuAdjType = 12;
7817 } else if (result == 1) {
7818 if (pBtdm8723->curPsTdma == 4) {
7819 btdm_2AntPsTdma(padapter, true, 3);
7820 pBtdm8723->psTdmaDuAdjType = 3;
7821 } else if (pBtdm8723->curPsTdma == 3) {
7822 btdm_2AntPsTdma(padapter, true, 3);
7823 pBtdm8723->psTdmaDuAdjType = 3;
7824 } else if (pBtdm8723->curPsTdma == 2) {
7825 btdm_2AntPsTdma(padapter, true, 3);
7826 pBtdm8723->psTdmaDuAdjType = 3;
7827 } else if (pBtdm8723->curPsTdma == 12) {
7828 btdm_2AntPsTdma(padapter, true, 11);
7829 pBtdm8723->psTdmaDuAdjType = 11;
7830 } else if (pBtdm8723->curPsTdma == 11) {
7831 btdm_2AntPsTdma(padapter, true, 11);
7832 pBtdm8723->psTdmaDuAdjType = 11;
7833 } else if (pBtdm8723->curPsTdma == 10) {
7834 btdm_2AntPsTdma(padapter, true, 11);
7835 pBtdm8723->psTdmaDuAdjType = 11;
7841 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type : recordPsTdma =%d\n", pBtdm8723->psTdmaDuAdjType));
7842 /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
7843 /* then we have to adjust it back to the previous record one. */
7844 if (pBtdm8723->curPsTdma != pBtdm8723->psTdmaDuAdjType) {
7845 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma =%d, recordPsTdma =%d\n",
7846 pBtdm8723->curPsTdma, pBtdm8723->psTdmaDuAdjType));
7848 if (!check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
7849 btdm_2AntPsTdma(padapter, true, pBtdm8723->psTdmaDuAdjType);
7851 RTPRINT(FBT, BT_TRACE, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
7855 /* default Action */
7856 /* SCO only or SCO+PAN(HS) */
7857 static void btdm_2Ant8723ASCOAction(struct rtw_adapter *padapter)
7859 u8 btRssiState, btRssiState1;
7861 if (btdm_NeedToDecBtPwr(padapter))
7862 btdm_2AntDecBtPwr(padapter, true);
7864 btdm_2AntDecBtPwr(padapter, false);
7866 if (BTDM_IsHT40(padapter)) {
7867 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7868 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7870 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7871 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7872 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7873 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7874 btdm_2AntPsTdma(padapter, true, 11);
7876 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7877 btdm_2AntPsTdma(padapter, true, 15);
7881 btdm_2AntAgcTable(padapter, false);
7882 btdm_2AntAdcBackOff(padapter, true);
7883 btdm_2AntDacSwing(padapter, false, 0xc0);
7885 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7886 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7887 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7890 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7891 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7892 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7893 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7894 btdm_2AntPsTdma(padapter, true, 11);
7896 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7897 btdm_2AntPsTdma(padapter, true, 15);
7901 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7902 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7903 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7904 btdm_2AntAgcTable(padapter, true);
7905 btdm_2AntAdcBackOff(padapter, true);
7906 btdm_2AntDacSwing(padapter, false, 0xc0);
7908 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7909 btdm_2AntAgcTable(padapter, false);
7910 btdm_2AntAdcBackOff(padapter, false);
7911 btdm_2AntDacSwing(padapter, false, 0xc0);
7916 static void btdm_2Ant8723AHIDAction(struct rtw_adapter *padapter)
7918 u8 btRssiState, btRssiState1;
7920 if (btdm_NeedToDecBtPwr(padapter))
7921 btdm_2AntDecBtPwr(padapter, true);
7923 btdm_2AntDecBtPwr(padapter, false);
7925 if (BTDM_IsHT40(padapter)) {
7926 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7927 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7929 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7930 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7931 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7932 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7933 btdm_2AntPsTdma(padapter, true, 9);
7935 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7936 btdm_2AntPsTdma(padapter, true, 13);
7940 btdm_2AntAgcTable(padapter, false);
7941 btdm_2AntAdcBackOff(padapter, false);
7942 btdm_2AntDacSwing(padapter, false, 0xc0);
7944 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7945 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7946 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7949 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7950 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7951 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7952 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7953 btdm_2AntPsTdma(padapter, true, 9);
7955 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7956 btdm_2AntPsTdma(padapter, true, 13);
7960 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7961 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7962 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7963 btdm_2AntAgcTable(padapter, true);
7964 btdm_2AntAdcBackOff(padapter, true);
7965 btdm_2AntDacSwing(padapter, false, 0xc0);
7967 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7968 btdm_2AntAgcTable(padapter, false);
7969 btdm_2AntAdcBackOff(padapter, false);
7970 btdm_2AntDacSwing(padapter, false, 0xc0);
7975 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
7976 static void btdm_2Ant8723AA2DPAction(struct rtw_adapter *padapter)
7978 u8 btRssiState, btRssiState1;
7979 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7980 u8 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
7982 if (btdm_NeedToDecBtPwr(padapter))
7983 btdm_2AntDecBtPwr(padapter, true);
7985 btdm_2AntDecBtPwr(padapter, false);
7987 if (BTDM_IsHT40(padapter)) {
7988 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7989 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7992 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7993 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7994 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7995 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 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 btdm_2AntAgcTable(padapter, false);
8017 btdm_2AntAdcBackOff(padapter, true);
8018 btdm_2AntDacSwing(padapter, false, 0xc0);
8020 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8021 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8022 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8025 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8026 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8027 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8028 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8029 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8030 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8031 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
8033 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8034 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8037 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8038 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8039 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8040 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
8042 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8043 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8048 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8049 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8050 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8051 btdm_2AntAgcTable(padapter, true);
8052 btdm_2AntAdcBackOff(padapter, true);
8053 btdm_2AntDacSwing(padapter, false, 0xc0);
8055 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8056 btdm_2AntAgcTable(padapter, false);
8057 btdm_2AntAdcBackOff(padapter, false);
8058 btdm_2AntDacSwing(padapter, false, 0xc0);
8063 static void btdm_2Ant8723APANEDRAction(struct rtw_adapter *padapter)
8065 u8 btRssiState, btRssiState1;
8067 if (btdm_NeedToDecBtPwr(padapter))
8068 btdm_2AntDecBtPwr(padapter, true);
8070 btdm_2AntDecBtPwr(padapter, false);
8072 if (BTDM_IsHT40(padapter)) {
8073 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8074 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8077 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8078 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8079 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8080 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8081 btdm_2AntPsTdma(padapter, true, 2);
8083 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8084 btdm_2AntPsTdma(padapter, true, 6);
8088 btdm_2AntAgcTable(padapter, false);
8089 btdm_2AntAdcBackOff(padapter, true);
8090 btdm_2AntDacSwing(padapter, false, 0xc0);
8092 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8093 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8094 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8097 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8098 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8099 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8100 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8101 btdm_2AntPsTdma(padapter, true, 2);
8103 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8104 btdm_2AntPsTdma(padapter, true, 6);
8108 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8109 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8110 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8111 btdm_2AntAgcTable(padapter, true);
8112 btdm_2AntAdcBackOff(padapter, true);
8113 btdm_2AntDacSwing(padapter, false, 0xc0);
8115 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8116 btdm_2AntAgcTable(padapter, false);
8117 btdm_2AntAdcBackOff(padapter, false);
8118 btdm_2AntDacSwing(padapter, false, 0xc0);
8124 static void btdm_2Ant8723APANHSAction(struct rtw_adapter *padapter)
8128 if (BTDM_IsHT40(padapter)) {
8129 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8130 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8132 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8133 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8134 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8135 btdm_2AntDecBtPwr(padapter, true);
8137 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8138 btdm_2AntDecBtPwr(padapter, false);
8140 btdm_2AntPsTdma(padapter, false, 0);
8143 btdm_2AntAgcTable(padapter, false);
8144 btdm_2AntAdcBackOff(padapter, true);
8145 btdm_2AntDacSwing(padapter, false, 0xc0);
8147 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8148 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8150 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8151 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8152 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high\n"));
8154 btdm_2AntDecBtPwr(padapter, true);
8155 btdm_2AntPsTdma(padapter, false, 0);
8158 btdm_2AntAgcTable(padapter, true);
8159 btdm_2AntAdcBackOff(padapter, true);
8160 btdm_2AntDacSwing(padapter, false, 0xc0);
8162 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low\n"));
8164 btdm_2AntDecBtPwr(padapter, false);
8165 btdm_2AntPsTdma(padapter, false, 0);
8168 btdm_2AntAgcTable(padapter, false);
8169 btdm_2AntAdcBackOff(padapter, false);
8170 btdm_2AntDacSwing(padapter, false, 0xc0);
8176 static void btdm_2Ant8723APANEDRA2DPAction(struct rtw_adapter *padapter)
8178 u8 btRssiState, btRssiState1, btInfoExt;
8179 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8181 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8183 if (btdm_NeedToDecBtPwr(padapter))
8184 btdm_2AntDecBtPwr(padapter, true);
8186 btdm_2AntDecBtPwr(padapter, false);
8188 if (BTDM_IsHT40(padapter)) {
8189 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8190 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8192 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8193 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8194 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8196 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8198 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8199 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8200 btdm_2AntPsTdma(padapter, true, 4);
8202 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8203 btdm_2AntPsTdma(padapter, true, 2);
8206 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8208 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8209 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8210 btdm_2AntPsTdma(padapter, true, 8);
8212 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8213 btdm_2AntPsTdma(padapter, true, 6);
8218 btdm_2AntAgcTable(padapter, false);
8219 btdm_2AntAdcBackOff(padapter, true);
8220 btdm_2AntDacSwing(padapter, false, 0xc0);
8222 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8223 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8224 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8226 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8227 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8228 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8229 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8231 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8232 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8233 btdm_2AntPsTdma(padapter, true, 4);
8235 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8236 btdm_2AntPsTdma(padapter, true, 2);
8239 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8241 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8242 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8243 btdm_2AntPsTdma(padapter, true, 8);
8245 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8246 btdm_2AntPsTdma(padapter, true, 6);
8251 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8252 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8253 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8254 btdm_2AntAgcTable(padapter, true);
8255 btdm_2AntAdcBackOff(padapter, true);
8256 btdm_2AntDacSwing(padapter, false, 0xc0);
8258 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8259 btdm_2AntAgcTable(padapter, false);
8260 btdm_2AntAdcBackOff(padapter, false);
8261 btdm_2AntDacSwing(padapter, false, 0xc0);
8266 static void btdm_2Ant8723APANEDRHIDAction(struct rtw_adapter *padapter)
8268 u8 btRssiState, btRssiState1;
8270 if (btdm_NeedToDecBtPwr(padapter))
8271 btdm_2AntDecBtPwr(padapter, true);
8273 btdm_2AntDecBtPwr(padapter, false);
8275 if (BTDM_IsHT40(padapter)) {
8276 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8277 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8279 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8280 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8281 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8282 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8283 btdm_2AntPsTdma(padapter, true, 10);
8285 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8286 btdm_2AntPsTdma(padapter, true, 14);
8290 btdm_2AntAgcTable(padapter, false);
8291 btdm_2AntAdcBackOff(padapter, true);
8292 btdm_2AntDacSwing(padapter, false, 0xc0);
8294 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8295 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8296 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8299 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8300 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8301 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8302 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8303 btdm_2AntPsTdma(padapter, true, 10);
8305 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8306 btdm_2AntPsTdma(padapter, true, 14);
8310 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8311 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8312 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8313 btdm_2AntAgcTable(padapter, true);
8314 btdm_2AntAdcBackOff(padapter, true);
8315 btdm_2AntDacSwing(padapter, false, 0xc0);
8317 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8318 btdm_2AntAgcTable(padapter, false);
8319 btdm_2AntAdcBackOff(padapter, false);
8320 btdm_2AntDacSwing(padapter, false, 0xc0);
8325 /* HID+A2DP+PAN(EDR) */
8326 static void btdm_2Ant8723AHIDA2DPPANEDRAction(struct rtw_adapter *padapter)
8328 u8 btRssiState, btRssiState1, btInfoExt;
8329 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8331 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8333 if (btdm_NeedToDecBtPwr(padapter))
8334 btdm_2AntDecBtPwr(padapter, true);
8336 btdm_2AntDecBtPwr(padapter, false);
8338 if (BTDM_IsHT40(padapter)) {
8339 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8340 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8341 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8342 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8343 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8344 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8346 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8347 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8348 btdm_2AntPsTdma(padapter, true, 12);
8350 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8351 btdm_2AntPsTdma(padapter, true, 10);
8354 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8355 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8356 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8357 btdm_2AntPsTdma(padapter, true, 16);
8359 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8360 btdm_2AntPsTdma(padapter, true, 14);
8365 btdm_2AntAgcTable(padapter, false);
8366 btdm_2AntAdcBackOff(padapter, true);
8367 btdm_2AntDacSwing(padapter, false, 0xc0);
8369 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8370 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 37, 0);
8371 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8372 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8373 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8374 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8375 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8377 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8378 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8379 btdm_2AntPsTdma(padapter, true, 12);
8381 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8382 btdm_2AntPsTdma(padapter, true, 10);
8385 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8386 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8387 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8388 btdm_2AntPsTdma(padapter, true, 16);
8390 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8391 btdm_2AntPsTdma(padapter, true, 14);
8396 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8397 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8398 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8399 btdm_2AntAgcTable(padapter, true);
8400 btdm_2AntAdcBackOff(padapter, true);
8401 btdm_2AntDacSwing(padapter, false, 0xc0);
8403 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8404 btdm_2AntAgcTable(padapter, false);
8405 btdm_2AntAdcBackOff(padapter, false);
8406 btdm_2AntDacSwing(padapter, false, 0xc0);
8411 static void btdm_2Ant8723AHIDA2DPAction(struct rtw_adapter *padapter)
8413 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8414 u8 btRssiState, btRssiState1, btInfoExt;
8416 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8418 if (btdm_NeedToDecBtPwr(padapter))
8419 btdm_2AntDecBtPwr(padapter, true);
8421 btdm_2AntDecBtPwr(padapter, false);
8423 if (BTDM_IsHT40(padapter)) {
8424 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8425 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8426 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8427 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8428 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8429 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8431 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8432 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8433 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8435 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8436 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8439 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8440 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8441 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8442 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8444 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8445 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8449 btdm_2AntAgcTable(padapter, false);
8450 btdm_2AntAdcBackOff(padapter, true);
8451 btdm_2AntDacSwing(padapter, false, 0xc0);
8453 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8454 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8455 btRssiState1 = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8457 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8458 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8459 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8460 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8462 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8463 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8464 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8466 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8467 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8470 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8471 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8472 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8473 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8475 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8476 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8479 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8480 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8481 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8483 btdm_2AntAgcTable(padapter, true);
8484 btdm_2AntAdcBackOff(padapter, true);
8485 btdm_2AntDacSwing(padapter, false, 0xc0);
8487 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8489 btdm_2AntAgcTable(padapter, false);
8490 btdm_2AntAdcBackOff(padapter, false);
8491 btdm_2AntDacSwing(padapter, false, 0xc0);
8496 static void btdm_2Ant8723AA2dp(struct rtw_adapter *padapter)
8498 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8499 u8 btRssiState, btRssiState1, btInfoExt;
8501 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8503 if (btdm_NeedToDecBtPwr(padapter))
8504 btdm_2AntDecBtPwr(padapter, true);
8506 btdm_2AntDecBtPwr(padapter, false);
8508 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8509 btdm_2AntIgnoreWlanAct(padapter, false);
8511 if (BTDM_IsHT40(padapter)) {
8512 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8513 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8515 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8516 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8517 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8518 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8519 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8521 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8522 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8526 btdm_2AntAgcTable(padapter, false);
8527 btdm_2AntAdcBackOff(padapter, true);
8528 btdm_2AntDacSwing(padapter, false, 0xc0);
8530 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8531 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8532 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8535 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8536 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8537 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8538 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8539 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8541 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8542 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8546 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8547 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8548 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8549 btdm_2AntAgcTable(padapter, true);
8550 btdm_2AntAdcBackOff(padapter, true);
8551 btdm_2AntDacSwing(padapter, false, 0xc0);
8553 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8554 btdm_2AntAgcTable(padapter, false);
8555 btdm_2AntAdcBackOff(padapter, false);
8556 btdm_2AntDacSwing(padapter, false, 0xc0);
8561 /* extern function start with BTDM_ */
8562 static void BTDM_2AntParaInit(struct rtw_adapter *padapter)
8565 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8566 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8568 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2Ant Parameter Init!!\n"));
8570 /* Enable counter statistics */
8571 rtl8723au_write8(padapter, 0x76e, 0x4);
8572 rtl8723au_write8(padapter, 0x778, 0x3);
8573 rtl8723au_write8(padapter, 0x40, 0x20);
8575 /* force to reset coex mechanism */
8576 pBtdm8723->preVal0x6c0 = 0x0;
8577 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8579 pBtdm8723->bPrePsTdmaOn = true;
8580 btdm_2AntPsTdma(padapter, false, 0);
8582 pBtdm8723->preFwDacSwingLvl = 0x10;
8583 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8585 pBtdm8723->bPreDecBtPwr = true;
8586 btdm_2AntDecBtPwr(padapter, false);
8588 pBtdm8723->bPreAgcTableEn = true;
8589 btdm_2AntAgcTable(padapter, false);
8591 pBtdm8723->bPreAdcBackOff = true;
8592 btdm_2AntAdcBackOff(padapter, false);
8594 pBtdm8723->bPreLowPenaltyRa = true;
8595 btdm_2AntLowPenaltyRa(padapter, false);
8597 pBtdm8723->bPreRfRxLpfShrink = true;
8598 btdm_2AntRfShrink(padapter, false);
8600 pBtdm8723->bPreDacSwingOn = true;
8601 btdm_2AntDacSwing(padapter, false, 0xc0);
8603 pBtdm8723->bPreIgnoreWlanAct = true;
8604 btdm_2AntIgnoreWlanAct(padapter, false);
8607 static void BTDM_2AntHwCoexAllOff8723A(struct rtw_adapter *padapter)
8609 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8612 static void BTDM_2AntFwCoexAllOff8723A(struct rtw_adapter *padapter)
8614 btdm_2AntIgnoreWlanAct(padapter, false);
8615 btdm_2AntPsTdma(padapter, false, 0);
8616 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8617 btdm_2AntDecBtPwr(padapter, false);
8620 static void BTDM_2AntSwCoexAllOff8723A(struct rtw_adapter *padapter)
8622 btdm_2AntAgcTable(padapter, false);
8623 btdm_2AntAdcBackOff(padapter, false);
8624 btdm_2AntLowPenaltyRa(padapter, false);
8625 btdm_2AntRfShrink(padapter, false);
8626 btdm_2AntDacSwing(padapter, false, 0xc0);
8629 static void BTDM_2AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
8631 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8632 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8633 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8634 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8636 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
8637 u8 bBtLinkExist = false, bBtHsModeExist = false;
8639 btInfo = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8640 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8642 /* check BIT2 first ==> check if bt is under inquiry or page scan */
8643 if (btInfo & BIT(2)) {
8644 if (!pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
8645 pBtMgnt->ExtConfig.bHoldForBtOperation = true;
8646 pBtMgnt->ExtConfig.bHoldPeriodCnt = 1;
8647 btdm_2AntBtInquiryPage(padapter);
8649 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8650 btdm_HoldForBtInqPage(padapter);
8652 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = true;
8655 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = false;
8656 pBtMgnt->ExtConfig.bHoldForBtOperation = false;
8657 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8660 RTPRINT(FBT, BT_TRACE,
8661 ("[BTC2H], pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage =%x pBtMgnt->ExtConfig.bHoldPeriodCnt =%x pBtMgnt->ExtConfig.bHoldForBtOperation =%x\n",
8662 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage,
8663 pBtMgnt->ExtConfig.bHoldPeriodCnt,
8664 pBtMgnt->ExtConfig.bHoldForBtOperation));
8666 RTPRINT(FBT, BT_TRACE,
8667 ("[BTC2H], btInfo =%x pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal =%x\n",
8668 btInfo, pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal));
8669 if (btInfo&BT_INFO_ACL) {
8670 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = true btInfo =%x\n", btInfo));
8671 bBtLinkExist = true;
8672 if (((btInfo&(BT_INFO_FTP|BT_INFO_A2DP|BT_INFO_HID|BT_INFO_SCO_BUSY)) != 0) ||
8673 pHalData->bt_coexist.halCoex8723.btRetryCnt > 0) {
8674 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
8676 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
8679 if (btInfo&BT_INFO_SCO || btInfo&BT_INFO_SCO_BUSY) {
8680 if (btInfo&BT_INFO_FTP || btInfo&BT_INFO_A2DP || btInfo&BT_INFO_HID) {
8681 switch (btInfo&0xe0) {
8683 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
8684 algorithm = BT_2ANT_COEX_ALGO_HID;
8687 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
8690 if (bBtHsModeExist) {
8691 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
8692 algorithm = BT_2ANT_COEX_ALGO_SCO;
8694 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
8695 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8698 case (BT_INFO_HID | BT_INFO_A2DP):
8699 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8700 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8702 case (BT_INFO_HID | BT_INFO_FTP):
8703 if (bBtHsModeExist) {
8704 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8705 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8707 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8708 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8711 case (BT_INFO_A2DP | BT_INFO_FTP):
8712 if (bBtHsModeExist) {
8713 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8714 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8716 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8717 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8720 case (BT_INFO_HID | BT_INFO_A2DP | BT_INFO_FTP):
8721 if (bBtHsModeExist) {
8722 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8723 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8725 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8726 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8731 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
8732 algorithm = BT_2ANT_COEX_ALGO_SCO;
8735 RTPRINT(FBT, BT_TRACE, ("[BTCoex], non SCO\n"));
8736 switch (btInfo&0xe0) {
8738 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID\n"));
8739 algorithm = BT_2ANT_COEX_ALGO_HID;
8742 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP\n"));
8743 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8746 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR)\n"));
8747 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8749 case (BT_INFO_HID | BT_INFO_A2DP):
8750 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8751 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8753 case (BT_INFO_HID|BT_INFO_FTP):
8754 if (bBtHsModeExist) {
8755 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8756 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8758 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8759 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8762 case (BT_INFO_A2DP|BT_INFO_FTP):
8763 if (bBtHsModeExist) {
8764 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8765 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8767 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8768 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8771 case (BT_INFO_HID|BT_INFO_A2DP|BT_INFO_FTP):
8772 if (bBtHsModeExist) {
8773 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8774 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8776 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8777 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8784 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = false\n"));
8785 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8788 pBtdm8723->curAlgorithm = algorithm;
8789 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8792 BTDM_CheckWiFiState(padapter);
8793 if (pBtMgnt->ExtConfig.bManualControl) {
8794 RTPRINT(FBT, BT_TRACE, ("Action Manual control, won't execute bt coexist mechanism!!\n"));
8799 void BTDM_2AntBtCoexist8723A(struct rtw_adapter *padapter)
8801 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8802 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8803 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
8804 u8 btInfoOriginal = 0;
8805 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8806 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8808 if (BTDM_BtProfileSupport(padapter)) {
8809 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8810 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8813 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8814 RTPRINT(FBT, BT_TRACE, ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8815 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8816 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8817 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8818 /* next time the coexist parameters should be reset again. */
8820 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8825 if (pBtDbg->dbgCtrl)
8826 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8828 pBtdm8723->curAlgorithm = btdm_ActionAlgorithm(padapter);
8829 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8831 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8832 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8833 pBtdm8723->bResetTdmaAdjust = true;
8835 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8836 RTPRINT(FBT, BT_TRACE, ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8837 pBtdm8723->preAlgorithm, pBtdm8723->curAlgorithm));
8838 pBtdm8723->bResetTdmaAdjust = true;
8840 switch (pBtdm8723->curAlgorithm) {
8841 case BT_2ANT_COEX_ALGO_SCO:
8842 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8843 btdm_2Ant8723ASCOAction(padapter);
8845 case BT_2ANT_COEX_ALGO_HID:
8846 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8847 btdm_2Ant8723AHIDAction(padapter);
8849 case BT_2ANT_COEX_ALGO_A2DP:
8850 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8851 btdm_2Ant8723AA2DPAction(padapter);
8853 case BT_2ANT_COEX_ALGO_PANEDR:
8854 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8855 btdm_2Ant8723APANEDRAction(padapter);
8857 case BT_2ANT_COEX_ALGO_PANHS:
8858 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8859 btdm_2Ant8723APANHSAction(padapter);
8861 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8862 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8863 btdm_2Ant8723APANEDRA2DPAction(padapter);
8865 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8866 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8867 btdm_2Ant8723APANEDRHIDAction(padapter);
8869 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8870 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8871 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8873 case BT_2ANT_COEX_ALGO_HID_A2DP:
8874 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8875 btdm_2Ant8723AHIDA2DPAction(padapter);
8878 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8879 btdm_2Ant8723AA2DPAction(padapter);
8882 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8885 RTPRINT(FBT, BT_TRACE, ("[BTCoex] Get bt info by fw!!\n"));
8886 /* msg shows c2h rsp for bt_info is received or not. */
8887 if (pHalData->bt_coexist.halCoex8723.bC2hBtInfoReqSent)
8888 RTPRINT(FBT, BT_TRACE, ("[BTCoex] c2h for btInfo not rcvd yet!!\n"));
8890 btInfoOriginal = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8892 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8893 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8896 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8897 RTPRINT(FBT, BT_TRACE,
8898 ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8899 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8900 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8901 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8902 /* next time the coexist parameters should be reset again. */
8904 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8909 if (pBtDbg->dbgCtrl)
8910 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8911 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8912 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8913 pBtdm8723->bResetTdmaAdjust = true;
8915 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8916 RTPRINT(FBT, BT_TRACE,
8917 ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8918 pBtdm8723->preAlgorithm,
8919 pBtdm8723->curAlgorithm));
8920 pBtdm8723->bResetTdmaAdjust = true;
8922 switch (pBtdm8723->curAlgorithm) {
8923 case BT_2ANT_COEX_ALGO_SCO:
8924 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8925 btdm_2Ant8723ASCOAction(padapter);
8927 case BT_2ANT_COEX_ALGO_HID:
8928 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8929 btdm_2Ant8723AHIDAction(padapter);
8931 case BT_2ANT_COEX_ALGO_A2DP:
8932 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8933 btdm_2Ant8723AA2dp(padapter);
8935 case BT_2ANT_COEX_ALGO_PANEDR:
8936 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8937 btdm_2Ant8723APANEDRAction(padapter);
8939 case BT_2ANT_COEX_ALGO_PANHS:
8940 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8941 btdm_2Ant8723APANHSAction(padapter);
8943 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8944 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8945 btdm_2Ant8723APANEDRA2DPAction(padapter);
8947 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8948 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8949 btdm_2Ant8723APANEDRHIDAction(padapter);
8951 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8952 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8953 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8955 case BT_2ANT_COEX_ALGO_HID_A2DP:
8956 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8957 btdm_2Ant8723AHIDA2DPAction(padapter);
8960 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8961 btdm_2Ant8723AA2DPAction(padapter);
8964 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8969 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
8971 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
8973 static u8 btCoexDbgBuf[BT_TMP_BUF_SIZE];
8975 static const char *const BtProfileString[] = {
8983 static const char *const BtSpecString[] = {
8993 static const char *const BtLinkRoleString[] = {
8998 static u8 btdm_BtWifiAntNum(struct rtw_adapter *padapter)
9000 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9001 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9003 if (Ant_x2 == pHalData->bt_coexist.BT_Ant_Num) {
9004 if (Ant_x2 == pBtCoex->TotalAntNum)
9014 static void btdm_BtHwCountersMonitor(struct rtw_adapter *padapter)
9016 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9017 u32 regHPTxRx, regLPTxRx, u4Tmp;
9018 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
9020 regHPTxRx = REG_HIGH_PRIORITY_TXRX;
9021 regLPTxRx = REG_LOW_PRIORITY_TXRX;
9023 u4Tmp = rtl8723au_read32(padapter, regHPTxRx);
9024 regHPTx = u4Tmp & bMaskLWord;
9025 regHPRx = (u4Tmp & bMaskHWord)>>16;
9027 u4Tmp = rtl8723au_read32(padapter, regLPTxRx);
9028 regLPTx = u4Tmp & bMaskLWord;
9029 regLPRx = (u4Tmp & bMaskHWord)>>16;
9031 pHalData->bt_coexist.halCoex8723.highPriorityTx = regHPTx;
9032 pHalData->bt_coexist.halCoex8723.highPriorityRx = regHPRx;
9033 pHalData->bt_coexist.halCoex8723.lowPriorityTx = regLPTx;
9034 pHalData->bt_coexist.halCoex8723.lowPriorityRx = regLPRx;
9036 RTPRINT(FBT, BT_TRACE, ("High Priority Tx/Rx = %d / %d\n", regHPTx, regHPRx));
9037 RTPRINT(FBT, BT_TRACE, ("Low Priority Tx/Rx = %d / %d\n", regLPTx, regLPRx));
9040 rtl8723au_write8(padapter, 0x76e, 0xc);
9043 /* This function check if 8723 bt is disabled */
9044 static void btdm_BtEnableDisableCheck8723A(struct rtw_adapter *padapter)
9047 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9049 #ifdef CHECK_BT_EXIST_FROM_REG
9052 /* ox68[28]= 1 => BT enable; otherwise disable */
9053 val8 = rtl8723au_read8(padapter, 0x6B);
9054 if (!(val8 & BIT(4)))
9058 pHalData->bt_coexist.bCurBtDisabled = false;
9060 pHalData->bt_coexist.bCurBtDisabled = true;
9062 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0 &&
9063 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0 &&
9064 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0 &&
9065 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0)
9067 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xeaea &&
9068 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xeaea &&
9069 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xeaea &&
9070 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xeaea)
9072 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xffff &&
9073 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xffff &&
9074 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xffff &&
9075 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xffff)
9078 pHalData->bt_coexist.btActiveZeroCnt = 0;
9079 pHalData->bt_coexist.bCurBtDisabled = false;
9080 RTPRINT(FBT, BT_TRACE, ("8723A BT is enabled !!\n"));
9082 pHalData->bt_coexist.btActiveZeroCnt++;
9083 RTPRINT(FBT, BT_TRACE, ("8723A bt all counters = 0, %d times!!\n",
9084 pHalData->bt_coexist.btActiveZeroCnt));
9085 if (pHalData->bt_coexist.btActiveZeroCnt >= 2) {
9086 pHalData->bt_coexist.bCurBtDisabled = true;
9087 RTPRINT(FBT, BT_TRACE, ("8723A BT is disabled !!\n"));
9092 if (!pHalData->bt_coexist.bCurBtDisabled) {
9093 if (BTDM_IsWifiConnectionExist(padapter))
9094 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
9096 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_DISCONNECT);
9099 if (pHalData->bt_coexist.bPreBtDisabled !=
9100 pHalData->bt_coexist.bCurBtDisabled) {
9101 RTPRINT(FBT, BT_TRACE, ("8723A BT is from %s to %s!!\n",
9102 (pHalData->bt_coexist.bPreBtDisabled ? "disabled":"enabled"),
9103 (pHalData->bt_coexist.bCurBtDisabled ? "disabled":"enabled")));
9104 pHalData->bt_coexist.bPreBtDisabled = pHalData->bt_coexist.bCurBtDisabled;
9108 static void btdm_BTCoexist8723AHandler(struct rtw_adapter *padapter)
9110 struct hal_data_8723a *pHalData;
9112 pHalData = GET_HAL_DATA(padapter);
9114 if (btdm_BtWifiAntNum(padapter) == Ant_x2) {
9115 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2 Ant mechanism\n"));
9116 BTDM_2AntBtCoexist8723A(padapter);
9118 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1 Ant mechanism\n"));
9119 BTDM_1AntBtCoexist8723A(padapter);
9122 if (!BTDM_IsSameCoexistState(padapter)) {
9123 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x\n",
9124 pHalData->bt_coexist.PreviousState,
9125 pHalData->bt_coexist.CurrentState));
9126 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
9128 RTPRINT(FBT, BT_TRACE, ("["));
9129 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT30)
9130 RTPRINT(FBT, BT_TRACE, ("BT 3.0, "));
9131 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT20)
9132 RTPRINT(FBT, BT_TRACE, ("HT20, "));
9133 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT40)
9134 RTPRINT(FBT, BT_TRACE, ("HT40, "));
9135 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_LEGACY)
9136 RTPRINT(FBT, BT_TRACE, ("Legacy, "));
9137 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_LOW)
9138 RTPRINT(FBT, BT_TRACE, ("Rssi_Low, "));
9139 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_MEDIUM)
9140 RTPRINT(FBT, BT_TRACE, ("Rssi_Mid, "));
9141 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_HIGH)
9142 RTPRINT(FBT, BT_TRACE, ("Rssi_High, "));
9143 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_IDLE)
9144 RTPRINT(FBT, BT_TRACE, ("Wifi_Idle, "));
9145 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_UPLINK)
9146 RTPRINT(FBT, BT_TRACE, ("Wifi_Uplink, "));
9147 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_DOWNLINK)
9148 RTPRINT(FBT, BT_TRACE, ("Wifi_Downlink, "));
9149 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)
9150 RTPRINT(FBT, BT_TRACE, ("BT_idle, "));
9151 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_HID)
9152 RTPRINT(FBT, BT_TRACE, ("PRO_HID, "));
9153 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_A2DP)
9154 RTPRINT(FBT, BT_TRACE, ("PRO_A2DP, "));
9155 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_PAN)
9156 RTPRINT(FBT, BT_TRACE, ("PRO_PAN, "));
9157 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_SCO)
9158 RTPRINT(FBT, BT_TRACE, ("PRO_SCO, "));
9159 RTPRINT(FBT, BT_TRACE, ("]\n"));
9163 /* extern function start with BTDM_ */
9164 u32 BTDM_BtTxRxCounterH(struct rtw_adapter *padapter)
9166 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9169 counters = pHalData->bt_coexist.halCoex8723.highPriorityTx+
9170 pHalData->bt_coexist.halCoex8723.highPriorityRx;
9174 u32 BTDM_BtTxRxCounterL(struct rtw_adapter *padapter)
9176 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9179 counters = pHalData->bt_coexist.halCoex8723.lowPriorityTx+
9180 pHalData->bt_coexist.halCoex8723.lowPriorityRx ;
9184 void BTDM_SetFwChnlInfo(struct rtw_adapter *padapter, enum rt_media_status mstatus)
9186 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9187 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9188 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9189 u8 H2C_Parameter[3] = {0};
9193 if (RT_MEDIA_CONNECT == mstatus)
9194 H2C_Parameter[0] = 0x1; /* 0: disconnected, 1:connected */
9196 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) {
9198 chnl = pmlmeext->cur_channel;
9199 if (BTDM_IsHT40(padapter)) {
9200 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
9202 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
9205 H2C_Parameter[1] = chnl;
9206 } else { /* check if HS link is exists */
9208 if (BT_Operation(padapter))
9209 H2C_Parameter[1] = pBtMgnt->BTChannel;
9211 H2C_Parameter[1] = pmlmeext->cur_channel;
9214 if (BTDM_IsHT40(padapter))
9215 H2C_Parameter[2] = 0x30;
9217 H2C_Parameter[2] = 0x20;
9219 FillH2CCmd(padapter, 0x19, 3, H2C_Parameter);
9222 u8 BTDM_IsWifiConnectionExist(struct rtw_adapter *padapter)
9226 if (BTHCI_HsConnectionEstablished(padapter))
9229 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true)
9236 struct rtw_adapter *padapter,
9244 u8 H2C_Parameter[5] = {0};
9246 if (rtl8723a_BT_using_antenna_1(padapter)) {
9247 if ((!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
9248 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
9249 /* for softap mode */
9250 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9251 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9252 u8 BtState = pBtCoex->c2hBtInfo;
9254 if ((BtState != BT_INFO_STATE_NO_CONNECTION) &&
9255 (BtState != BT_INFO_STATE_CONNECT_IDLE)) {
9256 if (byte1 & BIT(4)) {
9268 H2C_Parameter[0] = byte1;
9269 H2C_Parameter[1] = byte2;
9270 H2C_Parameter[2] = byte3;
9271 H2C_Parameter[3] = byte4;
9272 H2C_Parameter[4] = byte5;
9274 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%02x%08x\n",
9276 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
9278 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
9281 void BTDM_QueryBtInformation(struct rtw_adapter *padapter)
9283 u8 H2C_Parameter[1] = {0};
9284 struct hal_data_8723a *pHalData;
9285 struct bt_coexist_8723a *pBtCoex;
9287 pHalData = GET_HAL_DATA(padapter);
9288 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9290 if (!rtl8723a_BT_enabled(padapter)) {
9291 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9292 pBtCoex->bC2hBtInfoReqSent = false;
9296 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9297 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9299 if (pBtCoex->bC2hBtInfoReqSent == true)
9300 RTPRINT(FBT, BT_TRACE, ("[BTCoex], didn't recv previous BtInfo report!\n"));
9302 pBtCoex->bC2hBtInfoReqSent = true;
9304 H2C_Parameter[0] |= BIT(0); /* trigger */
9306 /*RTPRINT(FBT, BT_TRACE, ("[BTCoex], Query Bt information, write 0x38 = 0x%x\n", */
9307 /*H2C_Parameter[0])); */
9309 FillH2CCmd(padapter, 0x38, 1, H2C_Parameter);
9312 void BTDM_SetSwRfRxLpfCorner(struct rtw_adapter *padapter, u8 type)
9314 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9316 if (BT_RF_RX_LPF_CORNER_SHRINK == type) {
9317 /* Shrink RF Rx LPF corner */
9318 RTPRINT(FBT, BT_TRACE, ("Shrink RF Rx LPF corner!!\n"));
9319 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, 0xf0ff7);
9320 pHalData->bt_coexist.bSWCoexistAllOff = false;
9321 } else if (BT_RF_RX_LPF_CORNER_RESUME == type) {
9322 /* Resume RF Rx LPF corner */
9323 RTPRINT(FBT, BT_TRACE, ("Resume RF Rx LPF corner!!\n"));
9324 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, pHalData->bt_coexist.BtRfRegOrigin1E);
9329 BTDM_SetSwPenaltyTxRateAdaptive(
9330 struct rtw_adapter *padapter,
9334 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9337 tmpU1 = rtl8723au_read8(padapter, 0x4fd);
9339 if (BT_TX_RATE_ADAPTIVE_LOW_PENALTY == raType) {
9341 pHalData->bt_coexist.bSWCoexistAllOff = false;
9342 } else if (BT_TX_RATE_ADAPTIVE_NORMAL == raType) {
9346 rtl8723au_write8(padapter, 0x4fd, tmpU1);
9349 void BTDM_SetFwDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
9351 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9352 u8 H2C_Parameter[1] = {0};
9354 H2C_Parameter[0] = 0;
9357 H2C_Parameter[0] |= BIT(1);
9358 pHalData->bt_coexist.bFWCoexistAllOff = false;
9361 RTPRINT(FBT, BT_TRACE, ("[BTCoex], decrease Bt Power : %s, write 0x21 = 0x%x\n",
9362 (bDecBtPwr ? "Yes!!" : "No!!"), H2C_Parameter[0]));
9364 FillH2CCmd(padapter, 0x21, 1, H2C_Parameter);
9367 u8 BTDM_BtProfileSupport(struct rtw_adapter *padapter)
9370 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9371 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9372 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9374 if (pBtMgnt->bSupportProfile &&
9375 !pHalData->bt_coexist.halCoex8723.bForceFwBtInfo)
9381 static void BTDM_AdjustForBtOperation8723A(struct rtw_adapter *padapter)
9383 /* BTDM_2AntAdjustForBtOperation8723(padapter); */
9386 static void BTDM_FwC2hBtRssi8723A(struct rtw_adapter *padapter, u8 *tmpBuf)
9388 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9389 u8 percent = 0, u1tmp = 0;
9392 percent = u1tmp*2+10;
9394 pHalData->bt_coexist.halCoex8723.btRssi = percent;
9395 /*RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", percent)); */
9399 rtl8723a_fw_c2h_BT_info(struct rtw_adapter *padapter, u8 *tmpBuf, u8 length)
9401 struct hal_data_8723a *pHalData;
9402 struct bt_30info *pBTInfo;
9403 struct bt_mgnt *pBtMgnt;
9404 struct bt_coexist_8723a *pBtCoex;
9407 pHalData = GET_HAL_DATA(padapter);
9408 pBTInfo = GET_BT_INFO(padapter);
9409 pBtMgnt = &pBTInfo->BtMgnt;
9410 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9412 pBtCoex->bC2hBtInfoReqSent = false;
9414 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT info[%d]=[", length));
9416 pBtCoex->btRetryCnt = 0;
9417 for (i = 0; i < length; i++) {
9420 pBtCoex->c2hBtInfoOriginal = tmpBuf[i];
9423 pBtCoex->btRetryCnt = tmpBuf[i];
9426 BTDM_FwC2hBtRssi8723A(padapter, &tmpBuf[i]);
9429 pBtCoex->btInfoExt = tmpBuf[i]&BIT(0);
9434 RTPRINT(FBT, BT_TRACE, ("0x%02x]\n", tmpBuf[i]));
9436 RTPRINT(FBT, BT_TRACE, ("0x%02x, ", tmpBuf[i]));
9438 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", pBtCoex->btRssi));
9439 if (pBtCoex->btInfoExt)
9440 RTPRINT(FBT, BT_TRACE, ("[BTC2H], pBtCoex->btInfoExt =%x\n", pBtCoex->btInfoExt));
9442 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9443 BTDM_1AntFwC2hBtInfo8723A(padapter);
9445 BTDM_2AntFwC2hBtInfo8723A(padapter);
9447 if (pBtMgnt->ExtConfig.bManualControl) {
9448 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9452 btdm_BTCoexist8723AHandler(padapter);
9455 static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
9457 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9458 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9459 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9460 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9461 u8 u1Tmp, u1Tmp1, u1Tmp2, i, btInfoExt, psTdmaCase = 0;
9465 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
9466 DCMD_Printf(btCoexDbgBuf);
9468 if (!rtl8723a_BT_coexist(padapter)) {
9469 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");
9470 DCMD_Printf(btCoexDbgBuf);
9474 antNum = btdm_BtWifiAntNum(padapter);
9475 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/%d ", "Ant mechanism PG/Now run :", \
9476 ((pHalData->bt_coexist.BT_Ant_Num == Ant_x2) ? 2 : 1), ((antNum == Ant_x2) ? 2 : 1));
9477 DCMD_Printf(btCoexDbgBuf);
9479 if (pBtMgnt->ExtConfig.bManualControl) {
9480 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
9481 DCMD_Printf(btCoexDbgBuf);
9483 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
9484 ((pBtMgnt->bSupportProfile) ? "Yes" : "No"), pBtMgnt->ExtConfig.HCIExtensionVer);
9485 DCMD_Printf(btCoexDbgBuf);
9488 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = / %d", "Dot11 channel / BT channel", \
9489 pBtMgnt->BTChannel);
9490 DCMD_Printf(btCoexDbgBuf);
9492 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %d / %d / %d", "Wifi/BT/HS rssi", \
9493 BTDM_GetRxSS(padapter),
9494 pHalData->bt_coexist.halCoex8723.btRssi,
9495 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB);
9496 DCMD_Printf(btCoexDbgBuf);
9498 if (!pBtMgnt->ExtConfig.bManualControl) {
9499 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %s / %s ", "WIfi status",
9500 ((BTDM_Legacy(padapter)) ? "Legacy" : (((BTDM_IsHT40(padapter)) ? "HT40" : "HT20"))),
9501 ((!BTDM_IsWifiBusy(padapter)) ? "idle" : ((BTDM_IsWifiUplink(padapter)) ? "uplink" : "downlink")));
9502 DCMD_Printf(btCoexDbgBuf);
9504 if (pBtMgnt->bSupportProfile) {
9505 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
9506 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_SCO)) ? 1 : 0),
9507 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) ? 1 : 0),
9508 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) ? 1 : 0),
9509 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) ? 1 : 0));
9510 DCMD_Printf(btCoexDbgBuf);
9512 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
9513 if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
9514 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role",
9515 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9516 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec],
9517 BtLinkRoleString[pBtMgnt->ExtConfig.linkInfo[i].linkRole]);
9518 DCMD_Printf(btCoexDbgBuf);
9520 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
9521 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "A2DP rate", \
9522 (btInfoExt & BIT(0)) ?
9523 "Basic rate" : "EDR rate");
9524 DCMD_Printf(btCoexDbgBuf);
9526 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
9527 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9528 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec]);
9529 DCMD_Printf(btCoexDbgBuf);
9536 if (!pBtMgnt->ExtConfig.bManualControl) {
9537 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw BT Coex mechanism]============");
9538 DCMD_Printf(btCoexDbgBuf);
9539 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "AGC Table", \
9540 pBtCoex->btdm2Ant.bCurAgcTableEn);
9541 DCMD_Printf(btCoexDbgBuf);
9542 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "ADC Backoff", \
9543 pBtCoex->btdm2Ant.bCurAdcBackOff);
9544 DCMD_Printf(btCoexDbgBuf);
9545 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Low penalty RA", \
9546 pBtCoex->btdm2Ant.bCurLowPenaltyRa);
9547 DCMD_Printf(btCoexDbgBuf);
9548 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "RF Rx LPF Shrink", \
9549 pBtCoex->btdm2Ant.bCurRfRxLpfShrink);
9550 DCMD_Printf(btCoexDbgBuf);
9552 u4Tmp[0] = PHY_QueryRFReg(padapter, PathA, 0x1e, 0xff0);
9553 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "RF-A, 0x1e[11:4]/original val", \
9554 u4Tmp[0], pHalData->bt_coexist.BtRfRegOrigin1E);
9555 DCMD_Printf(btCoexDbgBuf);
9558 if (!pBtMgnt->ExtConfig.bManualControl) {
9559 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw BT Coex mechanism]============");
9560 DCMD_Printf(btCoexDbgBuf);
9562 if (!pBtMgnt->ExtConfig.bManualControl) {
9563 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9564 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm1Ant.curPsTdma;
9566 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm2Ant.curPsTdma;
9567 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA(0x3a)", \
9568 pHalData->bt_coexist.fw3aVal[0], pHalData->bt_coexist.fw3aVal[1],
9569 pHalData->bt_coexist.fw3aVal[2], pHalData->bt_coexist.fw3aVal[3],
9570 pHalData->bt_coexist.fw3aVal[4], psTdmaCase);
9571 DCMD_Printf(btCoexDbgBuf);
9573 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Decrease Bt Power", \
9574 pBtCoex->btdm2Ant.bCurDecBtPwr);
9575 DCMD_Printf(btCoexDbgBuf);
9577 u1Tmp = rtl8723au_read8(padapter, 0x778);
9578 u1Tmp1 = rtl8723au_read8(padapter, 0x783);
9579 u1Tmp2 = rtl8723au_read8(padapter, 0x796);
9580 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
9581 u1Tmp, u1Tmp1, u1Tmp2);
9582 DCMD_Printf(btCoexDbgBuf);
9584 if (!pBtMgnt->ExtConfig.bManualControl) {
9585 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "Sw DacSwing Ctrl/Val", \
9586 pBtCoex->btdm2Ant.bCurDacSwingOn, pBtCoex->btdm2Ant.curDacSwingLvl);
9587 DCMD_Printf(btCoexDbgBuf);
9589 u4Tmp[0] = rtl8723au_read32(padapter, 0x880);
9590 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \
9592 DCMD_Printf(btCoexDbgBuf);
9595 if (!pBtMgnt->ExtConfig.bManualControl) {
9596 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw BT Coex mechanism]============");
9597 DCMD_Printf(btCoexDbgBuf);
9600 u1Tmp = rtl8723au_read8(padapter, 0x40);
9601 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
9603 DCMD_Printf(btCoexDbgBuf);
9605 u4Tmp[0] = rtl8723au_read32(padapter, 0x550);
9606 u1Tmp = rtl8723au_read8(padapter, 0x522);
9607 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x", "0x550(bcn contrl)/0x522", \
9609 DCMD_Printf(btCoexDbgBuf);
9611 u4Tmp[0] = rtl8723au_read32(padapter, 0x484);
9612 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
9614 DCMD_Printf(btCoexDbgBuf);
9616 u4Tmp[0] = rtl8723au_read32(padapter, 0x50);
9617 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
9619 DCMD_Printf(btCoexDbgBuf);
9621 u4Tmp[0] = rtl8723au_read32(padapter, 0xda0);
9622 u4Tmp[1] = rtl8723au_read32(padapter, 0xda4);
9623 u4Tmp[2] = rtl8723au_read32(padapter, 0xda8);
9624 u4Tmp[3] = rtl8723au_read32(padapter, 0xdac);
9625 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
9626 u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);
9627 DCMD_Printf(btCoexDbgBuf);
9629 u4Tmp[0] = rtl8723au_read32(padapter, 0x6c0);
9630 u4Tmp[1] = rtl8723au_read32(padapter, 0x6c4);
9631 u4Tmp[2] = rtl8723au_read32(padapter, 0x6c8);
9632 u1Tmp = rtl8723au_read8(padapter, 0x6cc);
9633 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
9634 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp);
9635 DCMD_Printf(btCoexDbgBuf);
9637 /* u4Tmp = rtl8723au_read32(padapter, 0x770); */
9638 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x770(Hi pri Rx[31:16]/Tx[15:0])", \
9639 pHalData->bt_coexist.halCoex8723.highPriorityRx,
9640 pHalData->bt_coexist.halCoex8723.highPriorityTx);
9641 DCMD_Printf(btCoexDbgBuf);
9642 /* u4Tmp = rtl8723au_read32(padapter, 0x774); */
9643 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x774(Lo pri Rx[31:16]/Tx[15:0])", \
9644 pHalData->bt_coexist.halCoex8723.lowPriorityRx,
9645 pHalData->bt_coexist.halCoex8723.lowPriorityTx);
9646 DCMD_Printf(btCoexDbgBuf);
9648 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang */
9649 u1Tmp = rtl8723au_read8(padapter, 0x41b);
9650 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x41b (hang chk == 0xf)", \
9652 DCMD_Printf(btCoexDbgBuf);
9653 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
9654 pHalData->LastHMEBoxNum);
9655 DCMD_Printf(btCoexDbgBuf);
9659 BTDM_8723ASignalCompensation(struct rtw_adapter *padapter,
9660 u8 *rssi_wifi, u8 *rssi_bt)
9662 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9663 BTDM_1AntSignalCompensation(padapter, rssi_wifi, rssi_bt);
9666 static void BTDM_8723AInit(struct rtw_adapter *padapter)
9668 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9669 BTDM_2AntParaInit(padapter);
9671 BTDM_1AntParaInit(padapter);
9674 static void BTDM_HWCoexAllOff8723A(struct rtw_adapter *padapter)
9676 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9677 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9679 if (pBtMgnt->ExtConfig.bManualControl)
9682 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9683 BTDM_2AntHwCoexAllOff8723A(padapter);
9686 static void BTDM_FWCoexAllOff8723A(struct rtw_adapter *padapter)
9688 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9689 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9691 if (pBtMgnt->ExtConfig.bManualControl)
9694 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9695 BTDM_2AntFwCoexAllOff8723A(padapter);
9698 static void BTDM_SWCoexAllOff8723A(struct rtw_adapter *padapter)
9700 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9701 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9703 if (pBtMgnt->ExtConfig.bManualControl)
9706 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9707 BTDM_2AntSwCoexAllOff8723A(padapter);
9711 BTDM_Set8723ABtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
9713 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9714 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9717 pBtCoex->TotalAntNum = Ant_x1;
9718 else if (antNum == 2)
9719 pBtCoex->TotalAntNum = Ant_x2;
9722 void rtl8723a_BT_lps_leave(struct rtw_adapter *padapter)
9724 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9725 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9727 if (pBtMgnt->ExtConfig.bManualControl)
9730 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9731 BTDM_1AntLpsLeave(padapter);
9734 static void BTDM_ForHalt8723A(struct rtw_adapter *padapter)
9736 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9737 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9739 if (pBtMgnt->ExtConfig.bManualControl)
9742 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9743 BTDM_1AntForHalt(padapter);
9746 static void BTDM_WifiScanNotify8723A(struct rtw_adapter *padapter, u8 scanType)
9748 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9749 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9751 if (pBtMgnt->ExtConfig.bManualControl)
9754 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9755 BTDM_1AntWifiScanNotify(padapter, scanType);
9759 BTDM_WifiAssociateNotify8723A(struct rtw_adapter *padapter, u8 action)
9761 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9762 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9764 if (pBtMgnt->ExtConfig.bManualControl)
9767 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9768 BTDM_1AntWifiAssociateNotify(padapter, action);
9772 BTDM_MediaStatusNotify8723A(struct rtw_adapter *padapter,
9773 enum rt_media_status mstatus)
9775 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9776 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9778 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatusNotify, %s\n",
9779 mstatus?"connect":"disconnect"));
9781 BTDM_SetFwChnlInfo(padapter, mstatus);
9783 if (pBtMgnt->ExtConfig.bManualControl)
9786 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9787 BTDM_1AntMediaStatusNotify(padapter, mstatus);
9790 static void BTDM_ForDhcp8723A(struct rtw_adapter *padapter)
9792 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9793 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9795 if (pBtMgnt->ExtConfig.bManualControl)
9798 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9799 BTDM_1AntForDhcp(padapter);
9802 bool rtl8723a_BT_using_antenna_1(struct rtw_adapter *padapter)
9804 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9810 static void BTDM_BTCoexist8723A(struct rtw_adapter *padapter)
9812 struct hal_data_8723a *pHalData;
9813 struct bt_30info *pBTInfo;
9814 struct bt_mgnt *pBtMgnt;
9815 struct bt_coexist_8723a *pBtCoex;
9817 pHalData = GET_HAL_DATA(padapter);
9818 pBTInfo = GET_BT_INFO(padapter);
9819 pBtMgnt = &pBTInfo->BtMgnt;
9820 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9822 RTPRINT(FBT, BT_TRACE, ("[BTCoex], beacon RSSI = 0x%x(%d)\n",
9823 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB,
9824 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB));
9826 btdm_BtHwCountersMonitor(padapter);
9827 btdm_BtEnableDisableCheck8723A(padapter);
9829 if (pBtMgnt->ExtConfig.bManualControl) {
9830 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9834 if (pBtCoex->bC2hBtInfoReqSent) {
9835 if (!rtl8723a_BT_enabled(padapter)) {
9836 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9838 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9839 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9842 btdm_BTCoexist8723AHandler(padapter);
9843 } else if (!rtl8723a_BT_enabled(padapter)) {
9844 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9845 btdm_BTCoexist8723AHandler(padapter);
9848 BTDM_QueryBtInformation(padapter);
9851 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
9853 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
9855 /* local function start with btdm_ */
9856 /* extern function start with BTDM_ */
9858 static void BTDM_SetAntenna(struct rtw_adapter *padapter, u8 who)
9864 struct rtw_adapter *padapter,
9870 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9871 u8 H2C_Parameter[3] = {0};
9873 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9876 H2C_Parameter[2] = 0;
9877 H2C_Parameter[1] = 0;
9878 H2C_Parameter[0] = 0;
9881 H2C_Parameter[2] |= 0x02; /* BIT1 */
9882 pHalData->bt_coexist.bFWCoexistAllOff = false;
9884 pHalData->bt_coexist.bInterruptOn = bInterruptOn;
9887 H2C_Parameter[2] |= 0x10; /* BIT4 */
9888 pHalData->bt_coexist.bFWCoexistAllOff = false;
9890 pHalData->bt_coexist.bSingleAntOn = bSingleAntOn;
9893 H2C_Parameter[2] |= 0x20; /* BIT5 */
9894 pHalData->bt_coexist.bFWCoexistAllOff = false;
9896 pHalData->bt_coexist.bMultiNAVOn = bMultiNAVOn;
9898 RTPRINT(FBT, BT_TRACE, ("[DM][BT], SingleAntenna =[%s:%s:%s], write 0xe = 0x%x\n",
9899 bSingleAntOn?"ON":"OFF", bInterruptOn?"ON":"OFF", bMultiNAVOn?"ON":"OFF",
9900 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
9903 void BTDM_CheckBTIdleChange1Ant(struct rtw_adapter *padapter)
9905 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9906 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9907 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9908 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
9909 u8 stateChange = false;
9910 u32 BT_Polling, Ratio_Act, Ratio_STA;
9911 u32 BT_Active, BT_State;
9912 u32 regBTActive = 0, regBTState = 0, regBTPolling = 0;
9914 if (!rtl8723a_BT_coexist(padapter))
9916 if (pBtMgnt->ExtConfig.bManualControl)
9918 if (pHalData->bt_coexist.BT_CoexistType != BT_CSR_BC8)
9920 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9923 /* The following we only consider CSR BC8 and fw version should be >= 62 */
9924 RTPRINT(FBT, BT_TRACE, ("[DM][BT], FirmwareVersion = 0x%x(%d)\n",
9925 pHalData->FirmwareVersion, pHalData->FirmwareVersion));
9926 regBTActive = REG_BT_ACTIVE;
9927 regBTState = REG_BT_STATE;
9928 if (pHalData->FirmwareVersion >= FW_VER_BT_REG1)
9929 regBTPolling = REG_BT_POLLING1;
9931 regBTPolling = REG_BT_POLLING;
9933 BT_Active = rtl8723au_read32(padapter, regBTActive);
9934 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Active(0x%x) =%x\n", regBTActive, BT_Active));
9935 BT_Active = BT_Active & 0x00ffffff;
9937 BT_State = rtl8723au_read32(padapter, regBTState);
9938 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_State(0x%x) =%x\n", regBTState, BT_State));
9939 BT_State = BT_State & 0x00ffffff;
9941 BT_Polling = rtl8723au_read32(padapter, regBTPolling);
9942 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Polling(0x%x) =%x\n", regBTPolling, BT_Polling));
9944 if (BT_Active == 0xffffffff && BT_State == 0xffffffff && BT_Polling == 0xffffffff)
9946 if (BT_Polling == 0)
9949 Ratio_Act = BT_Active*1000/BT_Polling;
9950 Ratio_STA = BT_State*1000/BT_Polling;
9952 pHalData->bt_coexist.Ratio_Tx = Ratio_Act;
9953 pHalData->bt_coexist.Ratio_PRI = Ratio_STA;
9955 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_Act =%d\n", Ratio_Act));
9956 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_STA =%d\n", Ratio_STA));
9958 if (Ratio_STA < 60 && Ratio_Act < 500) { /* BT PAN idle */
9959 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_IDLE;
9960 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9961 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9963 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_IDLE;
9966 /* Check if BT PAN (under BT 2.1) is uplink or downlink */
9967 if ((Ratio_Act/Ratio_STA) < 2) {
9969 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = true;
9970 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_UPLINK;
9971 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = false;
9972 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9974 /* BT PAN downlink */
9975 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9976 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9977 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9978 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9981 /* BT PAN downlink */
9982 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9983 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9984 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9985 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9989 /* Check BT is idle or not */
9990 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9991 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9992 pBtMgnt->ExtConfig.bBTBusy = false;
9993 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9995 if (Ratio_STA < 60) {
9996 pBtMgnt->ExtConfig.bBTBusy = false;
9997 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9999 pBtMgnt->ExtConfig.bBTBusy = true;
10000 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_IDLE;
10004 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
10005 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
10006 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
10007 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
10008 BTDM_SetAntenna(padapter, BTDM_ANT_BT_IDLE);
10010 if (pBtMgnt->ExtConfig.MIN_BT_RSSI <= -5) {
10011 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_RSSI_LOW;
10012 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Low\n"));
10014 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
10015 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Normal\n"));
10019 if (pHalData->bt_coexist.bBTBusyTraffic != pBtMgnt->ExtConfig.bBTBusy) {
10020 /* BT idle or BT non-idle */
10021 pHalData->bt_coexist.bBTBusyTraffic = pBtMgnt->ExtConfig.bBTBusy;
10022 stateChange = true;
10026 if (!pBtMgnt->ExtConfig.bBTBusy)
10027 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
10029 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is non-idle\n"));
10031 if (!pBtMgnt->ExtConfig.bBTBusy) {
10032 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
10033 if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING|WIFI_SITE_MONITOR) == true)
10034 BTDM_SetAntenna(padapter, BTDM_ANT_WIFI);
10038 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
10040 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
10042 /* local function start with btdm_ */
10045 /* In the following, FW should be done before SW mechanism. */
10046 /* BTDM_Balance(), BTDM_DiminishWiFi(), BT_NAV() should be done */
10047 /* before BTDM_AGCTable(), BTDM_BBBackOffLevel(), btdm_DacSwing(). */
10049 /* extern function start with BTDM_ */
10053 struct rtw_adapter *padapter,
10060 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10061 u8 H2C_Parameter[3] = {0};
10063 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x2)
10066 if ((pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_RSSI_LOW) &&
10067 (DACSwingLevel == 0x20)) {
10068 RTPRINT(FBT, BT_TRACE, ("[BT]DiminishWiFi 0x20 original, but set 0x18 for Low RSSI!\n"));
10069 DACSwingLevel = 0x18;
10072 H2C_Parameter[2] = 0;
10073 H2C_Parameter[1] = DACSwingLevel;
10074 H2C_Parameter[0] = 0;
10076 H2C_Parameter[2] |= 0x01; /* BIT0 */
10078 H2C_Parameter[2] |= 0x02; /* BIT1 */
10079 pHalData->bt_coexist.bFWCoexistAllOff = false;
10082 H2C_Parameter[2] |= 0x08; /* BIT3 */
10083 pHalData->bt_coexist.bFWCoexistAllOff = false;
10086 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bDACOn = %s, bInterruptOn = %s, write 0xe = 0x%x\n",
10087 bDACOn?"ON":"OFF", bInterruptOn?"ON":"OFF",
10088 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10089 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bNAVOn = %s\n",
10090 bNAVOn?"ON":"OFF"));
10093 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
10095 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
10097 /* local function */
10098 static void btdm_ResetFWCoexState(struct rtw_adapter *padapter)
10100 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10102 pHalData->bt_coexist.CurrentState = 0;
10103 pHalData->bt_coexist.PreviousState = 0;
10106 static void btdm_InitBtCoexistDM(struct rtw_adapter *padapter)
10108 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10110 /* 20100415 Joseph: Restore RF register 0x1E and 0x1F value for further usage. */
10111 pHalData->bt_coexist.BtRfRegOrigin1E = PHY_QueryRFReg(padapter, PathA, RF_RCK1, bRFRegOffsetMask);
10112 pHalData->bt_coexist.BtRfRegOrigin1F = PHY_QueryRFReg(padapter, PathA, RF_RCK2, 0xf0);
10114 pHalData->bt_coexist.CurrentState = 0;
10115 pHalData->bt_coexist.PreviousState = 0;
10117 BTDM_8723AInit(padapter);
10118 pHalData->bt_coexist.bInitlized = true;
10122 /* extern function */
10124 void BTDM_CheckAntSelMode(struct rtw_adapter *padapter)
10128 void BTDM_FwC2hBtRssi(struct rtw_adapter *padapter, u8 *tmpBuf)
10130 BTDM_FwC2hBtRssi8723A(padapter, tmpBuf);
10133 void BTDM_DisplayBtCoexInfo(struct rtw_adapter *padapter)
10135 BTDM_Display8723ABtCoexInfo(padapter);
10138 void BTDM_RejectAPAggregatedPacket(struct rtw_adapter *padapter, u8 bReject)
10142 u8 BTDM_IsHT40(struct rtw_adapter *padapter)
10145 enum ht_channel_width bw;
10147 bw = padapter->mlmeextpriv.cur_bwmode;
10149 if (bw == HT_CHANNEL_WIDTH_20)
10151 else if (bw == HT_CHANNEL_WIDTH_40)
10157 u8 BTDM_Legacy(struct rtw_adapter *padapter)
10159 struct mlme_ext_priv *pmlmeext;
10160 u8 isLegacy = false;
10162 pmlmeext = &padapter->mlmeextpriv;
10163 if ((pmlmeext->cur_wireless_mode == WIRELESS_11B) ||
10164 (pmlmeext->cur_wireless_mode == WIRELESS_11G) ||
10165 (pmlmeext->cur_wireless_mode == WIRELESS_11BG))
10171 void BTDM_CheckWiFiState(struct rtw_adapter *padapter)
10173 struct hal_data_8723a *pHalData;
10174 struct mlme_priv *pmlmepriv;
10175 struct bt_30info *pBTInfo;
10176 struct bt_mgnt *pBtMgnt;
10178 pHalData = GET_HAL_DATA(padapter);
10179 pmlmepriv = &padapter->mlmepriv;
10180 pBTInfo = GET_BT_INFO(padapter);
10181 pBtMgnt = &pBTInfo->BtMgnt;
10183 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
10184 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_IDLE;
10186 if (pmlmepriv->LinkDetectInfo.bTxBusyTraffic)
10187 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_UPLINK;
10189 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10191 if (pmlmepriv->LinkDetectInfo.bRxBusyTraffic)
10192 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_DOWNLINK;
10194 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10196 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_IDLE;
10197 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10198 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10201 if (BTDM_Legacy(padapter)) {
10202 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_LEGACY;
10203 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10204 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10206 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_LEGACY;
10207 if (BTDM_IsHT40(padapter)) {
10208 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT40;
10209 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10211 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT20;
10212 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10216 if (pBtMgnt->BtOperationOn)
10217 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT30;
10219 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT30;
10222 s32 BTDM_GetRxSS(struct rtw_adapter *padapter)
10224 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10225 struct mlme_priv *pmlmepriv;
10226 struct hal_data_8723a *pHalData;
10227 s32 UndecoratedSmoothedPWDB = 0;
10229 pmlmepriv = &padapter->mlmepriv;
10230 pHalData = GET_HAL_DATA(padapter);
10232 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10233 UndecoratedSmoothedPWDB = GET_UNDECORATED_AVERAGE_RSSI(padapter);
10234 } else { /* associated entry pwdb */
10235 UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10236 /* pHalData->BT_EntryMinUndecoratedSmoothedPWDB */
10238 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxSS() = %d\n", UndecoratedSmoothedPWDB));
10239 return UndecoratedSmoothedPWDB;
10242 static s32 BTDM_GetRxBeaconSS(struct rtw_adapter *padapter)
10244 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10245 struct mlme_priv *pmlmepriv;
10246 struct hal_data_8723a *pHalData;
10247 s32 pwdbBeacon = 0;
10249 pmlmepriv = &padapter->mlmepriv;
10250 pHalData = GET_HAL_DATA(padapter);
10252 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10253 /* pwdbBeacon = pHalData->dmpriv.UndecoratedSmoothedBeacon; */
10254 pwdbBeacon = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10256 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxBeaconSS() = %d\n", pwdbBeacon));
10260 /* Get beacon rssi state */
10261 u8 BTDM_CheckCoexBcnRssiState(struct rtw_adapter *padapter, u8 levelNum,
10262 u8 RssiThresh, u8 RssiThresh1)
10264 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10265 s32 pwdbBeacon = 0;
10266 u8 bcnRssiState = 0;
10268 pwdbBeacon = BTDM_GetRxBeaconSS(padapter);
10270 if (levelNum == 2) {
10271 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10273 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10274 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10275 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10276 bcnRssiState = BT_RSSI_STATE_HIGH;
10277 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10278 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10279 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10281 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10282 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10285 if (pwdbBeacon < RssiThresh) {
10286 bcnRssiState = BT_RSSI_STATE_LOW;
10287 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10288 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10289 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10291 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10292 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10295 } else if (levelNum == 3) {
10296 if (RssiThresh > RssiThresh1) {
10297 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON thresh error!!\n"));
10298 return pHalData->bt_coexist.preRssiStateBeacon;
10301 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10302 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10303 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10304 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10305 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10306 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10307 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10308 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10310 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10311 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10313 } else if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_MEDIUM) ||
10314 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_MEDIUM)) {
10315 if (pwdbBeacon >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10316 bcnRssiState = BT_RSSI_STATE_HIGH;
10317 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10318 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10319 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10320 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10321 } else if (pwdbBeacon < RssiThresh) {
10322 bcnRssiState = BT_RSSI_STATE_LOW;
10323 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10324 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10325 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10326 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10328 bcnRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10329 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Medium\n"));
10332 if (pwdbBeacon < RssiThresh1) {
10333 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10334 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10335 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10336 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10337 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10339 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10340 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10345 pHalData->bt_coexist.preRssiStateBeacon = bcnRssiState;
10347 return bcnRssiState;
10350 u8 BTDM_CheckCoexRSSIState1(struct rtw_adapter *padapter, u8 levelNum,
10351 u8 RssiThresh, u8 RssiThresh1)
10353 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10354 s32 UndecoratedSmoothedPWDB = 0;
10355 u8 btRssiState = 0;
10357 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10359 if (levelNum == 2) {
10360 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10362 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10363 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10364 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10365 btRssiState = BT_RSSI_STATE_HIGH;
10366 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10367 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10368 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10370 btRssiState = BT_RSSI_STATE_STAY_LOW;
10371 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10374 if (UndecoratedSmoothedPWDB < RssiThresh) {
10375 btRssiState = BT_RSSI_STATE_LOW;
10376 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10377 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10378 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10380 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10381 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10384 } else if (levelNum == 3) {
10385 if (RssiThresh > RssiThresh1) {
10386 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 thresh error!!\n"));
10387 return pHalData->bt_coexist.preRssiState1;
10390 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10391 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10392 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10393 btRssiState = BT_RSSI_STATE_MEDIUM;
10394 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10395 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10396 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10397 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10399 btRssiState = BT_RSSI_STATE_STAY_LOW;
10400 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10402 } else if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_MEDIUM) ||
10403 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_MEDIUM)) {
10404 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10405 btRssiState = BT_RSSI_STATE_HIGH;
10406 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10407 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10408 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10409 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10410 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10411 btRssiState = BT_RSSI_STATE_LOW;
10412 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10413 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10414 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10415 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10417 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10418 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Medium\n"));
10421 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10422 btRssiState = BT_RSSI_STATE_MEDIUM;
10423 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10424 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10425 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10426 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10428 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10429 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10434 pHalData->bt_coexist.preRssiState1 = btRssiState;
10436 return btRssiState;
10439 u8 BTDM_CheckCoexRSSIState(struct rtw_adapter *padapter, u8 levelNum,
10440 u8 RssiThresh, u8 RssiThresh1)
10442 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10443 s32 UndecoratedSmoothedPWDB = 0;
10444 u8 btRssiState = 0;
10446 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10448 if (levelNum == 2) {
10449 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10451 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10452 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10453 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10454 btRssiState = BT_RSSI_STATE_HIGH;
10455 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10456 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10457 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10459 btRssiState = BT_RSSI_STATE_STAY_LOW;
10460 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10463 if (UndecoratedSmoothedPWDB < RssiThresh) {
10464 btRssiState = BT_RSSI_STATE_LOW;
10465 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10466 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10467 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10469 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10470 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10473 } else if (levelNum == 3) {
10474 if (RssiThresh > RssiThresh1) {
10475 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI thresh error!!\n"));
10476 return pHalData->bt_coexist.preRssiState;
10479 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10480 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10481 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10482 btRssiState = BT_RSSI_STATE_MEDIUM;
10483 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10484 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10485 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10486 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10488 btRssiState = BT_RSSI_STATE_STAY_LOW;
10489 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10491 } else if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_MEDIUM) ||
10492 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_MEDIUM)) {
10493 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10494 btRssiState = BT_RSSI_STATE_HIGH;
10495 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10496 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10497 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10498 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10499 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10500 btRssiState = BT_RSSI_STATE_LOW;
10501 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10502 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10503 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10504 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10506 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10507 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Medium\n"));
10510 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10511 btRssiState = BT_RSSI_STATE_MEDIUM;
10512 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10513 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10514 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10515 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10517 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10518 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10523 pHalData->bt_coexist.preRssiState = btRssiState;
10525 return btRssiState;
10528 bool rtl8723a_BT_disable_EDCA_turbo(struct rtw_adapter *padapter)
10530 struct bt_mgnt *pBtMgnt;
10531 struct hal_data_8723a *pHalData;
10532 u8 bBtChangeEDCA = false;
10533 u32 EDCA_BT_BE = 0x5ea42b, cur_EDCA_reg;
10536 pHalData = GET_HAL_DATA(padapter);
10537 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10539 if (!rtl8723a_BT_coexist(padapter)) {
10541 pHalData->bt_coexist.lastBtEdca = 0;
10544 if (!((pBtMgnt->bSupportProfile) ||
10545 (pHalData->bt_coexist.BT_CoexistType == BT_CSR_BC8))) {
10547 pHalData->bt_coexist.lastBtEdca = 0;
10551 if (rtl8723a_BT_using_antenna_1(padapter)) {
10553 pHalData->bt_coexist.lastBtEdca = 0;
10557 if (pHalData->bt_coexist.exec_cnt < 3)
10558 pHalData->bt_coexist.exec_cnt++;
10560 pHalData->bt_coexist.bEDCAInitialized = true;
10562 /* When BT is non idle */
10563 if (!(pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)) {
10564 RTPRINT(FBT, BT_TRACE, ("BT state non idle, set bt EDCA\n"));
10566 /* aggr_num = 0x0909; */
10567 if (pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA) {
10568 bBtChangeEDCA = true;
10569 pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA = false;
10570 pHalData->dmpriv.prv_traffic_idx = 3;
10572 cur_EDCA_reg = rtl8723au_read32(padapter, REG_EDCA_BE_PARAM);
10574 if (cur_EDCA_reg != EDCA_BT_BE)
10575 bBtChangeEDCA = true;
10576 if (bBtChangeEDCA || !pHalData->bt_coexist.bEDCAInitialized) {
10577 rtl8723au_write32(padapter, REG_EDCA_BE_PARAM,
10579 pHalData->bt_coexist.lastBtEdca = EDCA_BT_BE;
10583 RTPRINT(FBT, BT_TRACE, ("BT state idle, set original EDCA\n"));
10584 pHalData->bt_coexist.lastBtEdca = 0;
10592 struct rtw_adapter *padapter,
10598 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10599 u8 H2C_Parameter[3] = {0};
10602 H2C_Parameter[2] = 1;
10603 H2C_Parameter[1] = ms1;
10604 H2C_Parameter[0] = ms0;
10605 pHalData->bt_coexist.bFWCoexistAllOff = false;
10607 H2C_Parameter[2] = 0;
10608 H2C_Parameter[1] = 0;
10609 H2C_Parameter[0] = 0;
10611 pHalData->bt_coexist.bBalanceOn = bBalanceOn;
10613 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Balance =[%s:%dms:%dms], write 0xc = 0x%x\n",
10614 bBalanceOn?"ON":"OFF", ms0, ms1,
10615 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10617 FillH2CCmd(padapter, 0xc, 3, H2C_Parameter);
10620 void BTDM_AGCTable(struct rtw_adapter *padapter, u8 type)
10622 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10623 if (type == BT_AGCTABLE_OFF) {
10624 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable Off!\n"));
10625 rtl8723au_write32(padapter, 0xc78, 0x641c0001);
10626 rtl8723au_write32(padapter, 0xc78, 0x631d0001);
10627 rtl8723au_write32(padapter, 0xc78, 0x621e0001);
10628 rtl8723au_write32(padapter, 0xc78, 0x611f0001);
10629 rtl8723au_write32(padapter, 0xc78, 0x60200001);
10631 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x32000);
10632 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x71000);
10633 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xb0000);
10634 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xfc000);
10635 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x30355);
10637 pHalData->bt_coexist.b8723aAgcTableOn = false;
10638 } else if (type == BT_AGCTABLE_ON) {
10639 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable On!\n"));
10640 rtl8723au_write32(padapter, 0xc78, 0x4e1c0001);
10641 rtl8723au_write32(padapter, 0xc78, 0x4d1d0001);
10642 rtl8723au_write32(padapter, 0xc78, 0x4c1e0001);
10643 rtl8723au_write32(padapter, 0xc78, 0x4b1f0001);
10644 rtl8723au_write32(padapter, 0xc78, 0x4a200001);
10646 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xdc000);
10647 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x90000);
10648 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x51000);
10649 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x12000);
10650 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x00355);
10652 pHalData->bt_coexist.b8723aAgcTableOn = true;
10654 pHalData->bt_coexist.bSWCoexistAllOff = false;
10658 void BTDM_BBBackOffLevel(struct rtw_adapter *padapter, u8 type)
10660 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10662 if (type == BT_BB_BACKOFF_OFF) {
10663 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel Off!\n"));
10664 rtl8723au_write32(padapter, 0xc04, 0x3a05611);
10665 } else if (type == BT_BB_BACKOFF_ON) {
10666 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel On!\n"));
10667 rtl8723au_write32(padapter, 0xc04, 0x3a07611);
10668 pHalData->bt_coexist.bSWCoexistAllOff = false;
10672 void BTDM_FWCoexAllOff(struct rtw_adapter *padapter)
10674 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10676 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff()\n"));
10677 if (pHalData->bt_coexist.bFWCoexistAllOff)
10679 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff(), real Do\n"));
10681 BTDM_FWCoexAllOff8723A(padapter);
10683 pHalData->bt_coexist.bFWCoexistAllOff = true;
10686 void BTDM_SWCoexAllOff(struct rtw_adapter *padapter)
10688 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10690 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff()\n"));
10691 if (pHalData->bt_coexist.bSWCoexistAllOff)
10693 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff(), real Do\n"));
10694 BTDM_SWCoexAllOff8723A(padapter);
10696 pHalData->bt_coexist.bSWCoexistAllOff = true;
10699 void BTDM_HWCoexAllOff(struct rtw_adapter *padapter)
10701 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10703 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff()\n"));
10704 if (pHalData->bt_coexist.bHWCoexistAllOff)
10706 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff(), real Do\n"));
10708 BTDM_HWCoexAllOff8723A(padapter);
10710 pHalData->bt_coexist.bHWCoexistAllOff = true;
10713 void BTDM_CoexAllOff(struct rtw_adapter *padapter)
10715 BTDM_FWCoexAllOff(padapter);
10716 BTDM_SWCoexAllOff(padapter);
10717 BTDM_HWCoexAllOff(padapter);
10720 void rtl8723a_BT_disable_coexist(struct rtw_adapter *padapter)
10722 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
10724 if (!rtl8723a_BT_coexist(padapter))
10727 /* 8723 1Ant doesn't need to turn off bt coexist mechanism. */
10728 if (rtl8723a_BT_using_antenna_1(padapter))
10731 /* Before enter IPS, turn off FW BT Co-exist mechanism */
10732 if (ppwrctrl->reg_rfoff == rf_on) {
10733 RTPRINT(FBT, BT_TRACE, ("[BT][DM], Before enter IPS, turn off all Coexist DM\n"));
10734 btdm_ResetFWCoexState(padapter);
10735 BTDM_CoexAllOff(padapter);
10736 BTDM_SetAntenna(padapter, BTDM_ANT_BT);
10740 void BTDM_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
10742 BTDM_8723ASignalCompensation(padapter, rssi_wifi, rssi_bt);
10745 void rtl8723a_BT_do_coexist(struct rtw_adapter *padapter)
10747 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10749 if (!rtl8723a_BT_coexist(padapter)) {
10750 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT not exists!!\n"));
10754 if (!pHalData->bt_coexist.bInitlized) {
10755 RTPRINT(FBT, BT_TRACE, ("[DM][BT], btdm_InitBtCoexistDM()\n"));
10756 btdm_InitBtCoexistDM(padapter);
10759 RTPRINT(FBT, BT_TRACE, ("\n\n[DM][BT], BTDM start!!\n"));
10761 BTDM_PWDBMonitor(padapter);
10763 RTPRINT(FBT, BT_TRACE, ("[DM][BT], HW type is 8723\n"));
10764 BTDM_BTCoexist8723A(padapter);
10765 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BTDM end!!\n\n"));
10768 void BTDM_UpdateCoexState(struct rtw_adapter *padapter)
10770 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10772 if (!BTDM_IsSameCoexistState(padapter)) {
10773 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x, changeBits = 0x%"i64fmt"x\n",
10774 pHalData->bt_coexist.PreviousState,
10775 pHalData->bt_coexist.CurrentState,
10776 (pHalData->bt_coexist.PreviousState^pHalData->bt_coexist.CurrentState)));
10777 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
10781 u8 BTDM_IsSameCoexistState(struct rtw_adapter *padapter)
10783 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10785 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState) {
10788 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Coexist state changed!!\n"));
10793 void BTDM_PWDBMonitor(struct rtw_adapter *padapter)
10795 struct bt_30info *pBTInfo = GET_BT_INFO(GetDefaultAdapter(padapter));
10796 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10797 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10798 u8 H2C_Parameter[3] = {0};
10799 s32 tmpBTEntryMaxPWDB = 0, tmpBTEntryMinPWDB = 0xff;
10802 if (pBtMgnt->BtOperationOn) {
10803 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
10804 if (pBTInfo->BtAsocEntry[i].bUsed) {
10805 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB < tmpBTEntryMinPWDB)
10806 tmpBTEntryMinPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10807 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB > tmpBTEntryMaxPWDB)
10808 tmpBTEntryMaxPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10809 /* Report every BT connection (HS mode) RSSI to FW */
10810 H2C_Parameter[2] = (u8)(pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB & 0xFF);
10811 H2C_Parameter[0] = (MAX_FW_SUPPORT_MACID_NUM-1-i);
10812 RTPRINT(FDM, DM_BT30, ("RSSI report for BT[%d], H2C_Par = 0x%x\n", i, H2C_Parameter[0]));
10813 FillH2CCmd(padapter, RSSI_SETTING_EID, 3, H2C_Parameter);
10814 RTPRINT_ADDR(FDM, (DM_PWDB|DM_BT30), ("BT_Entry Mac :"),
10815 pBTInfo->BtAsocEntry[i].BTRemoteMACAddr)
10816 RTPRINT(FDM, (DM_PWDB|DM_BT30),
10817 ("BT rx pwdb[%d] = 0x%x(%d)\n", i,
10818 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB,
10819 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB));
10822 if (tmpBTEntryMaxPWDB != 0) { /* If associated entry is found */
10823 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = tmpBTEntryMaxPWDB;
10824 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMaxPWDB = 0x%x(%d)\n",
10825 tmpBTEntryMaxPWDB, tmpBTEntryMaxPWDB));
10827 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = 0;
10829 if (tmpBTEntryMinPWDB != 0xff) { /* If associated entry is found */
10830 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = tmpBTEntryMinPWDB;
10831 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMinPWDB = 0x%x(%d)\n",
10832 tmpBTEntryMinPWDB, tmpBTEntryMinPWDB));
10834 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = 0;
10839 u8 BTDM_IsBTBusy(struct rtw_adapter *padapter)
10841 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10842 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10844 if (pBtMgnt->ExtConfig.bBTBusy)
10850 u8 BTDM_IsWifiBusy(struct rtw_adapter *padapter)
10852 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10853 struct mlme_priv *pmlmepriv = &GetDefaultAdapter(padapter)->mlmepriv;
10854 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10855 struct bt_traffic *pBtTraffic = &pBTInfo->BtTraffic;
10857 if (pmlmepriv->LinkDetectInfo.bBusyTraffic ||
10858 pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic ||
10859 pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic)
10865 u8 BTDM_IsCoexistStateChanged(struct rtw_adapter *padapter)
10867 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10869 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState)
10875 u8 BTDM_IsWifiUplink(struct rtw_adapter *padapter)
10877 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10878 struct mlme_priv *pmlmepriv;
10879 struct bt_30info *pBTInfo;
10880 struct bt_traffic *pBtTraffic;
10882 pmlmepriv = &padapter->mlmepriv;
10883 pBTInfo = GET_BT_INFO(padapter);
10884 pBtTraffic = &pBTInfo->BtTraffic;
10886 if ((pmlmepriv->LinkDetectInfo.bTxBusyTraffic) ||
10887 (pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic))
10893 u8 BTDM_IsWifiDownlink(struct rtw_adapter *padapter)
10895 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10896 struct mlme_priv *pmlmepriv;
10897 struct bt_30info *pBTInfo;
10898 struct bt_traffic *pBtTraffic;
10900 pmlmepriv = &padapter->mlmepriv;
10901 pBTInfo = GET_BT_INFO(padapter);
10902 pBtTraffic = &pBTInfo->BtTraffic;
10904 if ((pmlmepriv->LinkDetectInfo.bRxBusyTraffic) ||
10905 (pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic))
10911 u8 BTDM_IsBTHSMode(struct rtw_adapter *padapter)
10913 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10914 struct hal_data_8723a *pHalData;
10915 struct bt_mgnt *pBtMgnt;
10917 pHalData = GET_HAL_DATA(padapter);
10918 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10920 if (pBtMgnt->BtOperationOn)
10926 u8 BTDM_IsBTUplink(struct rtw_adapter *padapter)
10928 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10930 if (pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic)
10936 u8 BTDM_IsBTDownlink(struct rtw_adapter *padapter)
10938 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10940 if (pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic)
10946 void BTDM_AdjustForBtOperation(struct rtw_adapter *padapter)
10948 RTPRINT(FBT, BT_TRACE, ("[BT][DM], BTDM_AdjustForBtOperation()\n"));
10949 BTDM_AdjustForBtOperation8723A(padapter);
10952 void BTDM_SetBtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
10954 BTDM_Set8723ABtCoexCurrAntNum(padapter, antNum);
10957 void BTDM_ForHalt(struct rtw_adapter *padapter)
10959 if (!rtl8723a_BT_coexist(padapter))
10962 BTDM_ForHalt8723A(padapter);
10963 GET_HAL_DATA(padapter)->bt_coexist.bInitlized = false;
10966 void BTDM_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
10968 if (!rtl8723a_BT_coexist(padapter))
10971 BTDM_WifiScanNotify8723A(padapter, scanType);
10974 void BTDM_WifiAssociateNotify(struct rtw_adapter *padapter, u8 action)
10976 if (!rtl8723a_BT_coexist(padapter))
10979 BTDM_WifiAssociateNotify8723A(padapter, action);
10982 void rtl8723a_BT_mediastatus_notify(struct rtw_adapter *padapter,
10983 enum rt_media_status mstatus)
10985 if (!rtl8723a_BT_coexist(padapter))
10988 BTDM_MediaStatusNotify8723A(padapter, mstatus);
10991 void rtl8723a_BT_specialpacket_notify(struct rtw_adapter *padapter)
10993 if (!rtl8723a_BT_coexist(padapter))
10996 BTDM_ForDhcp8723A(padapter);
10999 void BTDM_ResetActionProfileState(struct rtw_adapter *padapter)
11001 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11003 pHalData->bt_coexist.CurrentState &= ~\
11004 (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP|
11005 BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_SCO);
11008 u8 BTDM_IsActionSCO(struct rtw_adapter *padapter)
11010 struct hal_data_8723a *pHalData;
11011 struct bt_30info *pBTInfo;
11012 struct bt_mgnt *pBtMgnt;
11013 struct bt_dgb *pBtDbg;
11016 pHalData = GET_HAL_DATA(padapter);
11017 pBTInfo = GET_BT_INFO(padapter);
11018 pBtMgnt = &pBTInfo->BtMgnt;
11019 pBtDbg = &pBTInfo->BtDbg;
11022 if (pBtDbg->dbgCtrl) {
11023 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_SCO) {
11024 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
11028 if (pBtMgnt->ExtConfig.NumberOfSCO > 0) {
11029 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
11036 u8 BTDM_IsActionHID(struct rtw_adapter *padapter)
11038 struct bt_30info *pBTInfo;
11039 struct hal_data_8723a *pHalData;
11040 struct bt_mgnt *pBtMgnt;
11041 struct bt_dgb *pBtDbg;
11044 pHalData = GET_HAL_DATA(padapter);
11045 pBTInfo = GET_BT_INFO(padapter);
11046 pBtMgnt = &pBTInfo->BtMgnt;
11047 pBtDbg = &pBTInfo->BtDbg;
11050 if (pBtDbg->dbgCtrl) {
11051 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID) {
11052 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11056 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11057 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11058 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11065 u8 BTDM_IsActionA2DP(struct rtw_adapter *padapter)
11067 struct hal_data_8723a *pHalData;
11068 struct bt_30info *pBTInfo;
11069 struct bt_mgnt *pBtMgnt;
11070 struct bt_dgb *pBtDbg;
11073 pHalData = GET_HAL_DATA(padapter);
11074 pBTInfo = GET_BT_INFO(padapter);
11075 pBtMgnt = &pBTInfo->BtMgnt;
11076 pBtDbg = &pBTInfo->BtDbg;
11079 if (pBtDbg->dbgCtrl) {
11080 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_A2DP) {
11081 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11085 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP) &&
11086 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11087 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11094 u8 BTDM_IsActionPAN(struct rtw_adapter *padapter)
11096 struct hal_data_8723a *pHalData;
11097 struct bt_30info *pBTInfo;
11098 struct bt_mgnt *pBtMgnt;
11099 struct bt_dgb *pBtDbg;
11102 pHalData = GET_HAL_DATA(padapter);
11103 pBTInfo = GET_BT_INFO(padapter);
11104 pBtMgnt = &pBTInfo->BtMgnt;
11105 pBtDbg = &pBTInfo->BtDbg;
11108 if (pBtDbg->dbgCtrl) {
11109 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN) {
11110 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11114 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
11115 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11116 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11123 u8 BTDM_IsActionHIDA2DP(struct rtw_adapter *padapter)
11125 struct hal_data_8723a *pHalData;
11126 struct bt_30info *pBTInfo;
11127 struct bt_mgnt *pBtMgnt;
11128 struct bt_dgb *pBtDbg;
11131 pHalData = GET_HAL_DATA(padapter);
11132 pBTInfo = GET_BT_INFO(padapter);
11133 pBtMgnt = &pBTInfo->BtMgnt;
11134 pBtDbg = &pBTInfo->BtDbg;
11137 if (pBtDbg->dbgCtrl) {
11138 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_A2DP) {
11139 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11143 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11144 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11145 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11152 u8 BTDM_IsActionHIDPAN(struct rtw_adapter *padapter)
11154 struct hal_data_8723a *pHalData;
11155 struct bt_30info *pBTInfo;
11156 struct bt_dgb *pBtDbg;
11159 pHalData = GET_HAL_DATA(padapter);
11160 pBTInfo = GET_BT_INFO(padapter);
11161 pBtDbg = &pBTInfo->BtDbg;
11164 if (pBtDbg->dbgCtrl) {
11165 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_PAN) {
11166 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11170 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11171 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
11172 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11179 u8 BTDM_IsActionPANA2DP(struct rtw_adapter *padapter)
11181 struct hal_data_8723a *pHalData;
11182 struct bt_30info *pBTInfo;
11183 struct bt_dgb *pBtDbg;
11186 pHalData = GET_HAL_DATA(padapter);
11187 pBTInfo = GET_BT_INFO(padapter);
11188 pBtDbg = &pBTInfo->BtDbg;
11191 if (pBtDbg->dbgCtrl) {
11192 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN_A2DP) {
11193 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11197 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) && BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11198 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11205 bool rtl8723a_BT_enabled(struct rtw_adapter *padapter)
11207 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11209 if (pHalData->bt_coexist.bCurBtDisabled)
11215 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
11217 /* ===== Below this line is sync from SD7 driver HAL/HalBT.c ===== */
11220 /*local function */
11223 static void halbt_InitHwConfig8723A(struct rtw_adapter *padapter)
11228 /*extern function */
11230 u8 HALBT_GetPGAntNum(struct rtw_adapter *padapter)
11232 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11234 return pHalData->bt_coexist.BT_Ant_Num;
11237 void HALBT_SetKey(struct rtw_adapter *padapter, u8 EntryNum)
11239 struct bt_30info *pBTinfo;
11240 struct bt_asoc_entry *pBtAssocEntry;
11243 pBTinfo = GET_BT_INFO(padapter);
11244 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11246 pBtAssocEntry->HwCAMIndex = BT_HWCAM_STAR + EntryNum;
11248 usConfig = CAM_VALID | (CAM_AES << 2);
11249 rtl8723a_cam_write(padapter, pBtAssocEntry->HwCAMIndex, usConfig,
11250 pBtAssocEntry->BTRemoteMACAddr,
11251 pBtAssocEntry->PTK + TKIP_ENC_KEY_POS);
11254 void HALBT_RemoveKey(struct rtw_adapter *padapter, u8 EntryNum)
11256 struct bt_30info *pBTinfo;
11257 struct bt_asoc_entry *pBtAssocEntry;
11259 pBTinfo = GET_BT_INFO(padapter);
11260 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11262 if (pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex != 0) {
11263 /* ToDo : add New HALBT_RemoveKey function !! */
11264 if (pBtAssocEntry->HwCAMIndex >= BT_HWCAM_STAR &&
11265 pBtAssocEntry->HwCAMIndex < HALF_CAM_ENTRY)
11266 rtl8723a_cam_empty_entry(padapter,
11267 pBtAssocEntry->HwCAMIndex);
11268 pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex = 0;
11272 void rtl8723a_BT_init_hal_vars(struct rtw_adapter *padapter)
11274 struct hal_data_8723a *pHalData;
11276 pHalData = GET_HAL_DATA(padapter);
11278 pHalData->bt_coexist.BluetoothCoexist = pHalData->EEPROMBluetoothCoexist;
11279 pHalData->bt_coexist.BT_Ant_Num = pHalData->EEPROMBluetoothAntNum;
11280 pHalData->bt_coexist.BT_CoexistType = pHalData->EEPROMBluetoothType;
11281 pHalData->bt_coexist.BT_Ant_isolation = pHalData->EEPROMBluetoothAntIsolation;
11282 pHalData->bt_coexist.bt_radiosharedtype = pHalData->EEPROMBluetoothRadioShared;
11284 RT_TRACE(_module_hal_init_c_, _drv_info_,
11285 ("BT Coexistance = 0x%x\n", rtl8723a_BT_coexist(padapter)));
11287 if (rtl8723a_BT_coexist(padapter)) {
11288 if (pHalData->bt_coexist.BT_Ant_Num == Ant_x2) {
11289 BTDM_SetBtCoexCurrAntNum(padapter, 2);
11290 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx2\n"));
11291 } else if (pHalData->bt_coexist.BT_Ant_Num == Ant_x1) {
11292 BTDM_SetBtCoexCurrAntNum(padapter, 1);
11293 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx1\n"));
11295 pHalData->bt_coexist.bBTBusyTraffic = false;
11296 pHalData->bt_coexist.bBTTrafficModeSet = false;
11297 pHalData->bt_coexist.bBTNonTrafficModeSet = false;
11298 pHalData->bt_coexist.CurrentState = 0;
11299 pHalData->bt_coexist.PreviousState = 0;
11301 RT_TRACE(_module_hal_init_c_, _drv_info_,
11302 ("bt_radiosharedType = 0x%x\n",
11303 pHalData->bt_coexist.bt_radiosharedtype));
11307 bool rtl8723a_BT_coexist(struct rtw_adapter *padapter)
11309 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11311 if (pHalData->bt_coexist.BluetoothCoexist)
11317 u8 HALBT_BTChipType(struct rtw_adapter *padapter)
11319 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11321 return pHalData->bt_coexist.BT_CoexistType;
11324 void rtl8723a_BT_init_hwconfig(struct rtw_adapter *padapter)
11326 halbt_InitHwConfig8723A(padapter);
11327 rtl8723a_BT_do_coexist(padapter);
11330 void HALBT_SetRtsCtsNoLenLimit(struct rtw_adapter *padapter)
11334 /* ===== End of sync from SD7 driver HAL/HalBT.c ===== */
11336 void rtl8723a_dual_antenna_detection(struct rtw_adapter *padapter)
11338 struct hal_data_8723a *pHalData;
11339 struct dm_odm_t *pDM_Odm;
11340 struct sw_ant_sw *pDM_SWAT_Table;
11343 pHalData = GET_HAL_DATA(padapter);
11344 pDM_Odm = &pHalData->odmpriv;
11345 pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
11348 /* <Roger_Notes> RTL8723A Single and Dual antenna dynamic detection
11349 mechanism when RF power state is on. */
11350 /* We should take power tracking, IQK, LCK, RCK RF read/write
11351 operation into consideration. */
11354 if (!pHalData->bAntennaDetected) {
11355 u8 btAntNum = BT_GetPGAntNum(padapter);
11357 /* Set default antenna B status */
11358 if (btAntNum == Ant_x2)
11359 pDM_SWAT_Table->ANTB_ON = true;
11360 else if (btAntNum == Ant_x1)
11361 pDM_SWAT_Table->ANTB_ON = false;
11363 pDM_SWAT_Table->ANTB_ON = true;
11365 if (pHalData->CustomerID != RT_CID_TOSHIBA) {
11366 for (i = 0; i < MAX_ANTENNA_DETECTION_CNT; i++) {
11367 if (ODM_SingleDualAntennaDetection
11368 (&pHalData->odmpriv, ANTTESTALL) == true)
11372 /* Set default antenna number for BT coexistence */
11373 if (btAntNum == Ant_x2)
11374 BT_SetBtCoexCurrAntNum(padapter,
11378 pHalData->bAntennaDetected = true;