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 <rtw_ioctl_set.h>
18 #include <usb_ops_linux.h>
22 u32 BTCoexDbgLevel = _bt_dbg_off_;
24 #define RTPRINT(_Comp, _Level, Fmt)\
26 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
31 #define RTPRINT_ADDR(dbgtype, dbgflag, printstr, _Ptr)\
32 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
34 u8 *ptr = (u8 *)_Ptr; \
37 for (__i = 0; __i < 6; __i++) \
38 printk("%02X%s", ptr[__i], (__i == 5)?"":"-"); \
41 #define RTPRINT_DATA(dbgtype, dbgflag, _TitleString, _HexData, _HexDataLen)\
42 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
44 u8 *ptr = (u8 *)_HexData; \
45 printk(_TitleString); \
46 for (__i = 0; __i < (u32)_HexDataLen; __i++) { \
47 printk("%02X%s", ptr[__i], (((__i + 1) % 4) == 0)?" ":" ");\
48 if (((__i + 1) % 16) == 0) \
53 /* Added by Annie, 2005-11-22. */
54 #define MAX_STR_LEN 64
55 /* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. */
56 #define PRINTABLE(_ch) (_ch >= ' ' && _ch <= '~')
57 #define RT_PRINT_STR(_Comp, _Level, _TitleString, _Ptr, _Len) \
60 u8 buffer[MAX_STR_LEN]; \
61 u32 length = (_Len < MAX_STR_LEN) ? _Len : (MAX_STR_LEN-1);\
62 memset(buffer, 0, MAX_STR_LEN); \
63 memcpy(buffer, (u8 *)_Ptr, length); \
64 for (__i = 0; __i < length; __i++) { \
65 if (!PRINTABLE(buffer[__i])) \
68 buffer[length] = '\0'; \
69 printk(_TitleString); \
70 printk(": %d, <%s>\n", _Len, buffer); \
73 #define DCMD_Printf(...)
74 #define RT_ASSERT(...)
76 #define rsprintf snprintf
78 #define GetDefaultAdapter(padapter) padapter
80 #define PlatformZeroMemory(ptr, sz) memset(ptr, 0, sz)
82 #define PlatformProcessHCICommands(...)
83 #define PlatformTxBTQueuedPackets(...)
84 #define PlatformIndicateBTACLData(...) (RT_STATUS_SUCCESS)
85 #define PlatformAcquireSpinLock(padapter, type)
86 #define PlatformReleaseSpinLock(padapter, type)
88 #define GET_UNDECORATED_AVERAGE_RSSI(padapter) \
89 (GET_HAL_DATA(padapter)->dmpriv.EntryMinUndecoratedSmoothedPWDB)
90 #define RT_RF_CHANGE_SOURCE u32
101 /* ===== Below this line is sync from SD7 driver COMMOM/BT.c ===== */
103 static u8 BT_Operation(struct rtw_adapter *padapter)
105 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
106 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
108 if (pBtMgnt->BtOperationOn)
114 static u8 BT_IsLegalChannel(struct rtw_adapter *padapter, u8 channel)
116 struct rt_channel_info *pChanneList = NULL;
119 pChanneList = padapter->mlmeextpriv.channel_set;
120 channelLen = padapter->mlmeextpriv.max_chan_nums;
122 for (i = 0; i < channelLen; i++) {
123 RTPRINT(FIOCTL, IOCTL_STATE,
124 ("Check if chnl(%d) in channel plan contains bt target chnl(%d) for BT connection\n",
125 pChanneList[i].ChannelNum, channel));
126 if ((channel == pChanneList[i].ChannelNum) ||
127 (channel == pChanneList[i].ChannelNum + 2))
133 void BT_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
135 BTDM_SignalCompensation(padapter, rssi_wifi, rssi_bt);
138 void rtl8723a_BT_wifiscan_notify(struct rtw_adapter *padapter, u8 scanType)
140 BTHCI_WifiScanNotify(padapter, scanType);
141 BTDM_CheckAntSelMode(padapter);
142 BTDM_WifiScanNotify(padapter, scanType);
145 void rtl8723a_BT_wifiassociate_notify(struct rtw_adapter *padapter, u8 action)
148 /* true = associate start */
149 /* false = associate finished */
151 BTDM_CheckAntSelMode(padapter);
153 BTDM_WifiAssociateNotify(padapter, action);
156 void BT_HaltProcess(struct rtw_adapter *padapter)
158 BTDM_ForHalt(padapter);
161 /* ===== End of sync from SD7 driver COMMOM/BT.c ===== */
164 #define UINT64_C(v) (v)
166 #define FillOctetString(_os, _octet, _len) \
167 (_os).Octet = (u8 *)(_octet); \
168 (_os).Length = (_len);
170 static enum rt_status PlatformIndicateBTEvent(
171 struct rtw_adapter *padapter,
176 enum rt_status rt_status = RT_STATUS_FAILURE;
178 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event start, %d bytes data to Transferred!!\n", dataLen));
179 RTPRINT_DATA(FIOCTL, IOCTL_BT_EVENT_DETAIL, "To transfer Hex Data :\n",
182 BT_EventParse(padapter, pEvntData, dataLen);
184 printk(KERN_WARNING "%s: Linux has no way to report BT event!!\n", __func__);
186 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event end, %s\n",
187 (rt_status == RT_STATUS_SUCCESS) ? "SUCCESS" : "FAIL"));
192 /* ===== Below this line is sync from SD7 driver COMMOM/bt_hci.c ===== */
194 static u8 bthci_GetLocalChannel(struct rtw_adapter *padapter)
196 return padapter->mlmeextpriv.cur_channel;
199 static u8 bthci_GetCurrentEntryNum(struct rtw_adapter *padapter, u8 PhyHandle)
201 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
204 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
205 if ((pBTInfo->BtAsocEntry[i].bUsed) &&
206 (pBTInfo->BtAsocEntry[i].PhyLinkCmdData.BtPhyLinkhandle == PhyHandle))
213 static void bthci_DecideBTChannel(struct rtw_adapter *padapter, u8 EntryNum)
215 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
216 struct mlme_priv *pmlmepriv;
217 struct bt_30info *pBTInfo;
218 struct bt_mgnt *pBtMgnt;
219 struct bt_hci_info *pBtHciInfo;
220 struct chnl_txpower_triple *pTriple_subband = NULL;
221 struct common_triple *pTriple;
222 u8 i, j, localchnl, firstRemoteLegalChnlInTriplet = 0;
223 u8 regulatory_skipLen = 0;
224 u8 subbandTripletCnt = 0;
226 pmlmepriv = &padapter->mlmepriv;
227 pBTInfo = GET_BT_INFO(padapter);
228 pBtMgnt = &pBTInfo->BtMgnt;
229 pBtHciInfo = &pBTInfo->BtHciInfo;
231 pBtMgnt->CheckChnlIsSuit = true;
232 localchnl = bthci_GetLocalChannel(padapter);
234 pTriple = (struct common_triple *)
235 &pBtHciInfo->BTPreChnllist[COUNTRY_STR_LEN];
237 /* contains country string, len is 3 */
238 for (i = 0; i < (pBtHciInfo->BtPreChnlListLen-COUNTRY_STR_LEN); i += 3, pTriple++) {
240 /* check every triplet, an triplet may be */
241 /* regulatory extension identifier or sub-band triplet */
243 if (pTriple->byte_1st == 0xc9) {
244 /* Regulatory Extension Identifier, skip it */
245 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
246 ("Find Regulatory ID, regulatory class = %d\n", pTriple->byte_2nd));
247 regulatory_skipLen += 3;
248 pTriple_subband = NULL;
250 } else { /* Sub-band triplet */
251 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Find Sub-band triplet \n"));
253 pTriple_subband = (struct chnl_txpower_triple *)pTriple;
254 /* if remote first legal channel not found, then find first remote channel */
255 /* and it's legal for our channel plan. */
257 /* search the sub-band triplet and find if remote channel is legal to our channel plan. */
258 for (j = pTriple_subband->FirstChnl; j < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls); j++) {
259 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), (" Check if chnl(%d) is legal\n", j));
260 if (BT_IsLegalChannel(padapter, j)) {
261 /* remote channel is legal for our channel plan. */
262 firstRemoteLegalChnlInTriplet = j;
263 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
264 ("Find first remote legal channel : %d\n",
265 firstRemoteLegalChnlInTriplet));
267 /* If we find a remote legal channel in the sub-band triplet */
268 /* and only BT connection is established(local not connect to any AP or IBSS), */
269 /* then we just switch channel to remote channel. */
270 if (!(check_fwstate(pmlmepriv, WIFI_ASOC_STATE|WIFI_ADHOC_STATE|WIFI_AP_STATE) ||
271 BTHCI_HsConnectionEstablished(padapter))) {
272 pBtMgnt->BTChannel = firstRemoteLegalChnlInTriplet;
273 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Remote legal channel (%d) is selected, Local not connect to any!!\n", pBtMgnt->BTChannel));
276 if ((localchnl >= firstRemoteLegalChnlInTriplet) &&
277 (localchnl < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls))) {
278 pBtMgnt->BTChannel = localchnl;
279 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected, wifi or BT connection exists\n", pBtMgnt->BTChannel));
289 if (subbandTripletCnt) {
290 /* if any preferred channel triplet exists */
291 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("There are %d sub band triplet exists, ", subbandTripletCnt));
292 if (firstRemoteLegalChnlInTriplet == 0) {
293 /* no legal channel is found, reject the connection. */
294 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("no legal channel is found!!\n"));
296 /* Remote Legal channel is found but not match to local */
297 /* wifi connection exists), so reject the connection. */
298 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
299 ("Remote Legal channel is found but not match to local(wifi connection exists)!!\n"));
301 pBtMgnt->CheckChnlIsSuit = false;
303 /* There are not any preferred channel triplet exists */
304 /* Use current legal channel as the bt channel. */
305 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("No sub band triplet exists!!\n"));
307 pBtMgnt->BTChannel = localchnl;
308 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected!!\n", pBtMgnt->BTChannel));
311 /* Success:return true */
312 /* Fail:return false */
313 static u8 bthci_GetAssocInfo(struct rtw_adapter *padapter, u8 EntryNum)
315 struct bt_30info *pBTInfo;
316 struct bt_hci_info *pBtHciInfo;
319 u8 BaseMemoryShift = 0;
321 struct amp_assoc_structure *pAmpAsoc;
323 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo start\n"));
324 pBTInfo = GET_BT_INFO(padapter);
325 pBtHciInfo = &pBTInfo->BtHciInfo;
327 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar == 0) {
328 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen < (MAX_AMP_ASSOC_FRAG_LEN))
329 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen;
330 else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen == (MAX_AMP_ASSOC_FRAG_LEN))
331 TotalLen = MAX_AMP_ASSOC_FRAG_LEN;
332 } else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar > 0)
333 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar;
335 while ((pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar >= BaseMemoryShift) || TotalLen > BaseMemoryShift) {
336 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("GetAssocInfo, TotalLen =%d, BaseMemoryShift =%d\n", TotalLen, BaseMemoryShift));
338 (u8 *)pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment+BaseMemoryShift,
339 TotalLen-BaseMemoryShift);
340 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, "GetAssocInfo :\n",
341 tempBuf, TotalLen-BaseMemoryShift);
343 pAmpAsoc = (struct amp_assoc_structure *)tempBuf;
344 pAmpAsoc->Length = le16_to_cpu(pAmpAsoc->Length);
345 BaseMemoryShift += 3 + pAmpAsoc->Length;
347 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TypeID = 0x%x, ", pAmpAsoc->TypeID));
348 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Hex Data: \n", pAmpAsoc->Data, pAmpAsoc->Length);
349 switch (pAmpAsoc->TypeID) {
351 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_MAC_ADDR\n"));
352 if (pAmpAsoc->Length > 6)
354 memcpy(pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, pAmpAsoc->Data, 6);
355 RTPRINT_ADDR(FIOCTL, IOCTL_BT_HCICMD, ("Remote Mac address \n"), pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr);
357 case AMP_PREFERRED_CHANNEL_LIST:
358 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_PREFERRED_CHANNEL_LIST\n"));
359 pBtHciInfo->BtPreChnlListLen = pAmpAsoc->Length;
360 memcpy(pBtHciInfo->BTPreChnllist,
362 pBtHciInfo->BtPreChnlListLen);
363 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Preferred channel list : \n", pBtHciInfo->BTPreChnllist, pBtHciInfo->BtPreChnlListLen);
364 bthci_DecideBTChannel(padapter, EntryNum);
366 case AMP_CONNECTED_CHANNEL:
367 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_CONNECTED_CHANNEL\n"));
368 pBtHciInfo->BTConnectChnlListLen = pAmpAsoc->Length;
369 memcpy(pBtHciInfo->BTConnectChnllist,
371 pBtHciInfo->BTConnectChnlListLen);
373 case AMP_80211_PAL_CAP_LIST:
374 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_80211_PAL_CAP_LIST\n"));
375 pBTInfo->BtAsocEntry[EntryNum].BTCapability = *(u32 *)(pAmpAsoc->Data);
376 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000001) {
379 /* Signifies PAL capable of utilizing received activity reports. */
381 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000002) {
383 /* Signifies PAL is capable of utilizing scheduling information received in an activity reports. */
386 case AMP_80211_PAL_VISION:
387 pBtHciInfo->BTPalVersion = *(u8 *)(pAmpAsoc->Data);
388 pBtHciInfo->BTPalCompanyID = *(u16 *)(((u8 *)(pAmpAsoc->Data))+1);
389 pBtHciInfo->BTPalsubversion = *(u16 *)(((u8 *)(pAmpAsoc->Data))+3);
390 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("==> AMP_80211_PAL_VISION PalVersion 0x%x, PalCompanyID 0x%x, Palsubversion 0x%x\n",
391 pBtHciInfo->BTPalVersion,
392 pBtHciInfo->BTPalCompanyID,
393 pBtHciInfo->BTPalsubversion));
396 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> Unsupport TypeID !!\n"));
401 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo end\n"));
406 static u8 bthci_AddEntry(struct rtw_adapter *padapter)
408 struct bt_30info *pBTInfo;
409 struct bt_mgnt *pBtMgnt;
412 pBTInfo = GET_BT_INFO(padapter);
413 pBtMgnt = &pBTInfo->BtMgnt;
415 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
416 if (pBTInfo->BtAsocEntry[i].bUsed == false) {
417 pBTInfo->BtAsocEntry[i].bUsed = true;
418 pBtMgnt->CurrentConnectEntryNum = i;
423 if (i == MAX_BT_ASOC_ENTRY_NUM) {
424 RTPRINT(FIOCTL, IOCTL_STATE, ("bthci_AddEntry(), Add entry fail!!\n"));
430 static u8 bthci_DiscardTxPackets(struct rtw_adapter *padapter, u16 LLH)
436 bthci_CheckLogLinkBehavior(
437 struct rtw_adapter *padapter,
438 struct hci_flow_spec TxFlowSpec
441 u8 ID = TxFlowSpec.Identifier;
442 u8 ServiceType = TxFlowSpec.ServiceType;
443 u16 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
444 u32 SDUInterArrivatime = TxFlowSpec.SDUInterArrivalTime;
449 if (ServiceType == BT_LL_BE) {
451 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX best effort flowspec\n"));
452 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 0xffff)) {
454 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed latency flowspec\n"));
455 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
456 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed Large latency flowspec\n"));
460 if (ServiceType == BT_LL_BE) {
462 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX best effort flowspec\n"));
467 if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 1492)) {
469 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed latency flowspec\n"));
470 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
471 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed Large latency flowspec\n"));
475 if (ServiceType == BT_LL_BE) {
476 if ((SDUInterArrivatime == 0xffffffff) && (ServiceType == BT_LL_BE) && (MaxSDUSize == 1492)) {
478 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX aggregated best effort flowspec\n"));
480 } else if (ServiceType == BT_LL_GU) {
481 if (SDUInterArrivatime == 100) {
483 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX guaranteed bandwidth flowspec\n"));
488 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = Unknow Type !!!!!!!!\n"));
492 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
493 ("ID = 0x%x, ServiceType = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, AccessLatency = 0x%x, FlushTimeout = 0x%x\n",
494 TxFlowSpec.Identifier, TxFlowSpec.ServiceType, MaxSDUSize,
495 SDUInterArrivatime, TxFlowSpec.AccessLatency, TxFlowSpec.FlushTimeout));
499 static u16 bthci_AssocMACAddr(struct rtw_adapter *padapter, void *pbuf)
501 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
502 pAssoStrc->TypeID = AMP_MAC_ADDR;
503 pAssoStrc->Length = 0x06;
504 memcpy(&pAssoStrc->Data[0], padapter->eeprompriv.mac_addr, 6);
505 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
506 ("AssocMACAddr : \n"), pAssoStrc, pAssoStrc->Length+3);
508 return pAssoStrc->Length + 3;
512 bthci_PALCapabilities(
513 struct rtw_adapter *padapter,
517 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
519 pAssoStrc->TypeID = AMP_80211_PAL_CAP_LIST;
520 pAssoStrc->Length = 0x04;
522 pAssoStrc->Data[0] = 0x00;
523 pAssoStrc->Data[1] = 0x00;
525 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("PALCapabilities:\n"), pAssoStrc, pAssoStrc->Length+3);
526 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("PALCapabilities \n"));
528 RTPRINT(FIOCTL, IOCTL_BT_LOGO, (" TypeID = 0x%x,\n Length = 0x%x,\n Content = 0x0000\n",
532 return pAssoStrc->Length + 3;
535 static u16 bthci_AssocPreferredChannelList(struct rtw_adapter *padapter,
536 void *pbuf, u8 EntryNum)
538 struct bt_30info *pBTInfo;
539 struct amp_assoc_structure *pAssoStrc;
540 struct amp_pref_chnl_regulatory *pReg;
541 struct chnl_txpower_triple *pTriple;
542 char ctrString[3] = {'X', 'X', 'X'};
546 pBTInfo = GET_BT_INFO(padapter);
547 pAssoStrc = (struct amp_assoc_structure *)pbuf;
548 pReg = (struct amp_pref_chnl_regulatory *)&pAssoStrc->Data[3];
550 preferredChnl = bthci_GetLocalChannel(padapter);
551 pAssoStrc->TypeID = AMP_PREFERRED_CHANNEL_LIST;
554 memcpy(&pAssoStrc->Data[0], &ctrString[0], 3);
556 pReg->regulatoryClass = 254;
557 pReg->coverageClass = 0;
559 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("PREFERRED_CHNL_LIST\n"));
560 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("XXX, 201, 254, 0\n"));
561 /* at the following, chnl 1~11 should be contained */
562 pTriple = (struct chnl_txpower_triple *)&pAssoStrc->Data[len];
564 /* (1) if any wifi or bt HS connection exists */
565 if ((pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR) ||
566 (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE |
567 WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE |
569 BTHCI_HsConnectionEstablished(padapter)) {
570 pTriple->FirstChnl = preferredChnl;
571 pTriple->NumChnls = 1;
572 pTriple->MaxTxPowerInDbm = 20;
574 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("First Channel = %d, Channel Num = %d, MaxDbm = %d\n",
577 pTriple->MaxTxPowerInDbm));
580 pAssoStrc->Length = (u16)len;
581 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, ("AssocPreferredChannelList : \n"), pAssoStrc, pAssoStrc->Length+3);
583 return pAssoStrc->Length + 3;
586 static u16 bthci_AssocPALVer(struct rtw_adapter *padapter, void *pbuf)
588 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
592 pAssoStrc->TypeID = AMP_80211_PAL_VISION;
593 pAssoStrc->Length = 0x5;
594 pu1Tmp = &pAssoStrc->Data[0];
595 *pu1Tmp = 0x1; /* PAL Version */
596 pu2Tmp = (u16 *)&pAssoStrc->Data[1];
597 *pu2Tmp = 0x5D; /* SIG Company identifier of 802.11 PAL vendor */
598 pu2Tmp = (u16 *)&pAssoStrc->Data[3];
599 *pu2Tmp = 0x1; /* PAL Sub-version specifier */
601 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("AssocPALVer : \n"), pAssoStrc, pAssoStrc->Length+3);
602 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("AssocPALVer \n"));
604 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",
607 return pAssoStrc->Length + 3;
610 static u8 bthci_CheckRfStateBeforeConnect(struct rtw_adapter *padapter)
612 struct bt_30info *pBTInfo;
613 enum rt_rf_power_state RfState;
615 pBTInfo = GET_BT_INFO(padapter);
617 RfState = padapter->pwrctrlpriv.rf_pwrstate;
619 if (RfState != rf_on) {
620 mod_timer(&pBTInfo->BTPsDisableTimer,
621 jiffies + msecs_to_jiffies(50));
627 static void bthci_ResponderStartToScan(struct rtw_adapter *padapter)
631 static u8 bthci_PhyLinkConnectionInProgress(struct rtw_adapter *padapter, u8 PhyLinkHandle)
633 struct bt_30info *pBTInfo;
634 struct bt_mgnt *pBtMgnt;
636 pBTInfo = GET_BT_INFO(padapter);
637 pBtMgnt = &pBTInfo->BtMgnt;
639 if (pBtMgnt->bPhyLinkInProgress &&
640 (pBtMgnt->BtCurrentPhyLinkhandle == PhyLinkHandle))
645 static void bthci_ResetFlowSpec(struct rtw_adapter *padapter, u8 EntryNum, u8 index)
647 struct bt_30info *pBTinfo;
649 pBTinfo = GET_BT_INFO(padapter);
651 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtLogLinkhandle = 0;
652 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtPhyLinkhandle = 0;
653 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCompleteEventIsSet = false;
654 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCancelCMDIsSetandComplete = false;
655 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtTxFlowSpecID = 0;
656 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].TxPacketCount = 0;
658 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.Identifier = 0x01;
659 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
660 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.MaximumSDUSize = 0xffff;
661 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
662 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.AccessLatency = 0xffffffff;
663 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.FlushTimeout = 0xffffffff;
665 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.Identifier = 0x01;
666 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
667 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.MaximumSDUSize = 0xffff;
668 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
669 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.AccessLatency = 0xffffffff;
670 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.FlushTimeout = 0xffffffff;
673 static void bthci_ResetEntry(struct rtw_adapter *padapter, u8 EntryNum)
675 struct bt_30info *pBTinfo;
676 struct bt_mgnt *pBtMgnt;
679 pBTinfo = GET_BT_INFO(padapter);
680 pBtMgnt = &pBTinfo->BtMgnt;
682 pBTinfo->BtAsocEntry[EntryNum].bUsed = false;
683 pBTinfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_DISCONNECTED;
684 pBTinfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED;
686 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen = 0;
687 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = 0;
688 if (pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment != NULL)
689 memset(pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment, 0, TOTAL_ALLOCIATE_ASSOC_LEN);
690 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = 0;
692 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = 0;
693 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = 0;
694 memset(pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, 0,
695 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
696 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = 0;
698 /* 0x640; 0.625ms*1600 = 1000ms, 0.625ms*16000 = 10000ms */
699 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = 0x3e80;
701 pBTinfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_NONE;
703 pBTinfo->BtAsocEntry[EntryNum].mAssoc = false;
704 pBTinfo->BtAsocEntry[EntryNum].b4waySuccess = false;
707 pBTinfo->BtAsocEntry[EntryNum].KeyReplayCounter = 0;
708 pBTinfo->BtAsocEntry[EntryNum].BTWPAAuthState = STATE_WPA_AUTH_UNINITIALIZED;
710 pBTinfo->BtAsocEntry[EntryNum].bSendSupervisionPacket = false;
711 pBTinfo->BtAsocEntry[EntryNum].NoRxPktCnt = 0;
712 pBTinfo->BtAsocEntry[EntryNum].ShortRangeMode = 0;
713 pBTinfo->BtAsocEntry[EntryNum].rxSuvpPktCnt = 0;
715 for (j = 0; j < MAX_LOGICAL_LINK_NUM; j++)
716 bthci_ResetFlowSpec(padapter, EntryNum, j);
718 pBtMgnt->BTAuthCount = 0;
719 pBtMgnt->BTAsocCount = 0;
720 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
721 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
723 HALBT_RemoveKey(padapter, EntryNum);
726 static void bthci_RemoveEntryByEntryNum(struct rtw_adapter *padapter, u8 EntryNum)
728 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
729 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
731 bthci_ResetEntry(padapter, EntryNum);
733 if (pBtMgnt->CurrentBTConnectionCnt > 0)
734 pBtMgnt->CurrentBTConnectionCnt--;
736 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d!!\n",
737 pBtMgnt->CurrentBTConnectionCnt));
739 if (pBtMgnt->CurrentBTConnectionCnt > 0) {
740 pBtMgnt->BtOperationOn = true;
742 pBtMgnt->BtOperationOn = false;
743 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation OFF!!\n"));
746 if (!pBtMgnt->BtOperationOn) {
747 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
748 del_timer_sync(&pBTInfo->BTBeaconTimer);
749 pBtMgnt->bStartSendSupervisionPkt = false;
754 bthci_CommandCompleteHeader(
758 enum hci_status status
761 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
762 u8 NumHCI_Comm = 0x1;
764 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
765 PPacketIrpEvent->Data[0] = NumHCI_Comm; /* packet # */
766 PPacketIrpEvent->Data[1] = HCIOPCODELOW(OCF, OGF);
767 PPacketIrpEvent->Data[2] = HCIOPCODEHIGHT(OCF, OGF);
769 if (OGF == OGF_EXTENSION) {
770 if (OCF == HCI_SET_RSSI_VALUE) {
771 RTPRINT(FIOCTL, (IOCTL_BT_EVENT_PERIODICAL),
772 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
773 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
775 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_EXT),
776 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
777 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
780 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
781 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
782 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
787 static u8 bthci_ExtensionEventHeaderRtk(u8 *pbuf, u8 extensionEvent)
789 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
790 PPacketIrpEvent->EventCode = HCI_EVENT_EXTENSION_RTK;
791 PPacketIrpEvent->Data[0] = extensionEvent; /* extension event code */
796 static enum rt_status
798 struct rtw_adapter *padapter,
803 enum rt_status rt_status;
805 rt_status = PlatformIndicateBTEvent(padapter, pEvntData, dataLen);
811 bthci_EventWriteRemoteAmpAssoc(
812 struct rtw_adapter *padapter,
813 enum hci_status status,
817 u8 localBuf[TmpLocalBufSize] = "";
820 struct packet_irp_hcievent_data *PPacketIrpEvent;
822 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
823 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
825 len += bthci_CommandCompleteHeader(&localBuf[0],
826 OGF_STATUS_PARAMETERS,
827 HCI_WRITE_REMOTE_AMP_ASSOC,
829 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("PhyLinkHandle = 0x%x, status = %d\n", PLHandle, status));
830 /* Return parameters starts from here */
831 pRetPar = &PPacketIrpEvent->Data[len];
832 pRetPar[0] = status; /* status */
833 pRetPar[1] = PLHandle;
835 PPacketIrpEvent->Length = len;
837 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
841 bthci_EventEnhancedFlushComplete(
842 struct rtw_adapter *padapter,
847 struct packet_irp_hcievent_data *PPacketIrpEvent;
849 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("EventEnhancedFlushComplete, LLH = 0x%x\n", LLH));
851 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
852 PPacketIrpEvent->EventCode = HCI_EVENT_ENHANCED_FLUSH_COMPLETE;
853 PPacketIrpEvent->Length = 2;
854 /* Logical link handle */
855 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LLH);
856 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LLH);
858 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
862 bthci_EventShortRangeModeChangeComplete(
863 struct rtw_adapter *padapter,
864 enum hci_status HciStatus,
869 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
870 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
872 struct packet_irp_hcievent_data *PPacketIrpEvent;
874 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE)) {
875 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
876 ("[BT event], Short Range Mode Change Complete, Ignore to send this event due to event mask page 2\n"));
879 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",
880 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, ShortRangeState));
882 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
883 PPacketIrpEvent->EventCode = HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE;
884 PPacketIrpEvent->Length = 3;
885 PPacketIrpEvent->Data[0] = HciStatus;
886 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
887 PPacketIrpEvent->Data[2] = ShortRangeState;
888 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
891 static void bthci_EventSendFlowSpecModifyComplete(struct rtw_adapter *padapter,
892 enum hci_status HciStatus,
896 struct packet_irp_hcievent_data *PPacketIrpEvent;
897 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
898 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
900 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE)) {
901 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
902 ("[BT event], Flow Spec Modify Complete, Ignore to send this event due to event mask page 2\n"));
905 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
906 ("[BT event], Flow Spec Modify Complete, status = 0x%x, LLH = 0x%x\n", HciStatus, logicHandle));
907 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
908 PPacketIrpEvent->EventCode = HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE;
909 PPacketIrpEvent->Length = 3;
911 PPacketIrpEvent->Data[0] = HciStatus;
912 /* Logical link handle */
913 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(logicHandle);
914 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(logicHandle);
916 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
920 bthci_EventExtWifiScanNotify(
921 struct rtw_adapter *padapter,
925 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
926 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
931 struct packet_irp_hcievent_data *PPacketIrpEvent;
933 if (!pBtMgnt->BtOperationOn)
936 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
938 len += bthci_ExtensionEventHeaderRtk(&localBuf[0], HCI_EVENT_EXT_WIFI_SCAN_NOTIFY);
940 /* Return parameters starts from here */
941 pRetPar = &PPacketIrpEvent->Data[len];
942 pu1Temp = (u8 *)&pRetPar[0];
946 PPacketIrpEvent->Length = len;
948 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS) {
949 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Wifi scan notify, scan type = %d\n",
955 bthci_EventAMPReceiverReport(
956 struct rtw_adapter *padapter,
960 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
961 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
963 if (pBtHciInfo->bTestNeedReport) {
964 u8 localBuf[20] = "";
967 struct packet_irp_hcievent_data *PPacketIrpEvent;
969 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_EVENT_AMP_RECEIVER_REPORT\n"));
970 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
971 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_RECEIVER_REPORT;
972 PPacketIrpEvent->Length = 2;
974 PPacketIrpEvent->Data[0] = pBtHciInfo->TestCtrType;
976 PPacketIrpEvent->Data[1] = Reason;
978 pu4Temp = (u32 *)&PPacketIrpEvent->Data[2];
979 *pu4Temp = pBtHciInfo->TestEventType;
981 pu2Temp = (u16 *)&PPacketIrpEvent->Data[6];
982 *pu2Temp = pBtHciInfo->TestNumOfFrame;
984 pu2Temp = (u16 *)&PPacketIrpEvent->Data[8];
985 *pu2Temp = pBtHciInfo->TestNumOfErrFrame;
987 pu4Temp = (u32 *)&PPacketIrpEvent->Data[10];
988 *pu4Temp = pBtHciInfo->TestNumOfBits;
990 pu4Temp = (u32 *)&PPacketIrpEvent->Data[14];
991 *pu4Temp = pBtHciInfo->TestNumOfErrBits;
993 bthci_IndicateEvent(padapter, PPacketIrpEvent, 20);
995 /* Return to Idel state with RX and TX off. */
999 pBtHciInfo->TestNumOfFrame = 0x00;
1003 bthci_EventChannelSelected(
1004 struct rtw_adapter *padapter,
1008 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1009 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1010 u8 localBuf[3] = "";
1011 struct packet_irp_hcievent_data *PPacketIrpEvent;
1013 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_CHANNEL_SELECT)) {
1014 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1015 ("[BT event], Channel Selected, Ignore to send this event due to event mask page 2\n"));
1019 RTPRINT(FIOCTL, IOCTL_BT_EVENT|IOCTL_STATE,
1020 ("[BT event], Channel Selected, PhyLinkHandle %d\n",
1021 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle));
1023 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1024 PPacketIrpEvent->EventCode = HCI_EVENT_CHANNEL_SELECT;
1025 PPacketIrpEvent->Length = 1;
1026 PPacketIrpEvent->Data[0] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1027 bthci_IndicateEvent(padapter, PPacketIrpEvent, 3);
1031 bthci_EventDisconnectPhyLinkComplete(
1032 struct rtw_adapter *padapter,
1033 enum hci_status HciStatus,
1034 enum hci_status Reason,
1038 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1039 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1040 u8 localBuf[5] = "";
1041 struct packet_irp_hcievent_data *PPacketIrpEvent;
1043 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE)) {
1044 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1045 ("[BT event], Disconnect Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1048 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1049 ("[BT event], Disconnect Physical Link Complete, Status = 0x%x, PLH = 0x%x Reason = 0x%x\n",
1050 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, Reason));
1051 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1052 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE;
1053 PPacketIrpEvent->Length = 3;
1054 PPacketIrpEvent->Data[0] = HciStatus;
1055 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1056 PPacketIrpEvent->Data[2] = Reason;
1057 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
1061 bthci_EventPhysicalLinkComplete(
1062 struct rtw_adapter *padapter,
1063 enum hci_status HciStatus,
1068 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1069 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1070 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1071 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1072 u8 localBuf[4] = "";
1073 struct packet_irp_hcievent_data *PPacketIrpEvent;
1076 pBtMgnt->bPhyLinkInProgress = false;
1077 pBtDbg->dbgHciInfo.hciCmdPhyLinkStatus = HciStatus;
1078 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_PHY_LINK_COMPLETE)) {
1079 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1080 ("[BT event], Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1084 if (EntryNum == 0xff) {
1085 /* connection not started yet, just use the input physical link handle to response. */
1086 PL_handle = PLHandle;
1088 /* connection is under progress, use the phy link handle we recorded. */
1089 PL_handle = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1090 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = false;
1093 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Physical Link Complete, Status = 0x%x PhyLinkHandle = 0x%x\n", HciStatus,
1096 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1097 PPacketIrpEvent->EventCode = HCI_EVENT_PHY_LINK_COMPLETE;
1098 PPacketIrpEvent->Length = 2;
1100 PPacketIrpEvent->Data[0] = HciStatus;
1101 PPacketIrpEvent->Data[1] = PL_handle;
1102 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1107 bthci_EventCommandStatus(
1108 struct rtw_adapter *padapter,
1111 enum hci_status HciStatus
1115 u8 localBuf[6] = "";
1116 struct packet_irp_hcievent_data *PPacketIrpEvent;
1117 u8 Num_Hci_Comm = 0x1;
1118 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1119 ("[BT event], CommandStatus, Opcode = 0x%02x%02x, OGF = 0x%x, OCF = 0x%x, Status = 0x%x, Num_HCI_COMM = 0x%x\n",
1120 (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), OGF, OCF, HciStatus, Num_Hci_Comm));
1122 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1123 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_STATUS;
1124 PPacketIrpEvent->Length = 4;
1125 PPacketIrpEvent->Data[0] = HciStatus; /* current pending */
1126 PPacketIrpEvent->Data[1] = Num_Hci_Comm; /* packet # */
1127 PPacketIrpEvent->Data[2] = HCIOPCODELOW(OCF, OGF);
1128 PPacketIrpEvent->Data[3] = HCIOPCODEHIGHT(OCF, OGF);
1130 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1135 bthci_EventLogicalLinkComplete(
1136 struct rtw_adapter *padapter,
1137 enum hci_status HciStatus,
1144 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1145 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1146 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1147 u8 localBuf[7] = "";
1148 struct packet_irp_hcievent_data *PPacketIrpEvent;
1150 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_LOGICAL_LINK_COMPLETE)) {
1151 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1152 ("[BT event], Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1155 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Logical Link Complete, PhyLinkHandle = 0x%x, LogLinkHandle = 0x%x, Status = 0x%x\n",
1156 PhyLinkHandle, LogLinkHandle, HciStatus));
1158 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1159 PPacketIrpEvent->EventCode = HCI_EVENT_LOGICAL_LINK_COMPLETE;
1160 PPacketIrpEvent->Length = 5;
1162 PPacketIrpEvent->Data[0] = HciStatus;/* status code */
1163 /* Logical link handle */
1164 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1165 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1166 /* Physical link handle */
1167 PPacketIrpEvent->Data[3] = TWOBYTE_LOWBYTE(PhyLinkHandle);
1168 /* corresponding Tx flow spec ID */
1169 if (HciStatus == HCI_STATUS_SUCCESS) {
1170 PPacketIrpEvent->Data[4] =
1171 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData[LogLinkIndex].Tx_Flow_Spec.Identifier;
1173 PPacketIrpEvent->Data[4] = 0x0;
1176 bthci_IndicateEvent(padapter, PPacketIrpEvent, 7);
1180 bthci_EventDisconnectLogicalLinkComplete(
1181 struct rtw_adapter *padapter,
1182 enum hci_status HciStatus,
1184 enum hci_status Reason
1187 u8 localBuf[6] = "";
1188 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1189 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1190 struct packet_irp_hcievent_data *PPacketIrpEvent;
1192 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE)) {
1193 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1196 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Status = 0x%x, LLH = 0x%x Reason = 0x%x\n", HciStatus, LogLinkHandle, Reason));
1198 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1199 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE;
1200 PPacketIrpEvent->Length = 4;
1202 PPacketIrpEvent->Data[0] = HciStatus;
1203 /* Logical link handle */
1204 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1205 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1206 /* Disconnect reason */
1207 PPacketIrpEvent->Data[3] = Reason;
1209 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1213 bthci_EventFlushOccurred(
1214 struct rtw_adapter *padapter,
1218 u8 localBuf[4] = "";
1219 struct packet_irp_hcievent_data *PPacketIrpEvent;
1220 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("bthci_EventFlushOccurred(), LLH = 0x%x\n", LogLinkHandle));
1222 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1223 PPacketIrpEvent->EventCode = HCI_EVENT_FLUSH_OCCRUED;
1224 PPacketIrpEvent->Length = 2;
1225 /* Logical link handle */
1226 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LogLinkHandle);
1227 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1229 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1232 static enum hci_status
1233 bthci_BuildPhysicalLink(
1234 struct rtw_adapter *padapter,
1235 struct packet_irp_hcicmd_data *pHciCmd,
1239 enum hci_status status = HCI_STATUS_SUCCESS;
1240 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1241 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1244 /* Send HCI Command status event to AMP. */
1245 bthci_EventCommandStatus(padapter,
1246 LINK_CONTROL_COMMANDS,
1248 HCI_STATUS_SUCCESS);
1250 PLH = *((u8 *)pHciCmd->Data);
1252 /* Check if resource or bt connection is under progress, if yes, reject the link creation. */
1253 if (!bthci_AddEntry(padapter)) {
1254 status = HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE;
1255 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1259 EntryNum = pBtMgnt->CurrentConnectEntryNum;
1260 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = PLH;
1261 pBtMgnt->BtCurrentPhyLinkhandle = PLH;
1263 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1264 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Create/Accept PhysicalLink, AMP controller is busy\n"));
1265 status = HCI_STATUS_CONTROLLER_BUSY;
1266 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1270 /* Record Key and the info */
1271 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = (*((u8 *)pHciCmd->Data+1));
1272 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = (*((u8 *)pHciCmd->Data+2));
1273 memcpy(pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1274 (((u8 *)pHciCmd->Data+3)), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1275 memcpy(pBTInfo->BtAsocEntry[EntryNum].PMK, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, PMK_LEN);
1276 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildPhysicalLink, EntryNum = %d, PLH = 0x%x KeyLen = 0x%x, KeyType = 0x%x\n",
1277 EntryNum, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1278 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen,
1279 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType));
1280 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("BtAMPKey\n"), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1281 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1282 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("PMK\n"), pBTInfo->BtAsocEntry[EntryNum].PMK,
1285 if (OCF == HCI_CREATE_PHYSICAL_LINK) {
1286 /* These macros require braces */
1287 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_CREATE_PHY_LINK, EntryNum);
1288 } else if (OCF == HCI_ACCEPT_PHYSICAL_LINK) {
1289 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ACCEPT_PHY_LINK, EntryNum);
1296 bthci_BuildLogicalLink(
1297 struct rtw_adapter *padapter,
1298 struct packet_irp_hcicmd_data *pHciCmd,
1302 enum hci_status status = HCI_STATUS_SUCCESS;
1303 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1304 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
1305 u8 PhyLinkHandle, EntryNum;
1306 static u16 AssignLogHandle = 1;
1308 struct hci_flow_spec TxFlowSpec;
1309 struct hci_flow_spec RxFlowSpec;
1310 u32 MaxSDUSize, ArriveTime, Bandwidth;
1312 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1314 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1317 &pHciCmd->Data[1], sizeof(struct hci_flow_spec));
1319 &pHciCmd->Data[17], sizeof(struct hci_flow_spec));
1321 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
1322 ArriveTime = TxFlowSpec.SDUInterArrivalTime;
1324 if (bthci_CheckLogLinkBehavior(padapter, TxFlowSpec) && bthci_CheckLogLinkBehavior(padapter, RxFlowSpec))
1325 Bandwidth = BTTOTALBANDWIDTH;
1326 else if (MaxSDUSize == 0xffff && ArriveTime == 0xffffffff)
1327 Bandwidth = BTTOTALBANDWIDTH;
1329 Bandwidth = MaxSDUSize*8*1000/(ArriveTime+244);
1331 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
1332 ("BuildLogicalLink, PhyLinkHandle = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, Bandwidth = 0x%x\n",
1333 PhyLinkHandle, MaxSDUSize, ArriveTime, Bandwidth));
1335 if (EntryNum == 0xff) {
1336 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Invalid Physical Link handle = 0x%x, status = HCI_STATUS_UNKNOW_CONNECT_ID, return\n", PhyLinkHandle));
1337 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1339 /* When we receive Create/Accept logical link command, we should send command status event first. */
1340 bthci_EventCommandStatus(padapter,
1341 LINK_CONTROL_COMMANDS,
1347 if (!pBtMgnt->bLogLinkInProgress) {
1348 if (bthci_PhyLinkConnectionInProgress(padapter, PhyLinkHandle)) {
1349 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Physical link connection in progress, status = HCI_STATUS_CMD_DISALLOW, return\n"));
1350 status = HCI_STATUS_CMD_DISALLOW;
1352 pBtMgnt->bPhyLinkInProgressStartLL = true;
1353 /* When we receive Create/Accept logical link command, we should send command status event first. */
1354 bthci_EventCommandStatus(padapter,
1355 LINK_CONTROL_COMMANDS,
1362 if (Bandwidth > BTTOTALBANDWIDTH) {
1363 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_QOS_REJECT, Bandwidth = 0x%x, return\n", Bandwidth));
1364 status = HCI_STATUS_QOS_REJECT;
1366 /* When we receive Create/Accept logical link command, we should send command status event first. */
1367 bthci_EventCommandStatus(padapter,
1368 LINK_CONTROL_COMMANDS,
1372 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_SUCCESS\n"));
1373 status = HCI_STATUS_SUCCESS;
1375 /* When we receive Create/Accept logical link command, we should send command status event first. */
1376 bthci_EventCommandStatus(padapter,
1377 LINK_CONTROL_COMMANDS,
1383 if (pBTinfo->BtAsocEntry[EntryNum].BtCurrentState != HCI_STATE_CONNECTED) {
1384 bthci_EventLogicalLinkComplete(padapter,
1385 HCI_STATUS_CMD_DISALLOW, 0, 0, 0, EntryNum);
1389 pBtMgnt->bLogLinkInProgress = true;
1391 /* find an unused logical link index and copy the data */
1392 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
1393 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle == 0) {
1394 enum hci_status LogCompEventstatus = HCI_STATUS_SUCCESS;
1396 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
1397 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle = AssignLogHandle;
1398 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildLogicalLink, EntryNum = %d, physical link handle = 0x%x, logical link handle = 0x%x\n",
1399 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1400 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle));
1401 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Tx_Flow_Spec,
1402 &TxFlowSpec, sizeof(struct hci_flow_spec));
1403 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Rx_Flow_Spec,
1404 &RxFlowSpec, sizeof(struct hci_flow_spec));
1406 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = false;
1408 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCancelCMDIsSetandComplete)
1409 LogCompEventstatus = HCI_STATUS_UNKNOW_CONNECT_ID;
1410 bthci_EventLogicalLinkComplete(padapter,
1412 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle,
1413 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle, i, EntryNum);
1415 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = true;
1418 pBtMgnt->BtCurrentLogLinkhandle = AssignLogHandle;
1425 bthci_EventLogicalLinkComplete(padapter,
1426 HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE, 0, 0, 0, EntryNum);
1428 pBtMgnt->bLogLinkInProgress = false;
1431 bthci_EventLogicalLinkComplete(padapter,
1432 HCI_STATUS_CONTROLLER_BUSY, 0, 0, 0, EntryNum);
1438 bthci_StartBeaconAndConnect(
1439 struct rtw_adapter *padapter,
1440 struct packet_irp_hcicmd_data *pHciCmd,
1444 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1445 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1446 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1448 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("StartBeaconAndConnect, CurrentAssocNum =%d, AMPRole =%d\n",
1450 pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole));
1452 if (!pBtMgnt->CheckChnlIsSuit) {
1453 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONNECT_REJ_NOT_SUIT_CHNL_FOUND, CurrentAssocNum, INVALID_PL_HANDLE);
1454 bthci_RemoveEntryByEntryNum(padapter, CurrentAssocNum);
1458 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1459 rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
1460 padapter->eeprompriv.mac_addr[0],
1461 padapter->eeprompriv.mac_addr[1],
1462 padapter->eeprompriv.mac_addr[2],
1463 padapter->eeprompriv.mac_addr[3],
1464 padapter->eeprompriv.mac_addr[4],
1465 padapter->eeprompriv.mac_addr[5]);
1466 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1467 rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
1468 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[0],
1469 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[1],
1470 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[2],
1471 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[3],
1472 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[4],
1473 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[5]);
1476 FillOctetString(pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid, pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 21);
1477 pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid.Length = 21;
1479 /* To avoid set the start ap or connect twice, or the original connection will be disconnected. */
1480 if (!pBtMgnt->bBTConnectInProgress) {
1481 pBtMgnt->bBTConnectInProgress = true;
1482 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress ON!!\n"));
1483 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_STARTING, STATE_CMD_MAC_START_COMPLETE, CurrentAssocNum);
1485 /* 20100325 Joseph: Check RF ON/OFF. */
1486 /* If RF OFF, it reschedule connecting operation after 50ms. */
1487 if (!bthci_CheckRfStateBeforeConnect(padapter))
1490 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1491 /* These macros need braces */
1492 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_COMPLETE, CurrentAssocNum);
1493 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1494 bthci_ResponderStartToScan(padapter);
1497 RT_PRINT_STR(_module_rtl871x_mlme_c_, _drv_notice_,
1498 "StartBeaconAndConnect, SSID:\n",
1499 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Octet,
1500 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Length);
1503 static void bthci_ResetBtMgnt(struct bt_mgnt *pBtMgnt)
1505 pBtMgnt->BtOperationOn = false;
1506 pBtMgnt->bBTConnectInProgress = false;
1507 pBtMgnt->bLogLinkInProgress = false;
1508 pBtMgnt->bPhyLinkInProgress = false;
1509 pBtMgnt->bPhyLinkInProgressStartLL = false;
1510 pBtMgnt->DisconnectEntryNum = 0xff;
1511 pBtMgnt->bStartSendSupervisionPkt = false;
1512 pBtMgnt->JoinerNeedSendAuth = false;
1513 pBtMgnt->CurrentBTConnectionCnt = 0;
1514 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
1515 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
1516 pBtMgnt->BTAuthCount = 0;
1517 pBtMgnt->btLogoTest = 0;
1520 static void bthci_ResetBtHciInfo(struct bt_hci_info *pBtHciInfo)
1522 pBtHciInfo->BTEventMask = 0;
1523 pBtHciInfo->BTEventMaskPage2 = 0;
1524 pBtHciInfo->ConnAcceptTimeout = 10000;
1525 pBtHciInfo->PageTimeout = 0x30;
1526 pBtHciInfo->LocationDomainAware = 0x0;
1527 pBtHciInfo->LocationDomain = 0x5858;
1528 pBtHciInfo->LocationDomainOptions = 0x58;
1529 pBtHciInfo->LocationOptions = 0x0;
1530 pBtHciInfo->FlowControlMode = 0x1; /* 0:Packet based data flow control mode(BR/EDR), 1: Data block based data flow control mode(AMP). */
1532 pBtHciInfo->enFlush_LLH = 0;
1533 pBtHciInfo->FLTO_LLH = 0;
1535 /* Test command only */
1536 pBtHciInfo->bTestIsEnd = true;
1537 pBtHciInfo->bInTestMode = false;
1538 pBtHciInfo->bTestNeedReport = false;
1539 pBtHciInfo->TestScenario = 0xff;
1540 pBtHciInfo->TestReportInterval = 0x01;
1541 pBtHciInfo->TestCtrType = 0x5d;
1542 pBtHciInfo->TestEventType = 0x00;
1543 pBtHciInfo->TestNumOfFrame = 0;
1544 pBtHciInfo->TestNumOfErrFrame = 0;
1545 pBtHciInfo->TestNumOfBits = 0;
1546 pBtHciInfo->TestNumOfErrBits = 0;
1549 static void bthci_ResetBtSec(struct rtw_adapter *padapter, struct bt_security *pBtSec)
1551 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1553 /* Set BT used HW or SW encrypt !! */
1554 if (GET_HAL_DATA(padapter)->bBTMode)
1555 pBtSec->bUsedHwEncrypt = true;
1557 pBtSec->bUsedHwEncrypt = false;
1558 RT_TRACE(_module_rtl871x_security_c_, _drv_info_, ("%s: bUsedHwEncrypt =%d\n", __func__, pBtSec->bUsedHwEncrypt));
1560 pBtSec->RSNIE.Octet = pBtSec->RSNIEBuf;
1563 static void bthci_ResetBtExtInfo(struct bt_mgnt *pBtMgnt)
1567 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
1568 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = 0;
1569 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = 0;
1570 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = 0;
1571 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = BT_PROFILE_NONE;
1572 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = BT_SPEC_2_1_EDR;
1573 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = 0;
1574 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
1575 pBtMgnt->ExtConfig.linkInfo[i].linkRole = BT_LINK_MASTER;
1578 pBtMgnt->ExtConfig.CurrentConnectHandle = 0;
1579 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = 0;
1580 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = 0;
1581 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
1582 pBtMgnt->ExtConfig.NumberOfHandle = 0;
1583 pBtMgnt->ExtConfig.NumberOfSCO = 0;
1584 pBtMgnt->ExtConfig.CurrentBTStatus = 0;
1585 pBtMgnt->ExtConfig.HCIExtensionVer = 0;
1587 pBtMgnt->ExtConfig.bManualControl = false;
1588 pBtMgnt->ExtConfig.bBTBusy = false;
1589 pBtMgnt->ExtConfig.bBTA2DPBusy = false;
1592 static enum hci_status bthci_CmdReset(struct rtw_adapter *_padapter, u8 bNeedSendEvent)
1594 enum hci_status status = HCI_STATUS_SUCCESS;
1595 struct rtw_adapter *padapter;
1596 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1597 struct bt_30info *pBTInfo;
1598 struct bt_mgnt *pBtMgnt;
1599 struct bt_hci_info *pBtHciInfo;
1600 struct bt_security *pBtSec;
1601 struct bt_dgb *pBtDbg;
1604 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_CmdReset()\n"));
1606 padapter = GetDefaultAdapter(_padapter);
1607 pBTInfo = GET_BT_INFO(padapter);
1608 pBtMgnt = &pBTInfo->BtMgnt;
1609 pBtHciInfo = &pBTInfo->BtHciInfo;
1610 pBtSec = &pBTInfo->BtSec;
1611 pBtDbg = &pBTInfo->BtDbg;
1613 pBTInfo->padapter = padapter;
1615 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++)
1616 bthci_ResetEntry(padapter, i);
1618 bthci_ResetBtMgnt(pBtMgnt);
1619 bthci_ResetBtHciInfo(pBtHciInfo);
1620 bthci_ResetBtSec(padapter, pBtSec);
1622 pBtMgnt->BTChannel = BT_Default_Chnl;
1623 pBtMgnt->CheckChnlIsSuit = true;
1625 pBTInfo->BTBeaconTmrOn = false;
1627 pBtMgnt->bCreateSpportQos = true;
1629 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
1630 del_timer_sync(&pBTInfo->BTBeaconTimer);
1632 HALBT_SetRtsCtsNoLenLimit(padapter);
1634 /* Maybe we need to take care Group != AES case !! */
1635 /* now we Pairwise and Group all used AES !! */
1637 bthci_ResetBtExtInfo(pBtMgnt);
1639 /* send command complete event here when all data are received. */
1640 if (bNeedSendEvent) {
1641 u8 localBuf[6] = "";
1644 struct packet_irp_hcievent_data *PPacketIrpEvent;
1646 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1648 len += bthci_CommandCompleteHeader(&localBuf[0],
1649 OGF_SET_EVENT_MASK_COMMAND,
1653 /* Return parameters starts from here */
1654 pRetPar = &PPacketIrpEvent->Data[len];
1655 pRetPar[0] = status; /* status */
1657 PPacketIrpEvent->Length = len;
1659 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1665 static enum hci_status
1666 bthci_CmdWriteRemoteAMPAssoc(
1667 struct rtw_adapter *padapter,
1668 struct packet_irp_hcicmd_data *pHciCmd
1671 enum hci_status status = HCI_STATUS_SUCCESS;
1672 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1673 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1677 pBtDbg->dbgHciInfo.hciCmdCntWriteRemoteAmpAssoc++;
1678 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1679 CurrentAssocNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1681 if (CurrentAssocNum == 0xff) {
1682 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, No such Handle in the Entry\n"));
1683 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1684 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1688 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1689 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, AMP controller is busy\n"));
1690 status = HCI_STATUS_CONTROLLER_BUSY;
1691 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1695 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.BtPhyLinkhandle = PhyLinkHandle;/* u8 *)pHciCmd->Data); */
1696 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
1697 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen = *((u16 *)((u8 *)pHciCmd->Data+3));
1699 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, LenSoFar = 0x%x, AssocRemLen = 0x%x\n",
1700 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar,
1701 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1703 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
1704 ("WriteRemoteAMPAssoc fragment \n"),
1706 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen+5);
1707 if ((pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen) > MAX_AMP_ASSOC_FRAG_LEN) {
1708 memcpy(((u8 *)pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8)))),
1709 (u8 *)pHciCmd->Data+5,
1710 MAX_AMP_ASSOC_FRAG_LEN);
1712 memcpy((u8 *)(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment)+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8))),
1713 ((u8 *)pHciCmd->Data+5),
1714 (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1716 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "WriteRemoteAMPAssoc :\n",
1717 pHciCmd->Data+5, pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen);
1719 if (!bthci_GetAssocInfo(padapter, CurrentAssocNum))
1720 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
1722 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1724 bthci_StartBeaconAndConnect(padapter, pHciCmd, CurrentAssocNum);
1731 static enum hci_status bthci_CmdReadConnectionAcceptTimeout(struct rtw_adapter *padapter)
1733 enum hci_status status = HCI_STATUS_SUCCESS;
1734 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1735 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1736 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1737 u8 localBuf[8] = "";
1740 struct packet_irp_hcievent_data *PPacketIrpEvent;
1743 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1745 len += bthci_CommandCompleteHeader(&localBuf[0],
1746 OGF_SET_EVENT_MASK_COMMAND,
1747 HCI_READ_CONNECTION_ACCEPT_TIMEOUT,
1750 /* Return parameters starts from here */
1751 pRetPar = &PPacketIrpEvent->Data[len];
1752 pRetPar[0] = status; /* status */
1753 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
1754 *pu2Temp = pBtHciInfo->ConnAcceptTimeout;
1756 PPacketIrpEvent->Length = len;
1758 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1764 static enum hci_status
1765 bthci_CmdSetEventFilter(
1766 struct rtw_adapter *padapter,
1767 struct packet_irp_hcicmd_data *pHciCmd
1770 enum hci_status status = HCI_STATUS_SUCCESS;
1776 static enum hci_status
1777 bthci_CmdWriteConnectionAcceptTimeout(
1778 struct rtw_adapter *padapter,
1779 struct packet_irp_hcicmd_data *pHciCmd
1782 enum hci_status status = HCI_STATUS_SUCCESS;
1783 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1784 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1786 u8 localBuf[6] = "";
1789 struct packet_irp_hcievent_data *PPacketIrpEvent;
1791 pu2Temp = (u16 *)&pHciCmd->Data[0];
1792 pBtHciInfo->ConnAcceptTimeout = *pu2Temp;
1793 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ConnAcceptTimeout = 0x%x",
1794 pBtHciInfo->ConnAcceptTimeout));
1796 /* send command complete event here when all data are received. */
1797 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1799 len += bthci_CommandCompleteHeader(&localBuf[0],
1800 OGF_SET_EVENT_MASK_COMMAND,
1801 HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT,
1804 /* Return parameters starts from here */
1805 pRetPar = &PPacketIrpEvent->Data[len];
1806 pRetPar[0] = status; /* status */
1808 PPacketIrpEvent->Length = len;
1810 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1815 static enum hci_status
1816 bthci_CmdReadPageTimeout(
1817 struct rtw_adapter *padapter,
1818 struct packet_irp_hcicmd_data *pHciCmd
1821 enum hci_status status = HCI_STATUS_SUCCESS;
1822 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1823 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1824 u8 localBuf[8] = "";
1827 struct packet_irp_hcievent_data *PPacketIrpEvent;
1830 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1832 len += bthci_CommandCompleteHeader(&localBuf[0],
1833 OGF_SET_EVENT_MASK_COMMAND,
1834 HCI_READ_PAGE_TIMEOUT,
1837 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Read PageTimeout = 0x%x\n", pBtHciInfo->PageTimeout));
1838 /* Return parameters starts from here */
1839 pRetPar = &PPacketIrpEvent->Data[len];
1840 pRetPar[0] = status; /* status */
1841 pu2Temp = (u16 *)&pRetPar[1]; /* Page_Timeout */
1842 *pu2Temp = pBtHciInfo->PageTimeout;
1844 PPacketIrpEvent->Length = len;
1846 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1851 static enum hci_status
1852 bthci_CmdWritePageTimeout(
1853 struct rtw_adapter *padapter,
1854 struct packet_irp_hcicmd_data *pHciCmd
1857 enum hci_status status = HCI_STATUS_SUCCESS;
1858 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1859 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1862 pu2Temp = (u16 *)&pHciCmd->Data[0];
1863 pBtHciInfo->PageTimeout = *pu2Temp;
1864 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Write PageTimeout = 0x%x\n",
1865 pBtHciInfo->PageTimeout));
1867 /* send command complete event here when all data are received. */
1869 u8 localBuf[6] = "";
1872 struct packet_irp_hcievent_data *PPacketIrpEvent;
1874 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1876 len += bthci_CommandCompleteHeader(&localBuf[0],
1877 OGF_SET_EVENT_MASK_COMMAND,
1878 HCI_WRITE_PAGE_TIMEOUT,
1881 /* Return parameters starts from here */
1882 pRetPar = &PPacketIrpEvent->Data[len];
1883 pRetPar[0] = status; /* status */
1885 PPacketIrpEvent->Length = len;
1887 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1893 static enum hci_status
1894 bthci_CmdReadLinkSupervisionTimeout(
1895 struct rtw_adapter *padapter,
1896 struct packet_irp_hcicmd_data *pHciCmd
1899 enum hci_status status = HCI_STATUS_SUCCESS;
1900 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1901 u8 physicalLinkHandle, EntryNum;
1903 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1905 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1907 if (EntryNum == 0xff) {
1908 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLinkSupervisionTimeout, No such Handle in the Entry\n"));
1909 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1913 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle)
1914 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1917 u8 localBuf[10] = "";
1920 struct packet_irp_hcievent_data *PPacketIrpEvent;
1923 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1925 len += bthci_CommandCompleteHeader(&localBuf[0],
1926 OGF_SET_EVENT_MASK_COMMAND,
1927 HCI_READ_LINK_SUPERVISION_TIMEOUT,
1930 /* Return parameters starts from here */
1931 pRetPar = &PPacketIrpEvent->Data[len];
1932 pRetPar[0] = status;
1933 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1935 pu2Temp = (u16 *)&pRetPar[3]; /* Conn_Accept_Timeout */
1936 *pu2Temp = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout;
1938 PPacketIrpEvent->Length = len;
1940 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1946 static enum hci_status
1947 bthci_CmdWriteLinkSupervisionTimeout(
1948 struct rtw_adapter *padapter,
1949 struct packet_irp_hcicmd_data *pHciCmd
1952 enum hci_status status = HCI_STATUS_SUCCESS;
1953 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1954 u8 physicalLinkHandle, EntryNum;
1956 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1958 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1960 if (EntryNum == 0xff) {
1961 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("WriteLinkSupervisionTimeout, No such Handle in the Entry\n"));
1962 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1964 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle) {
1965 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1967 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = *((u16 *)(((u8 *)pHciCmd->Data)+2));
1968 RTPRINT(FIOCTL, IOCTL_STATE, ("BT Write LinkSuperversionTimeout[%d] = 0x%x\n",
1969 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout));
1974 u8 localBuf[8] = "";
1977 struct packet_irp_hcievent_data *PPacketIrpEvent;
1979 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1981 len += bthci_CommandCompleteHeader(&localBuf[0],
1982 OGF_SET_EVENT_MASK_COMMAND,
1983 HCI_WRITE_LINK_SUPERVISION_TIMEOUT,
1986 /* Return parameters starts from here */
1987 pRetPar = &PPacketIrpEvent->Data[len];
1988 pRetPar[0] = status;
1989 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1992 PPacketIrpEvent->Length = len;
1994 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2000 static enum hci_status
2001 bthci_CmdEnhancedFlush(
2002 struct rtw_adapter *padapter,
2003 struct packet_irp_hcicmd_data *pHciCmd
2006 enum hci_status status = HCI_STATUS_SUCCESS;
2007 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2008 struct bt_hci_info *pBtHciInfo = &pBTinfo->BtHciInfo;
2012 logicHandle = *((u16 *)&pHciCmd->Data[0]);
2013 Packet_Type = pHciCmd->Data[2];
2015 if (Packet_Type != 0)
2016 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
2018 pBtHciInfo->enFlush_LLH = logicHandle;
2020 if (bthci_DiscardTxPackets(padapter, pBtHciInfo->enFlush_LLH))
2021 bthci_EventFlushOccurred(padapter, pBtHciInfo->enFlush_LLH);
2023 /* should send command status event */
2024 bthci_EventCommandStatus(padapter,
2025 OGF_SET_EVENT_MASK_COMMAND,
2029 if (pBtHciInfo->enFlush_LLH) {
2030 bthci_EventEnhancedFlushComplete(padapter, pBtHciInfo->enFlush_LLH);
2031 pBtHciInfo->enFlush_LLH = 0;
2037 static enum hci_status
2038 bthci_CmdReadLogicalLinkAcceptTimeout(
2039 struct rtw_adapter *padapter,
2040 struct packet_irp_hcicmd_data *pHciCmd
2043 enum hci_status status = HCI_STATUS_SUCCESS;
2044 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2045 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2046 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2047 u8 localBuf[8] = "";
2050 struct packet_irp_hcievent_data *PPacketIrpEvent;
2053 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2055 len += bthci_CommandCompleteHeader(&localBuf[0],
2056 OGF_SET_EVENT_MASK_COMMAND,
2057 HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT,
2060 /* Return parameters starts from here */
2061 pRetPar = &PPacketIrpEvent->Data[len];
2062 pRetPar[0] = status;
2064 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
2065 *pu2Temp = pBtHciInfo->LogicalAcceptTimeout;
2067 PPacketIrpEvent->Length = len;
2069 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2074 static enum hci_status
2075 bthci_CmdWriteLogicalLinkAcceptTimeout(
2076 struct rtw_adapter *padapter,
2077 struct packet_irp_hcicmd_data *pHciCmd
2080 enum hci_status status = HCI_STATUS_SUCCESS;
2081 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2082 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2083 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2084 u8 localBuf[6] = "";
2087 struct packet_irp_hcievent_data *PPacketIrpEvent;
2089 pBtHciInfo->LogicalAcceptTimeout = *((u16 *)pHciCmd->Data);
2091 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2093 len += bthci_CommandCompleteHeader(&localBuf[0],
2094 OGF_SET_EVENT_MASK_COMMAND,
2095 HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT,
2098 /* Return parameters starts from here */
2099 pRetPar = &PPacketIrpEvent->Data[len];
2100 pRetPar[0] = status;
2103 PPacketIrpEvent->Length = len;
2105 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2109 static enum hci_status
2110 bthci_CmdSetEventMask(
2111 struct rtw_adapter *padapter,
2112 struct packet_irp_hcicmd_data *pHciCmd
2115 enum hci_status status = HCI_STATUS_SUCCESS;
2116 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2117 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2118 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2120 u8 localBuf[6] = "";
2123 struct packet_irp_hcievent_data *PPacketIrpEvent;
2125 pu8Temp = (u8 *)&pHciCmd->Data[0];
2126 pBtHciInfo->BTEventMask = *pu8Temp;
2127 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("BTEventMask = 0x%"i64fmt"x\n",
2128 pBtHciInfo->BTEventMask));
2130 /* send command complete event here when all data are received. */
2131 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2133 len += bthci_CommandCompleteHeader(&localBuf[0],
2134 OGF_SET_EVENT_MASK_COMMAND,
2138 /* Return parameters starts from here */
2139 pRetPar = &PPacketIrpEvent->Data[len];
2140 pRetPar[0] = status; /* status */
2142 PPacketIrpEvent->Length = len;
2144 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2150 static enum hci_status
2151 bthci_CmdSetEventMaskPage2(
2152 struct rtw_adapter *padapter,
2153 struct packet_irp_hcicmd_data *pHciCmd
2156 enum hci_status status = HCI_STATUS_SUCCESS;
2157 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2158 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2160 u8 localBuf[6] = "";
2163 struct packet_irp_hcievent_data *PPacketIrpEvent;
2165 pu8Temp = (u8 *)&pHciCmd->Data[0];
2166 pBtHciInfo->BTEventMaskPage2 = *pu8Temp;
2167 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("BTEventMaskPage2 = 0x%"i64fmt"x\n",
2168 pBtHciInfo->BTEventMaskPage2));
2170 /* send command complete event here when all data are received. */
2171 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2173 len += bthci_CommandCompleteHeader(&localBuf[0],
2174 OGF_SET_EVENT_MASK_COMMAND,
2175 HCI_SET_EVENT_MASK_PAGE_2,
2178 /* Return parameters starts from here */
2179 pRetPar = &PPacketIrpEvent->Data[len];
2180 pRetPar[0] = status; /* status */
2182 PPacketIrpEvent->Length = len;
2184 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2189 static enum hci_status
2190 bthci_CmdReadLocationData(
2191 struct rtw_adapter *padapter,
2192 struct packet_irp_hcicmd_data *pHciCmd
2195 enum hci_status status = HCI_STATUS_SUCCESS;
2196 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2197 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2198 u8 localBuf[12] = "";
2201 struct packet_irp_hcievent_data *PPacketIrpEvent;
2204 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2206 len += bthci_CommandCompleteHeader(&localBuf[0],
2207 OGF_SET_EVENT_MASK_COMMAND,
2208 HCI_READ_LOCATION_DATA,
2210 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2211 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2212 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2213 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2215 /* Return parameters starts from here */
2216 pRetPar = &PPacketIrpEvent->Data[len];
2217 pRetPar[0] = status;
2219 pRetPar[1] = pBtHciInfo->LocationDomainAware; /* 0x0; Location_Domain_Aware */
2220 pu2Temp = (u16 *)&pRetPar[2]; /* Location_Domain */
2221 *pu2Temp = pBtHciInfo->LocationDomain; /* 0x5858; */
2222 pRetPar[4] = pBtHciInfo->LocationDomainOptions; /* 0x58; Location_Domain_Options */
2223 pRetPar[5] = pBtHciInfo->LocationOptions; /* 0x0; Location_Options */
2225 PPacketIrpEvent->Length = len;
2227 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2231 static enum hci_status
2232 bthci_CmdWriteLocationData(
2233 struct rtw_adapter *padapter,
2234 struct packet_irp_hcicmd_data *pHciCmd
2237 enum hci_status status = HCI_STATUS_SUCCESS;
2238 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2239 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2241 u8 localBuf[6] = "";
2244 struct packet_irp_hcievent_data *PPacketIrpEvent;
2246 pBtHciInfo->LocationDomainAware = pHciCmd->Data[0];
2247 pu2Temp = (u16 *)&pHciCmd->Data[1];
2248 pBtHciInfo->LocationDomain = *pu2Temp;
2249 pBtHciInfo->LocationDomainOptions = pHciCmd->Data[3];
2250 pBtHciInfo->LocationOptions = pHciCmd->Data[4];
2251 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2252 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2253 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2254 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2256 /* send command complete event here when all data are received. */
2257 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2259 len += bthci_CommandCompleteHeader(&localBuf[0],
2260 OGF_SET_EVENT_MASK_COMMAND,
2261 HCI_WRITE_LOCATION_DATA,
2264 /* Return parameters starts from here */
2265 pRetPar = &PPacketIrpEvent->Data[len];
2266 pRetPar[0] = status; /* status */
2268 PPacketIrpEvent->Length = len;
2270 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2275 static enum hci_status
2276 bthci_CmdReadFlowControlMode(
2277 struct rtw_adapter *padapter,
2278 struct packet_irp_hcicmd_data *pHciCmd
2281 enum hci_status status = HCI_STATUS_SUCCESS;
2282 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2283 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2284 u8 localBuf[7] = "";
2287 struct packet_irp_hcievent_data *PPacketIrpEvent;
2289 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2291 len += bthci_CommandCompleteHeader(&localBuf[0],
2292 OGF_SET_EVENT_MASK_COMMAND,
2293 HCI_READ_FLOW_CONTROL_MODE,
2296 /* Return parameters starts from here */
2297 pRetPar = &PPacketIrpEvent->Data[len];
2298 pRetPar[0] = status;
2299 pRetPar[1] = pBtHciInfo->FlowControlMode; /* Flow Control Mode */
2301 PPacketIrpEvent->Length = len;
2303 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2307 static enum hci_status
2308 bthci_CmdWriteFlowControlMode(
2309 struct rtw_adapter *padapter,
2310 struct packet_irp_hcicmd_data *pHciCmd
2313 enum hci_status status = HCI_STATUS_SUCCESS;
2314 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2315 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2316 u8 localBuf[6] = "";
2319 struct packet_irp_hcievent_data *PPacketIrpEvent;
2321 pBtHciInfo->FlowControlMode = pHciCmd->Data[0];
2323 /* send command complete event here when all data are received. */
2324 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2326 len += bthci_CommandCompleteHeader(&localBuf[0],
2327 OGF_SET_EVENT_MASK_COMMAND,
2328 HCI_WRITE_FLOW_CONTROL_MODE,
2331 /* Return parameters starts from here */
2332 pRetPar = &PPacketIrpEvent->Data[len];
2333 pRetPar[0] = status; /* status */
2335 PPacketIrpEvent->Length = len;
2337 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2342 static enum hci_status
2343 bthci_CmdReadBestEffortFlushTimeout(
2344 struct rtw_adapter *padapter,
2345 struct packet_irp_hcicmd_data *pHciCmd
2348 enum hci_status status = HCI_STATUS_SUCCESS;
2349 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2350 u16 i, j, logicHandle;
2351 u32 BestEffortFlushTimeout = 0xffffffff;
2354 logicHandle = *((u16 *)pHciCmd->Data);
2355 /* find an matched logical link index and copy the data */
2356 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2357 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2358 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2359 BestEffortFlushTimeout = pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout;
2367 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2370 u8 localBuf[10] = "";
2373 struct packet_irp_hcievent_data *PPacketIrpEvent;
2376 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2378 len += bthci_CommandCompleteHeader(&localBuf[0],
2379 OGF_SET_EVENT_MASK_COMMAND,
2380 HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT,
2383 /* Return parameters starts from here */
2384 pRetPar = &PPacketIrpEvent->Data[len];
2385 pRetPar[0] = status;
2386 pu4Temp = (u32 *)&pRetPar[1]; /* Best_Effort_Flush_Timeout */
2387 *pu4Temp = BestEffortFlushTimeout;
2389 PPacketIrpEvent->Length = len;
2391 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2396 static enum hci_status
2397 bthci_CmdWriteBestEffortFlushTimeout(
2398 struct rtw_adapter *padapter,
2399 struct packet_irp_hcicmd_data *pHciCmd
2402 enum hci_status status = HCI_STATUS_SUCCESS;
2403 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2404 u16 i, j, logicHandle;
2405 u32 BestEffortFlushTimeout = 0xffffffff;
2408 logicHandle = *((u16 *)pHciCmd->Data);
2409 BestEffortFlushTimeout = *((u32 *)(pHciCmd->Data+1));
2411 /* find an matched logical link index and copy the data */
2412 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2413 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2414 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2415 pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout = BestEffortFlushTimeout;
2423 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2426 u8 localBuf[6] = "";
2429 struct packet_irp_hcievent_data *PPacketIrpEvent;
2431 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2433 len += bthci_CommandCompleteHeader(&localBuf[0],
2434 OGF_SET_EVENT_MASK_COMMAND,
2435 HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT,
2438 /* Return parameters starts from here */
2439 pRetPar = &PPacketIrpEvent->Data[len];
2440 pRetPar[0] = status;
2442 PPacketIrpEvent->Length = len;
2444 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2449 static enum hci_status
2450 bthci_CmdShortRangeMode(
2451 struct rtw_adapter *padapter,
2452 struct packet_irp_hcicmd_data *pHciCmd
2455 enum hci_status status = HCI_STATUS_SUCCESS;
2456 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2457 u8 PhyLinkHandle, EntryNum, ShortRangeMode;
2459 PhyLinkHandle = pHciCmd->Data[0];
2460 ShortRangeMode = pHciCmd->Data[1];
2461 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x, Short_Range_Mode = 0x%x\n", PhyLinkHandle, ShortRangeMode));
2463 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2464 if (EntryNum != 0xff) {
2465 pBTInfo->BtAsocEntry[EntryNum].ShortRangeMode = ShortRangeMode;
2467 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PhyLinkHandle));
2468 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2471 bthci_EventCommandStatus(padapter,
2472 OGF_SET_EVENT_MASK_COMMAND,
2473 HCI_SHORT_RANGE_MODE,
2476 bthci_EventShortRangeModeChangeComplete(padapter, status, ShortRangeMode, EntryNum);
2481 static enum hci_status bthci_CmdReadLocalSupportedCommands(struct rtw_adapter *padapter)
2483 enum hci_status status = HCI_STATUS_SUCCESS;
2484 u8 localBuf[TmpLocalBufSize] = "";
2485 u8 *pRetPar, *pSupportedCmds;
2487 struct packet_irp_hcievent_data *PPacketIrpEvent;
2489 /* send command complete event here when all data are received. */
2490 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2491 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2493 len += bthci_CommandCompleteHeader(&localBuf[0],
2494 OGF_INFORMATIONAL_PARAMETERS,
2495 HCI_READ_LOCAL_SUPPORTED_COMMANDS,
2498 /* Return parameters starts from here */
2499 pRetPar = &PPacketIrpEvent->Data[len];
2500 pRetPar[0] = status; /* status */
2502 pSupportedCmds = &pRetPar[1];
2503 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[5]= 0xc0\nBit [6]= Set Event Mask, [7]= Reset\n"));
2504 pSupportedCmds[5] = 0xc0;
2505 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[6]= 0x01\nBit [0]= Set Event Filter\n"));
2506 pSupportedCmds[6] = 0x01;
2507 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[7]= 0x0c\nBit [2]= Read Connection Accept Timeout, [3]= Write Connection Accept Timeout\n"));
2508 pSupportedCmds[7] = 0x0c;
2509 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[10]= 0x80\nBit [7]= Host Number Of Completed Packets\n"));
2510 pSupportedCmds[10] = 0x80;
2511 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[11]= 0x03\nBit [0]= Read Link Supervision Timeout, [1]= Write Link Supervision Timeout\n"));
2512 pSupportedCmds[11] = 0x03;
2513 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"));
2514 pSupportedCmds[14] = 0xa8;
2515 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"));
2516 pSupportedCmds[15] = 0x1c;
2517 /* pSupportedCmds[16] = 0x04; */
2518 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[19]= 0x40\nBit [6]= Enhanced Flush\n"));
2519 pSupportedCmds[19] = 0x40;
2520 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"));
2521 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"));
2522 pSupportedCmds[21] = 0xff;
2523 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"));
2524 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"));
2525 pSupportedCmds[22] = 0xff;
2526 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"));
2527 pSupportedCmds[23] = 0x07;
2528 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"));
2529 pSupportedCmds[24] = 0x1c;
2531 PPacketIrpEvent->Length = len;
2533 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2538 static enum hci_status bthci_CmdReadLocalSupportedFeatures(struct rtw_adapter *padapter)
2540 enum hci_status status = HCI_STATUS_SUCCESS;
2541 u8 localBuf[TmpLocalBufSize] = "";
2544 struct packet_irp_hcievent_data *PPacketIrpEvent;
2546 /* send command complete event here when all data are received. */
2547 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2548 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2550 len += bthci_CommandCompleteHeader(&localBuf[0],
2551 OGF_INFORMATIONAL_PARAMETERS,
2552 HCI_READ_LOCAL_SUPPORTED_FEATURES,
2555 /* Return parameters starts from here */
2556 pRetPar = &PPacketIrpEvent->Data[len];
2557 pRetPar[0] = status; /* status */
2559 PPacketIrpEvent->Length = len;
2561 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2565 static enum hci_status bthci_CmdReadLocalAMPAssoc(struct rtw_adapter *padapter,
2566 struct packet_irp_hcicmd_data *pHciCmd)
2568 enum hci_status status = HCI_STATUS_SUCCESS;
2569 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2570 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
2571 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2572 u8 PhyLinkHandle, EntryNum;
2574 pBtDbg->dbgHciInfo.hciCmdCntReadLocalAmpAssoc++;
2575 PhyLinkHandle = *((u8 *)pHciCmd->Data);
2576 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2578 if ((EntryNum == 0xff) && PhyLinkHandle != 0) {
2579 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x\n",
2580 EntryNum, PhyLinkHandle));
2581 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2582 } else if (pBtMgnt->bPhyLinkInProgressStartLL) {
2583 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2584 pBtMgnt->bPhyLinkInProgressStartLL = false;
2586 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
2587 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
2588 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen = *((u16 *)((u8 *)pHciCmd->Data+3));
2589 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ReadLocalAMPAssoc, LenSoFar =%d, MaxRemoteASSOCLen =%d\n",
2590 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar,
2591 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen));
2594 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x, LengthSoFar = %x \n",
2595 EntryNum, PhyLinkHandle, pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar));
2597 /* send command complete event here when all data are received. */
2599 struct packet_irp_hcievent_data *PPacketIrpEvent;
2601 /* PVOID buffer = padapter->IrpHCILocalbuf.Ptr; */
2602 u8 localBuf[TmpLocalBufSize] = "";
2605 u16 typeLen = 0, remainLen = 0, ret_index = 0;
2608 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2609 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2610 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2612 totalLen += bthci_CommandCompleteHeader(&localBuf[0],
2613 OGF_STATUS_PARAMETERS,
2614 HCI_READ_LOCAL_AMP_ASSOC,
2616 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2617 /* Return parameters starts from here */
2618 pRetPar = &PPacketIrpEvent->Data[totalLen];
2619 pRetPar[0] = status; /* status */
2620 pRetPar[1] = *((u8 *)pHciCmd->Data);
2621 pRemainLen = (u16 *)&pRetPar[2]; /* AMP_ASSOC_Remaining_Length */
2622 totalLen += 4; /* 0]~[3] */
2625 typeLen = bthci_AssocMACAddr(padapter, &pRetPar[ret_index]);
2626 totalLen += typeLen;
2627 remainLen += typeLen;
2628 ret_index += typeLen;
2629 typeLen = bthci_AssocPreferredChannelList(padapter, &pRetPar[ret_index], EntryNum);
2630 totalLen += typeLen;
2631 remainLen += typeLen;
2632 ret_index += typeLen;
2633 typeLen = bthci_PALCapabilities(padapter, &pRetPar[ret_index]);
2634 totalLen += typeLen;
2635 remainLen += typeLen;
2636 ret_index += typeLen;
2637 typeLen = bthci_AssocPALVer(padapter, &pRetPar[ret_index]);
2638 totalLen += typeLen;
2639 remainLen += typeLen;
2640 PPacketIrpEvent->Length = (u8)totalLen;
2641 *pRemainLen = remainLen; /* AMP_ASSOC_Remaining_Length */
2642 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2643 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("AMP_ASSOC_fragment : \n"), PPacketIrpEvent->Data, totalLen);
2645 bthci_IndicateEvent(padapter, PPacketIrpEvent, totalLen+2);
2651 static enum hci_status bthci_CmdReadFailedContactCounter(struct rtw_adapter *padapter,
2652 struct packet_irp_hcicmd_data *pHciCmd)
2655 enum hci_status status = HCI_STATUS_SUCCESS;
2656 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2657 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2658 u8 localBuf[TmpLocalBufSize] = "";
2661 struct packet_irp_hcievent_data *PPacketIrpEvent;
2664 handle = *((u16 *)pHciCmd->Data);
2665 /* send command complete event here when all data are received. */
2666 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2667 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2669 len += bthci_CommandCompleteHeader(&localBuf[0],
2670 OGF_STATUS_PARAMETERS,
2671 HCI_READ_FAILED_CONTACT_COUNTER,
2674 /* Return parameters starts from here */
2675 pRetPar = &PPacketIrpEvent->Data[len];
2676 pRetPar[0] = status; /* status */
2677 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2678 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2679 pRetPar[3] = TWOBYTE_LOWBYTE(pBtHciInfo->FailContactCount);
2680 pRetPar[4] = TWOBYTE_HIGHTBYTE(pBtHciInfo->FailContactCount);
2682 PPacketIrpEvent->Length = len;
2684 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2689 static enum hci_status
2690 bthci_CmdResetFailedContactCounter(
2691 struct rtw_adapter *padapter,
2692 struct packet_irp_hcicmd_data *pHciCmd
2695 enum hci_status status = HCI_STATUS_SUCCESS;
2696 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2697 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2698 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2700 u8 localBuf[TmpLocalBufSize] = "";
2703 struct packet_irp_hcievent_data *PPacketIrpEvent;
2705 handle = *((u16 *)pHciCmd->Data);
2706 pBtHciInfo->FailContactCount = 0;
2708 /* send command complete event here when all data are received. */
2709 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2710 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2711 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2713 len += bthci_CommandCompleteHeader(&localBuf[0],
2714 OGF_STATUS_PARAMETERS,
2715 HCI_RESET_FAILED_CONTACT_COUNTER,
2718 /* Return parameters starts from here */
2719 pRetPar = &PPacketIrpEvent->Data[len];
2720 pRetPar[0] = status; /* status */
2721 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2722 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2724 PPacketIrpEvent->Length = len;
2726 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2731 /* BT 3.0+HS [Vol 2] 7.4.1 */
2733 static enum hci_status
2734 bthci_CmdReadLocalVersionInformation(
2735 struct rtw_adapter *padapter
2738 enum hci_status status = HCI_STATUS_SUCCESS;
2739 /* send command complete event here when all data are received. */
2740 u8 localBuf[TmpLocalBufSize] = "";
2743 struct packet_irp_hcievent_data *PPacketIrpEvent;
2746 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2747 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2749 len += bthci_CommandCompleteHeader(&localBuf[0],
2750 OGF_INFORMATIONAL_PARAMETERS,
2751 HCI_READ_LOCAL_VERSION_INFORMATION,
2754 /* Return parameters starts from here */
2755 pRetPar = &PPacketIrpEvent->Data[len];
2756 pRetPar[0] = status; /* status */
2757 pRetPar[1] = 0x05; /* HCI_Version */
2758 pu2Temp = (u16 *)&pRetPar[2]; /* HCI_Revision */
2760 pRetPar[4] = 0x05; /* LMP/PAL_Version */
2761 pu2Temp = (u16 *)&pRetPar[5]; /* Manufacturer_Name */
2763 pu2Temp = (u16 *)&pRetPar[7]; /* LMP/PAL_Subversion */
2766 PPacketIrpEvent->Length = len;
2768 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LOCAL_VERSION_INFORMATION\n"));
2769 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Status %x\n", status));
2770 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Version = 0x05\n"));
2771 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Revision = 0x0001\n"));
2772 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Version = 0x05\n"));
2773 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Manufacturer_Name = 0x0001\n"));
2774 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Subversion = 0x0001\n"));
2776 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2782 static enum hci_status bthci_CmdReadDataBlockSize(struct rtw_adapter *padapter)
2784 enum hci_status status = HCI_STATUS_SUCCESS;
2785 u8 localBuf[TmpLocalBufSize] = "";
2788 struct packet_irp_hcievent_data *PPacketIrpEvent;
2791 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2792 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2794 len += bthci_CommandCompleteHeader(&localBuf[0],
2795 OGF_INFORMATIONAL_PARAMETERS,
2796 HCI_READ_DATA_BLOCK_SIZE,
2799 /* Return parameters starts from here */
2800 pRetPar = &PPacketIrpEvent->Data[len];
2801 pRetPar[0] = HCI_STATUS_SUCCESS; /* status */
2802 pu2Temp = (u16 *)&pRetPar[1]; /* Max_ACL_Data_Packet_Length */
2803 *pu2Temp = Max80211PALPDUSize;
2805 pu2Temp = (u16 *)&pRetPar[3]; /* Data_Block_Length */
2806 *pu2Temp = Max80211PALPDUSize;
2807 pu2Temp = (u16 *)&pRetPar[5]; /* Total_Num_Data_Blocks */
2808 *pu2Temp = BTTotalDataBlockNum;
2810 PPacketIrpEvent->Length = len;
2812 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2818 static enum hci_status bthci_CmdReadBufferSize(struct rtw_adapter *padapter)
2820 enum hci_status status = HCI_STATUS_SUCCESS;
2821 u8 localBuf[TmpLocalBufSize] = "";
2824 struct packet_irp_hcievent_data *PPacketIrpEvent;
2827 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2828 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2829 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2831 len += bthci_CommandCompleteHeader(&localBuf[0],
2832 OGF_INFORMATIONAL_PARAMETERS,
2833 HCI_READ_BUFFER_SIZE,
2835 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Synchronous_Data_Packet_Length = 0x%x\n", BTSynDataPacketLength));
2836 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_ACL_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2837 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_Synchronous_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2838 /* Return parameters starts from here */
2839 pRetPar = &PPacketIrpEvent->Data[len];
2840 pRetPar[0] = status; /* status */
2841 pu2Temp = (u16 *)&pRetPar[1]; /* HC_ACL_Data_Packet_Length */
2842 *pu2Temp = Max80211PALPDUSize;
2844 pRetPar[3] = BTSynDataPacketLength; /* HC_Synchronous_Data_Packet_Length */
2845 pu2Temp = (u16 *)&pRetPar[4]; /* HC_Total_Num_ACL_Data_Packets */
2846 *pu2Temp = BTTotalDataBlockNum;
2847 pu2Temp = (u16 *)&pRetPar[6]; /* HC_Total_Num_Synchronous_Data_Packets */
2848 *pu2Temp = BTTotalDataBlockNum;
2850 PPacketIrpEvent->Length = len;
2852 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2857 static enum hci_status bthci_CmdReadLocalAMPInfo(struct rtw_adapter *padapter)
2859 enum hci_status status = HCI_STATUS_SUCCESS;
2860 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
2861 u8 localBuf[TmpLocalBufSize] = "";
2864 struct packet_irp_hcievent_data *PPacketIrpEvent;
2867 u32 TotalBandwidth = BTTOTALBANDWIDTH, MaxBandGUBandwidth = BTMAXBANDGUBANDWIDTH;
2868 u8 ControlType = 0x01, AmpStatus = 0x01;
2869 u32 MaxFlushTimeout = 10000, BestEffortFlushTimeout = 5000;
2870 u16 MaxPDUSize = Max80211PALPDUSize, PalCap = 0x1, AmpAssocLen = Max80211AMPASSOCLen, MinLatency = 20;
2872 if ((ppwrctrl->rfoff_reason & RF_CHANGE_BY_HW) ||
2873 (ppwrctrl->rfoff_reason & RF_CHANGE_BY_SW)) {
2874 AmpStatus = AMP_STATUS_NO_CAPACITY_FOR_BT;
2877 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2878 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2879 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2881 len += bthci_CommandCompleteHeader(&localBuf[0],
2882 OGF_STATUS_PARAMETERS,
2883 HCI_READ_LOCAL_AMP_INFO,
2886 /* Return parameters starts from here */
2887 pRetPar = &PPacketIrpEvent->Data[len];
2888 pRetPar[0] = status; /* status */
2889 pRetPar[1] = AmpStatus; /* AMP_Status */
2890 pu4Temp = (u32 *)&pRetPar[2]; /* Total_Bandwidth */
2891 *pu4Temp = TotalBandwidth; /* 0x19bfcc00;0x7530; */
2892 pu4Temp = (u32 *)&pRetPar[6]; /* Max_Guaranteed_Bandwidth */
2893 *pu4Temp = MaxBandGUBandwidth; /* 0x19bfcc00;0x4e20; */
2894 pu4Temp = (u32 *)&pRetPar[10]; /* Min_Latency */
2895 *pu4Temp = MinLatency; /* 150; */
2896 pu4Temp = (u32 *)&pRetPar[14]; /* Max_PDU_Size */
2897 *pu4Temp = MaxPDUSize;
2898 pRetPar[18] = ControlType; /* Controller_Type */
2899 pu2Temp = (u16 *)&pRetPar[19]; /* PAL_Capabilities */
2901 pu2Temp = (u16 *)&pRetPar[21]; /* AMP_ASSOC_Length */
2902 *pu2Temp = AmpAssocLen;
2903 pu4Temp = (u32 *)&pRetPar[23]; /* Max_Flush_Timeout */
2904 *pu4Temp = MaxFlushTimeout;
2905 pu4Temp = (u32 *)&pRetPar[27]; /* Best_Effort_Flush_Timeout */
2906 *pu4Temp = BestEffortFlushTimeout;
2908 PPacketIrpEvent->Length = len;
2909 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("AmpStatus = 0x%x\n",
2911 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TotalBandwidth = 0x%x, MaxBandGUBandwidth = 0x%x, MinLatency = 0x%x, \n MaxPDUSize = 0x%x, ControlType = 0x%x\n",
2912 TotalBandwidth, MaxBandGUBandwidth, MinLatency, MaxPDUSize, ControlType));
2913 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PalCap = 0x%x, AmpAssocLen = 0x%x, MaxFlushTimeout = 0x%x, BestEffortFlushTimeout = 0x%x\n",
2914 PalCap, AmpAssocLen, MaxFlushTimeout, BestEffortFlushTimeout));
2915 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2919 static enum hci_status
2920 bthci_CmdCreatePhysicalLink(
2921 struct rtw_adapter *padapter,
2922 struct packet_irp_hcicmd_data *pHciCmd
2925 enum hci_status status;
2926 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2927 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2929 pBtDbg->dbgHciInfo.hciCmdCntCreatePhyLink++;
2931 status = bthci_BuildPhysicalLink(padapter,
2932 pHciCmd, HCI_CREATE_PHYSICAL_LINK);
2937 static enum hci_status
2938 bthci_CmdReadLinkQuality(
2939 struct rtw_adapter *padapter,
2940 struct packet_irp_hcicmd_data *pHciCmd
2943 enum hci_status status = HCI_STATUS_SUCCESS;
2944 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2946 u8 EntryNum, LinkQuality = 0x55;
2948 PLH = *((u16 *)&pHciCmd->Data[0]);
2949 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x\n", PLH));
2951 EntryNum = bthci_GetCurrentEntryNum(padapter, (u8)PLH);
2952 if (EntryNum == 0xff) {
2953 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PLH));
2954 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2958 u8 localBuf[11] = "";
2961 struct packet_irp_hcievent_data *PPacketIrpEvent;
2963 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2965 len += bthci_CommandCompleteHeader(&localBuf[0],
2966 OGF_STATUS_PARAMETERS,
2967 HCI_READ_LINK_QUALITY,
2970 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" PLH = 0x%x\n Link Quality = 0x%x\n", PLH, LinkQuality));
2972 /* Return parameters starts from here */
2973 pRetPar = &PPacketIrpEvent->Data[len];
2974 pRetPar[0] = status; /* status */
2975 *((u16 *)&pRetPar[1]) = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle; /* Handle */
2976 pRetPar[3] = 0x55; /* Link Quailty */
2978 PPacketIrpEvent->Length = len;
2980 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2986 static enum hci_status bthci_CmdReadRSSI(struct rtw_adapter *padapter)
2988 enum hci_status status = HCI_STATUS_SUCCESS;
2992 static enum hci_status
2993 bthci_CmdCreateLogicalLink(
2994 struct rtw_adapter *padapter,
2995 struct packet_irp_hcicmd_data *pHciCmd
2998 enum hci_status status = HCI_STATUS_SUCCESS;
2999 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3000 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3002 pBtDbg->dbgHciInfo.hciCmdCntCreateLogLink++;
3004 bthci_BuildLogicalLink(padapter, pHciCmd,
3005 HCI_CREATE_LOGICAL_LINK);
3010 static enum hci_status
3011 bthci_CmdAcceptLogicalLink(
3012 struct rtw_adapter *padapter,
3013 struct packet_irp_hcicmd_data *pHciCmd
3016 enum hci_status status = HCI_STATUS_SUCCESS;
3017 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3018 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3020 pBtDbg->dbgHciInfo.hciCmdCntAcceptLogLink++;
3022 bthci_BuildLogicalLink(padapter, pHciCmd,
3023 HCI_ACCEPT_LOGICAL_LINK);
3028 static enum hci_status
3029 bthci_CmdDisconnectLogicalLink(
3030 struct rtw_adapter *padapter,
3031 struct packet_irp_hcicmd_data *pHciCmd
3034 enum hci_status status = HCI_STATUS_SUCCESS;
3035 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3036 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3037 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3038 struct bt_dgb *pBtDbg = &pBTinfo->BtDbg;
3040 u8 i, j, find = 0, LogLinkCount = 0;
3042 pBtDbg->dbgHciInfo.hciCmdCntDisconnectLogLink++;
3044 logicHandle = *((u16 *)pHciCmd->Data);
3045 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle = 0x%x\n", logicHandle));
3047 /* find an created logical link index and clear the data */
3048 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3049 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3050 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3051 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle is matched 0x%x\n", logicHandle));
3052 bthci_ResetFlowSpec(padapter, j, i);
3054 pBtMgnt->DisconnectEntryNum = j;
3061 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3064 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3065 if (pBTinfo->BtAsocEntry[pBtMgnt->DisconnectEntryNum].LogLinkCmdData[i].BtLogLinkhandle != 0)
3069 /* When we receive Create logical link command, we should send command status event first. */
3070 bthci_EventCommandStatus(padapter,
3071 LINK_CONTROL_COMMANDS,
3072 HCI_DISCONNECT_LOGICAL_LINK,
3075 /* When we determines the logical link is established, we should send command complete event. */
3077 if (status == HCI_STATUS_SUCCESS) {
3078 bthci_EventDisconnectLogicalLinkComplete(padapter, status,
3079 logicHandle, HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST);
3082 if (LogLinkCount == 0)
3083 mod_timer(&pBTinfo->BTDisconnectPhyLinkTimer,
3084 jiffies + msecs_to_jiffies(100));
3089 static enum hci_status
3090 bthci_CmdLogicalLinkCancel(struct rtw_adapter *padapter,
3091 struct packet_irp_hcicmd_data *pHciCmd)
3093 enum hci_status status = HCI_STATUS_SUCCESS;
3094 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3095 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3096 u8 CurrentEntryNum, CurrentLogEntryNum;
3098 u8 physicalLinkHandle, TxFlowSpecID, i;
3099 u16 CurrentLogicalHandle;
3101 physicalLinkHandle = *((u8 *)pHciCmd->Data);
3102 TxFlowSpecID = *(((u8 *)pHciCmd->Data)+1);
3104 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, physicalLinkHandle = 0x%x, TxFlowSpecID = 0x%x\n",
3105 physicalLinkHandle, TxFlowSpecID));
3107 CurrentEntryNum = pBtMgnt->CurrentConnectEntryNum;
3108 CurrentLogicalHandle = pBtMgnt->BtCurrentLogLinkhandle;
3110 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("CurrentEntryNum = 0x%x, CurrentLogicalHandle = 0x%x\n",
3111 CurrentEntryNum, CurrentLogicalHandle));
3113 CurrentLogEntryNum = 0xff;
3114 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3115 if ((CurrentLogicalHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtLogLinkhandle) &&
3116 (physicalLinkHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtPhyLinkhandle)) {
3117 CurrentLogEntryNum = i;
3122 if (CurrentLogEntryNum == 0xff) {
3123 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, CurrentLogEntryNum == 0xff !!!!\n"));
3124 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3127 if (pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCompleteEventIsSet) {
3128 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, LLCompleteEventIsSet!!!!\n"));
3129 status = HCI_STATUS_ACL_CONNECT_EXISTS;
3134 u8 localBuf[8] = "";
3137 struct packet_irp_hcievent_data *PPacketIrpEvent;
3139 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3141 len += bthci_CommandCompleteHeader(&localBuf[0],
3142 LINK_CONTROL_COMMANDS,
3143 HCI_LOGICAL_LINK_CANCEL,
3146 /* Return parameters starts from here */
3147 pRetPar = &PPacketIrpEvent->Data[len];
3148 pRetPar[0] = status; /* status */
3149 pRetPar[1] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtPhyLinkhandle;
3150 pRetPar[2] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtTxFlowSpecID;
3152 PPacketIrpEvent->Length = len;
3154 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3157 pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCancelCMDIsSetandComplete = true;
3162 static enum hci_status
3163 bthci_CmdFlowSpecModify(struct rtw_adapter *padapter,
3164 struct packet_irp_hcicmd_data *pHciCmd)
3166 enum hci_status status = HCI_STATUS_SUCCESS;
3167 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3168 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3172 logicHandle = *((u16 *)pHciCmd->Data);
3173 /* find an matched logical link index and copy the data */
3174 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3175 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3176 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3177 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec,
3178 &pHciCmd->Data[2], sizeof(struct hci_flow_spec));
3179 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Rx_Flow_Spec,
3180 &pHciCmd->Data[18], sizeof(struct hci_flow_spec));
3182 bthci_CheckLogLinkBehavior(padapter, pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec);
3188 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("FlowSpecModify, LLH = 0x%x, \n", logicHandle));
3190 /* When we receive Flow Spec Modify command, we should send command status event first. */
3191 bthci_EventCommandStatus(padapter,
3192 LINK_CONTROL_COMMANDS,
3193 HCI_FLOW_SPEC_MODIFY,
3194 HCI_STATUS_SUCCESS);
3197 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3199 bthci_EventSendFlowSpecModifyComplete(padapter, status, logicHandle);
3204 static enum hci_status
3205 bthci_CmdAcceptPhysicalLink(struct rtw_adapter *padapter,
3206 struct packet_irp_hcicmd_data *pHciCmd)
3208 enum hci_status status;
3209 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3210 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3212 pBtDbg->dbgHciInfo.hciCmdCntAcceptPhyLink++;
3214 status = bthci_BuildPhysicalLink(padapter,
3215 pHciCmd, HCI_ACCEPT_PHYSICAL_LINK);
3220 static enum hci_status
3221 bthci_CmdDisconnectPhysicalLink(struct rtw_adapter *padapter,
3222 struct packet_irp_hcicmd_data *pHciCmd)
3224 enum hci_status status = HCI_STATUS_SUCCESS;
3225 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3226 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3227 u8 PLH, CurrentEntryNum, PhysLinkDisconnectReason;
3229 pBtDbg->dbgHciInfo.hciCmdCntDisconnectPhyLink++;
3231 PLH = *((u8 *)pHciCmd->Data);
3232 PhysLinkDisconnectReason = (*((u8 *)pHciCmd->Data+1));
3233 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK PhyHandle = 0x%x, Reason = 0x%x\n",
3234 PLH, PhysLinkDisconnectReason));
3236 CurrentEntryNum = bthci_GetCurrentEntryNum(padapter, PLH);
3238 if (CurrentEntryNum == 0xff) {
3239 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
3240 ("DisconnectPhysicalLink, No such Handle in the Entry\n"));
3241 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3243 pBTInfo->BtAsocEntry[CurrentEntryNum].PhyLinkDisconnectReason =
3244 (enum hci_status)PhysLinkDisconnectReason;
3246 /* Send HCI Command status event to AMP. */
3247 bthci_EventCommandStatus(padapter, LINK_CONTROL_COMMANDS,
3248 HCI_DISCONNECT_PHYSICAL_LINK, status);
3250 if (status != HCI_STATUS_SUCCESS)
3253 /* The macros below require { and } in the if statement */
3254 if (pBTInfo->BtAsocEntry[CurrentEntryNum].BtCurrentState == HCI_STATE_DISCONNECTED) {
3255 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3257 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3262 static enum hci_status
3263 bthci_CmdSetACLLinkDataFlowMode(struct rtw_adapter *padapter,
3264 struct packet_irp_hcicmd_data *pHciCmd)
3266 enum hci_status status = HCI_STATUS_SUCCESS;
3267 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3268 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3269 u8 localBuf[8] = "";
3272 struct packet_irp_hcievent_data *PPacketIrpEvent;
3275 pBtMgnt->ExtConfig.CurrentConnectHandle = *((u16 *)pHciCmd->Data);
3276 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = *((u8 *)pHciCmd->Data)+2;
3277 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = *((u8 *)pHciCmd->Data)+3;
3278 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Connection Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic mode = 0x%x",
3279 pBtMgnt->ExtConfig.CurrentConnectHandle,
3280 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode,
3281 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode));
3284 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3286 len += bthci_CommandCompleteHeader(&localBuf[0],
3288 HCI_SET_ACL_LINK_DATA_FLOW_MODE,
3291 /* Return parameters starts from here */
3292 pRetPar = &PPacketIrpEvent->Data[len];
3293 pRetPar[0] = status; /* status */
3295 pu2Temp = (u16 *)&pRetPar[1];
3296 *pu2Temp = pBtMgnt->ExtConfig.CurrentConnectHandle;
3298 PPacketIrpEvent->Length = len;
3300 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3304 static enum hci_status
3305 bthci_CmdSetACLLinkStatus(struct rtw_adapter *padapter,
3306 struct packet_irp_hcicmd_data *pHciCmd)
3308 enum hci_status status = HCI_STATUS_SUCCESS;
3309 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3310 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3311 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3315 pBtDbg->dbgHciInfo.hciCmdCntSetAclLinkStatus++;
3316 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "SetACLLinkStatus, Hex Data :\n",
3317 &pHciCmd->Data[0], pHciCmd->Length);
3319 /* Only Core Stack v251 and later version support this command. */
3320 pBtMgnt->bSupportProfile = true;
3322 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3323 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3325 pTriple = &pHciCmd->Data[1];
3326 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3327 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3328 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = pTriple[2];
3329 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = pTriple[3];
3330 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3331 ("Connection_Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic Mode = 0x%x\n",
3332 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3333 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode,
3334 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode));
3339 u8 localBuf[6] = "";
3342 struct packet_irp_hcievent_data *PPacketIrpEvent;
3344 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3346 len += bthci_CommandCompleteHeader(&localBuf[0],
3348 HCI_SET_ACL_LINK_STATUS,
3351 /* Return parameters starts from here */
3352 pRetPar = &PPacketIrpEvent->Data[len];
3353 pRetPar[0] = status; /* status */
3356 PPacketIrpEvent->Length = len;
3358 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3364 static enum hci_status
3365 bthci_CmdSetSCOLinkStatus(
3366 struct rtw_adapter *padapter,
3367 struct packet_irp_hcicmd_data *pHciCmd
3370 enum hci_status status = HCI_STATUS_SUCCESS;
3371 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3372 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3373 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3375 pBtDbg->dbgHciInfo.hciCmdCntSetScoLinkStatus++;
3376 pBtMgnt->ExtConfig.NumberOfSCO = *((u8 *)pHciCmd->Data);
3377 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfSCO = 0x%x\n",
3378 pBtMgnt->ExtConfig.NumberOfSCO));
3381 u8 localBuf[6] = "";
3384 struct packet_irp_hcievent_data *PPacketIrpEvent;
3386 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3388 len += bthci_CommandCompleteHeader(&localBuf[0],
3390 HCI_SET_SCO_LINK_STATUS,
3393 /* Return parameters starts from here */
3394 pRetPar = &PPacketIrpEvent->Data[len];
3395 pRetPar[0] = status; /* status */
3398 PPacketIrpEvent->Length = len;
3400 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3406 static enum hci_status
3407 bthci_CmdSetRSSIValue(
3408 struct rtw_adapter *padapter,
3409 struct packet_irp_hcicmd_data *pHciCmd
3412 enum hci_status status = HCI_STATUS_SUCCESS;
3413 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3414 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3417 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3418 if (pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle == *((u16 *)&pHciCmd->Data[0])) {
3419 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = (s8)(pHciCmd->Data[2]);
3420 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL,
3421 ("Connection_Handle = 0x%x, RSSI = %d \n",
3422 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3423 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI));
3425 /* get the minimum bt rssi value */
3426 if (pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI <= min_bt_rssi)
3427 min_bt_rssi = pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI;
3430 pBtMgnt->ExtConfig.MIN_BT_RSSI = min_bt_rssi;
3431 RTPRINT(FBT, BT_TRACE, ("[bt rssi], the min rssi is %d\n", min_bt_rssi));
3434 u8 localBuf[6] = "";
3437 struct packet_irp_hcievent_data *PPacketIrpEvent;
3439 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3441 len += bthci_CommandCompleteHeader(&localBuf[0],
3446 /* Return parameters starts from here */
3447 pRetPar = &PPacketIrpEvent->Data[len];
3448 pRetPar[0] = status; /* status */
3451 PPacketIrpEvent->Length = len;
3453 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3459 static enum hci_status
3460 bthci_CmdSetCurrentBluetoothStatus(
3461 struct rtw_adapter *padapter,
3462 struct packet_irp_hcicmd_data *pHciCmd
3465 enum hci_status status = HCI_STATUS_SUCCESS;
3466 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3467 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3468 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3470 pBtMgnt->ExtConfig.CurrentBTStatus = *((u8 *)&pHciCmd->Data[0]);
3471 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("SetCurrentBluetoothStatus, CurrentBTStatus = 0x%x\n",
3472 pBtMgnt->ExtConfig.CurrentBTStatus));
3475 u8 localBuf[6] = "";
3478 struct packet_irp_hcievent_data *PPacketIrpEvent;
3480 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3482 len += bthci_CommandCompleteHeader(&localBuf[0],
3484 HCI_SET_CURRENT_BLUETOOTH_STATUS,
3487 /* Return parameters starts from here */
3488 pRetPar = &PPacketIrpEvent->Data[len];
3489 pRetPar[0] = status; /* status */
3492 PPacketIrpEvent->Length = len;
3494 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3500 static enum hci_status
3501 bthci_CmdExtensionVersionNotify(
3502 struct rtw_adapter *padapter,
3503 struct packet_irp_hcicmd_data *pHciCmd
3506 enum hci_status status = HCI_STATUS_SUCCESS;
3507 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3508 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3509 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3511 pBtDbg->dbgHciInfo.hciCmdCntExtensionVersionNotify++;
3512 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "ExtensionVersionNotify, Hex Data :\n",
3513 &pHciCmd->Data[0], pHciCmd->Length);
3515 pBtMgnt->ExtConfig.HCIExtensionVer = *((u16 *)&pHciCmd->Data[0]);
3516 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = 0x%x\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3519 u8 localBuf[6] = "";
3522 struct packet_irp_hcievent_data *PPacketIrpEvent;
3524 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3526 len += bthci_CommandCompleteHeader(&localBuf[0],
3528 HCI_EXTENSION_VERSION_NOTIFY,
3531 /* Return parameters starts from here */
3532 pRetPar = &PPacketIrpEvent->Data[len];
3533 pRetPar[0] = status; /* status */
3536 PPacketIrpEvent->Length = len;
3538 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3544 static enum hci_status
3545 bthci_CmdLinkStatusNotify(
3546 struct rtw_adapter *padapter,
3547 struct packet_irp_hcicmd_data *pHciCmd
3550 enum hci_status status = HCI_STATUS_SUCCESS;
3551 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3552 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3553 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3557 pBtDbg->dbgHciInfo.hciCmdCntLinkStatusNotify++;
3558 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "LinkStatusNotify, Hex Data :\n",
3559 &pHciCmd->Data[0], pHciCmd->Length);
3561 /* Current only RTL8723 support this command. */
3562 pBtMgnt->bSupportProfile = true;
3564 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3565 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3566 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = %d\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3568 pTriple = &pHciCmd->Data[1];
3569 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3570 if (pBtMgnt->ExtConfig.HCIExtensionVer < 1) {
3571 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3572 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3573 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3574 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3575 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d\n",
3576 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3577 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3578 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec));
3580 } else if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
3581 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3582 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3583 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3584 pBtMgnt->ExtConfig.linkInfo[i].linkRole = pTriple[4];
3585 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3586 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d, LinkRole =%d\n",
3587 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3588 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3589 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec,
3590 pBtMgnt->ExtConfig.linkInfo[i].linkRole));
3595 BTHCI_UpdateBTProfileRTKToMoto(padapter);
3597 u8 localBuf[6] = "";
3600 struct packet_irp_hcievent_data *PPacketIrpEvent;
3602 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3604 len += bthci_CommandCompleteHeader(&localBuf[0],
3606 HCI_LINK_STATUS_NOTIFY,
3609 /* Return parameters starts from here */
3610 pRetPar = &PPacketIrpEvent->Data[len];
3611 pRetPar[0] = status; /* status */
3614 PPacketIrpEvent->Length = len;
3616 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3622 static enum hci_status
3623 bthci_CmdBtOperationNotify(
3624 struct rtw_adapter *padapter,
3625 struct packet_irp_hcicmd_data *pHciCmd
3628 enum hci_status status = HCI_STATUS_SUCCESS;
3629 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3630 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3632 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Bt Operation notify, Hex Data :\n",
3633 &pHciCmd->Data[0], pHciCmd->Length);
3635 pBtMgnt->ExtConfig.btOperationCode = *((u8 *)pHciCmd->Data);
3636 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("btOperationCode = 0x%x\n", pBtMgnt->ExtConfig.btOperationCode));
3637 switch (pBtMgnt->ExtConfig.btOperationCode) {
3638 case HCI_BT_OP_NONE:
3639 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Operation None!!\n"));
3641 case HCI_BT_OP_INQUIRY_START:
3642 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire start!!\n"));
3644 case HCI_BT_OP_INQUIRY_FINISH:
3645 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire finished!!\n"));
3647 case HCI_BT_OP_PAGING_START:
3648 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging is started!!\n"));
3650 case HCI_BT_OP_PAGING_SUCCESS:
3651 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete successfully!!\n"));
3653 case HCI_BT_OP_PAGING_UNSUCCESS:
3654 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete unsuccessfully!!\n"));
3656 case HCI_BT_OP_PAIRING_START:
3657 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing start!!\n"));
3659 case HCI_BT_OP_PAIRING_FINISH:
3660 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing finished!!\n"));
3662 case HCI_BT_OP_BT_DEV_ENABLE:
3663 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is enabled!!\n"));
3665 case HCI_BT_OP_BT_DEV_DISABLE:
3666 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is disabled!!\n"));
3669 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Unknown, error!!\n"));
3672 BTDM_AdjustForBtOperation(padapter);
3674 u8 localBuf[6] = "";
3677 struct packet_irp_hcievent_data *PPacketIrpEvent;
3679 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3681 len += bthci_CommandCompleteHeader(&localBuf[0],
3683 HCI_BT_OPERATION_NOTIFY,
3686 /* Return parameters starts from here */
3687 pRetPar = &PPacketIrpEvent->Data[len];
3688 pRetPar[0] = status; /* status */
3691 PPacketIrpEvent->Length = len;
3693 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3699 static enum hci_status
3700 bthci_CmdEnableWifiScanNotify(struct rtw_adapter *padapter,
3701 struct packet_irp_hcicmd_data *pHciCmd)
3703 enum hci_status status = HCI_STATUS_SUCCESS;
3704 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3705 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3707 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Enable Wifi scan notify, Hex Data :\n",
3708 &pHciCmd->Data[0], pHciCmd->Length);
3710 pBtMgnt->ExtConfig.bEnableWifiScanNotify = *((u8 *)pHciCmd->Data);
3711 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("bEnableWifiScanNotify = %d\n", pBtMgnt->ExtConfig.bEnableWifiScanNotify));
3714 u8 localBuf[6] = "";
3717 struct packet_irp_hcievent_data *PPacketIrpEvent;
3719 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3721 len += bthci_CommandCompleteHeader(&localBuf[0],
3723 HCI_ENABLE_WIFI_SCAN_NOTIFY,
3726 /* Return parameters starts from here */
3727 pRetPar = &PPacketIrpEvent->Data[len];
3728 pRetPar[0] = status; /* status */
3731 PPacketIrpEvent->Length = len;
3733 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3739 static enum hci_status
3740 bthci_CmdWIFICurrentChannel(struct rtw_adapter *padapter,
3741 struct packet_irp_hcicmd_data *pHciCmd)
3743 enum hci_status status = HCI_STATUS_SUCCESS;
3744 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3745 u8 chnl = pmlmeext->cur_channel;
3747 if (pmlmeext->cur_bwmode == HT_CHANNEL_WIDTH_40) {
3748 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
3750 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
3754 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current Channel = 0x%x\n", chnl));
3757 u8 localBuf[8] = "";
3760 struct packet_irp_hcievent_data *PPacketIrpEvent;
3762 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3764 len += bthci_CommandCompleteHeader(&localBuf[0],
3766 HCI_WIFI_CURRENT_CHANNEL,
3769 /* Return parameters starts from here */
3770 pRetPar = &PPacketIrpEvent->Data[len];
3771 pRetPar[0] = status; /* status */
3772 pRetPar[1] = chnl; /* current channel */
3774 PPacketIrpEvent->Length = len;
3776 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3782 static enum hci_status
3783 bthci_CmdWIFICurrentBandwidth(struct rtw_adapter *padapter,
3784 struct packet_irp_hcicmd_data *pHciCmd)
3786 enum hci_status status = HCI_STATUS_SUCCESS;
3787 enum ht_channel_width bw;
3790 bw = padapter->mlmeextpriv.cur_bwmode;
3792 if (bw == HT_CHANNEL_WIDTH_20)
3794 else if (bw == HT_CHANNEL_WIDTH_40)
3797 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current BW = 0x%x\n",
3801 u8 localBuf[8] = "";
3804 struct packet_irp_hcievent_data *PPacketIrpEvent;
3806 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3808 len += bthci_CommandCompleteHeader(&localBuf[0],
3810 HCI_WIFI_CURRENT_BANDWIDTH,
3813 /* Return parameters starts from here */
3814 pRetPar = &PPacketIrpEvent->Data[len];
3815 pRetPar[0] = status; /* status */
3816 pRetPar[1] = CurrentBW; /* current BW */
3818 PPacketIrpEvent->Length = len;
3820 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3826 static enum hci_status
3827 bthci_CmdWIFIConnectionStatus(
3828 struct rtw_adapter *padapter,
3829 struct packet_irp_hcicmd_data *pHciCmd
3832 enum hci_status status = HCI_STATUS_SUCCESS;
3833 u8 connectStatus = HCI_WIFI_NOT_CONNECTED;
3835 if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) {
3836 if (padapter->stapriv.asoc_sta_count >= 3)
3837 connectStatus = HCI_WIFI_CONNECTED;
3839 connectStatus = HCI_WIFI_NOT_CONNECTED;
3840 } else if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE|WIFI_ASOC_STATE)) {
3841 connectStatus = HCI_WIFI_CONNECTED;
3842 } else if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING)) {
3843 connectStatus = HCI_WIFI_CONNECT_IN_PROGRESS;
3845 connectStatus = HCI_WIFI_NOT_CONNECTED;
3849 u8 localBuf[8] = "";
3852 struct packet_irp_hcievent_data *PPacketIrpEvent;
3854 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3856 len += bthci_CommandCompleteHeader(&localBuf[0],
3858 HCI_WIFI_CONNECTION_STATUS,
3861 /* Return parameters starts from here */
3862 pRetPar = &PPacketIrpEvent->Data[len];
3863 pRetPar[0] = status; /* status */
3864 pRetPar[1] = connectStatus; /* connect status */
3866 PPacketIrpEvent->Length = len;
3868 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3874 static enum hci_status
3875 bthci_CmdEnableDeviceUnderTestMode(
3876 struct rtw_adapter *padapter,
3877 struct packet_irp_hcicmd_data *pHciCmd
3880 enum hci_status status = HCI_STATUS_SUCCESS;
3881 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3882 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3884 pBtHciInfo->bInTestMode = true;
3885 pBtHciInfo->bTestIsEnd = false;
3887 /* send command complete event here when all data are received. */
3889 u8 localBuf[6] = "";
3892 struct packet_irp_hcievent_data *PPacketIrpEvent;
3894 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3896 len += bthci_CommandCompleteHeader(&localBuf[0],
3897 OGF_TESTING_COMMANDS,
3898 HCI_ENABLE_DEVICE_UNDER_TEST_MODE,
3901 /* Return parameters starts from here */
3902 pRetPar = &PPacketIrpEvent->Data[len];
3903 pRetPar[0] = status; /* status */
3905 PPacketIrpEvent->Length = len;
3907 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3913 static enum hci_status
3914 bthci_CmdAMPTestEnd(struct rtw_adapter *padapter,
3915 struct packet_irp_hcicmd_data *pHciCmd)
3917 enum hci_status status = HCI_STATUS_SUCCESS;
3918 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3919 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3921 if (!pBtHciInfo->bInTestMode) {
3922 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3923 status = HCI_STATUS_CMD_DISALLOW;
3927 pBtHciInfo->bTestIsEnd = true;
3929 del_timer_sync(&pBTInfo->BTTestSendPacketTimer);
3931 rtl8723a_check_bssid(padapter, true);
3933 /* send command complete event here when all data are received. */
3935 u8 localBuf[4] = "";
3936 struct packet_irp_hcievent_data *PPacketIrpEvent;
3938 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3939 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3940 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3941 PPacketIrpEvent->Length = 2;
3943 PPacketIrpEvent->Data[0] = status;
3944 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario;
3946 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3949 bthci_EventAMPReceiverReport(padapter, 0x01);
3954 static enum hci_status
3955 bthci_CmdAMPTestCommand(struct rtw_adapter *padapter,
3956 struct packet_irp_hcicmd_data *pHciCmd)
3958 enum hci_status status = HCI_STATUS_SUCCESS;
3959 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3960 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3962 if (!pBtHciInfo->bInTestMode) {
3963 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3964 status = HCI_STATUS_CMD_DISALLOW;
3968 pBtHciInfo->TestScenario = *((u8 *)pHciCmd->Data);
3970 if (pBtHciInfo->TestScenario == 0x01)
3971 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
3972 else if (pBtHciInfo->TestScenario == 0x02)
3973 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
3975 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("No Such Test !!!!!!!!!!!!!!!!!! \n"));
3977 if (pBtHciInfo->bTestIsEnd) {
3978 u8 localBuf[5] = "";
3979 struct packet_irp_hcievent_data *PPacketIrpEvent;
3981 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3982 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3983 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3984 PPacketIrpEvent->Length = 2;
3986 PPacketIrpEvent->Data[0] = status;
3987 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
3989 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3991 /* Return to Idel state with RX and TX off. */
3996 /* should send command status event */
3997 bthci_EventCommandStatus(padapter,
3998 OGF_TESTING_COMMANDS,
3999 HCI_AMP_TEST_COMMAND,
4002 /* The HCI_AMP_Start Test Event shall be generated when the */
4003 /* HCI_AMP_Test_Command has completed and the first data is ready to be sent */
4007 u8 localBuf[5] = "";
4008 struct packet_irp_hcievent_data *PPacketIrpEvent;
4010 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_AMP_Start Test Event \n"));
4011 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4012 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_START_TEST;
4013 PPacketIrpEvent->Length = 2;
4015 PPacketIrpEvent->Data[0] = status;
4016 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
4018 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
4020 /* Return to Idel state with RX and TX off. */
4023 if (pBtHciInfo->TestScenario == 0x01) {
4025 When in a transmitter test scenario and the frames/bursts count have been
4026 transmitted the HCI_AMP_Test_End event shall be sent.
4028 mod_timer(&pBTInfo->BTTestSendPacketTimer,
4029 jiffies + msecs_to_jiffies(50));
4030 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
4031 } else if (pBtHciInfo->TestScenario == 0x02) {
4032 rtl8723a_check_bssid(padapter, false);
4033 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
4039 static enum hci_status
4040 bthci_CmdEnableAMPReceiverReports(struct rtw_adapter *padapter,
4041 struct packet_irp_hcicmd_data *pHciCmd)
4043 enum hci_status status = HCI_STATUS_SUCCESS;
4044 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4045 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4047 if (!pBtHciInfo->bInTestMode) {
4048 status = HCI_STATUS_CMD_DISALLOW;
4049 /* send command complete event here when all data are received. */
4051 u8 localBuf[6] = "";
4054 struct packet_irp_hcievent_data *PPacketIrpEvent;
4056 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4058 len += bthci_CommandCompleteHeader(&localBuf[0],
4059 OGF_TESTING_COMMANDS,
4060 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4063 /* Return parameters starts from here */
4064 pRetPar = &PPacketIrpEvent->Data[len];
4065 pRetPar[0] = status; /* status */
4067 PPacketIrpEvent->Length = len;
4069 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4074 pBtHciInfo->bTestNeedReport = *((u8 *)pHciCmd->Data);
4075 pBtHciInfo->TestReportInterval = (*((u8 *)pHciCmd->Data+2));
4077 bthci_EventAMPReceiverReport(padapter, 0x00);
4079 /* send command complete event here when all data are received. */
4081 u8 localBuf[6] = "";
4084 struct packet_irp_hcievent_data *PPacketIrpEvent;
4086 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4088 len += bthci_CommandCompleteHeader(&localBuf[0],
4089 OGF_TESTING_COMMANDS,
4090 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4093 /* Return parameters starts from here */
4094 pRetPar = &PPacketIrpEvent->Data[len];
4095 pRetPar[0] = status; /* status */
4097 PPacketIrpEvent->Length = len;
4099 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4105 static enum hci_status
4106 bthci_CmdHostBufferSize(struct rtw_adapter *padapter,
4107 struct packet_irp_hcicmd_data *pHciCmd)
4109 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4110 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4111 struct packet_irp_hcievent_data *PPacketIrpEvent;
4112 enum hci_status status = HCI_STATUS_SUCCESS;
4113 u8 localBuf[6] = "";
4117 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].ACLPacketsData.ACLDataPacketLen = *((u16 *)pHciCmd->Data);
4118 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].SyncDataPacketLen = *((u8 *)(pHciCmd->Data+2));
4119 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalNumACLDataPackets = *((u16 *)(pHciCmd->Data+3));
4120 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalSyncNumDataPackets = *((u16 *)(pHciCmd->Data+5));
4122 /* send command complete event here when all data are received. */
4123 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4125 len += bthci_CommandCompleteHeader(&localBuf[0],
4126 OGF_SET_EVENT_MASK_COMMAND,
4127 HCI_HOST_BUFFER_SIZE,
4130 /* Return parameters starts from here */
4131 pRetPar = &PPacketIrpEvent->Data[len];
4132 pRetPar[0] = status; /* status */
4134 PPacketIrpEvent->Length = len;
4136 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4141 static enum hci_status
4142 bthci_CmdHostNumberOfCompletedPackets(struct rtw_adapter *padapter,
4143 struct packet_irp_hcicmd_data *pHciCmd)
4145 enum hci_status status = HCI_STATUS_SUCCESS;
4150 static enum hci_status
4151 bthci_UnknownCMD(struct rtw_adapter *padapter, struct packet_irp_hcicmd_data *pHciCmd)
4153 enum hci_status status = HCI_STATUS_UNKNOW_HCI_CMD;
4154 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4155 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
4157 pBtDbg->dbgHciInfo.hciCmdCntUnknown++;
4158 bthci_EventCommandStatus(padapter,
4166 static enum hci_status
4167 bthci_HandleOGFInformationalParameters(struct rtw_adapter *padapter,
4168 struct packet_irp_hcicmd_data *pHciCmd)
4170 enum hci_status status = HCI_STATUS_SUCCESS;
4172 switch (pHciCmd->OCF) {
4173 case HCI_READ_LOCAL_VERSION_INFORMATION:
4174 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_VERSION_INFORMATION\n"));
4175 status = bthci_CmdReadLocalVersionInformation(padapter);
4177 case HCI_READ_LOCAL_SUPPORTED_COMMANDS:
4178 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_COMMANDS\n"));
4179 status = bthci_CmdReadLocalSupportedCommands(padapter);
4181 case HCI_READ_LOCAL_SUPPORTED_FEATURES:
4182 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_FEATURES\n"));
4183 status = bthci_CmdReadLocalSupportedFeatures(padapter);
4185 case HCI_READ_BUFFER_SIZE:
4186 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BUFFER_SIZE\n"));
4187 status = bthci_CmdReadBufferSize(padapter);
4189 case HCI_READ_DATA_BLOCK_SIZE:
4190 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_DATA_BLOCK_SIZE\n"));
4191 status = bthci_CmdReadDataBlockSize(padapter);
4194 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFInformationalParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4195 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4196 status = bthci_UnknownCMD(padapter, pHciCmd);
4202 static enum hci_status
4203 bthci_HandleOGFSetEventMaskCMD(struct rtw_adapter *padapter,
4204 struct packet_irp_hcicmd_data *pHciCmd)
4206 enum hci_status status = HCI_STATUS_SUCCESS;
4208 switch (pHciCmd->OCF) {
4209 case HCI_SET_EVENT_MASK:
4210 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK\n"));
4211 status = bthci_CmdSetEventMask(padapter, pHciCmd);
4214 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET\n"));
4215 status = bthci_CmdReset(padapter, true);
4217 case HCI_READ_CONNECTION_ACCEPT_TIMEOUT:
4218 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_CONNECTION_ACCEPT_TIMEOUT\n"));
4219 status = bthci_CmdReadConnectionAcceptTimeout(padapter);
4221 case HCI_SET_EVENT_FILTER:
4222 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_FILTER\n"));
4223 status = bthci_CmdSetEventFilter(padapter, pHciCmd);
4225 case HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT:
4226 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT\n"));
4227 status = bthci_CmdWriteConnectionAcceptTimeout(padapter, pHciCmd);
4229 case HCI_READ_PAGE_TIMEOUT:
4230 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_PAGE_TIMEOUT\n"));
4231 status = bthci_CmdReadPageTimeout(padapter, pHciCmd);
4233 case HCI_WRITE_PAGE_TIMEOUT:
4234 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_PAGE_TIMEOUT\n"));
4235 status = bthci_CmdWritePageTimeout(padapter, pHciCmd);
4237 case HCI_HOST_NUMBER_OF_COMPLETED_PACKETS:
4238 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_NUMBER_OF_COMPLETED_PACKETS\n"));
4239 status = bthci_CmdHostNumberOfCompletedPackets(padapter, pHciCmd);
4241 case HCI_READ_LINK_SUPERVISION_TIMEOUT:
4242 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_SUPERVISION_TIMEOUT\n"));
4243 status = bthci_CmdReadLinkSupervisionTimeout(padapter, pHciCmd);
4245 case HCI_WRITE_LINK_SUPERVISION_TIMEOUT:
4246 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LINK_SUPERVISION_TIMEOUT\n"));
4247 status = bthci_CmdWriteLinkSupervisionTimeout(padapter, pHciCmd);
4249 case HCI_ENHANCED_FLUSH:
4250 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENHANCED_FLUSH\n"));
4251 status = bthci_CmdEnhancedFlush(padapter, pHciCmd);
4253 case HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT:
4254 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4255 status = bthci_CmdReadLogicalLinkAcceptTimeout(padapter, pHciCmd);
4257 case HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT:
4258 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4259 status = bthci_CmdWriteLogicalLinkAcceptTimeout(padapter, pHciCmd);
4261 case HCI_SET_EVENT_MASK_PAGE_2:
4262 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK_PAGE_2\n"));
4263 status = bthci_CmdSetEventMaskPage2(padapter, pHciCmd);
4265 case HCI_READ_LOCATION_DATA:
4266 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCATION_DATA\n"));
4267 status = bthci_CmdReadLocationData(padapter, pHciCmd);
4269 case HCI_WRITE_LOCATION_DATA:
4270 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOCATION_DATA\n"));
4271 status = bthci_CmdWriteLocationData(padapter, pHciCmd);
4273 case HCI_READ_FLOW_CONTROL_MODE:
4274 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FLOW_CONTROL_MODE\n"));
4275 status = bthci_CmdReadFlowControlMode(padapter, pHciCmd);
4277 case HCI_WRITE_FLOW_CONTROL_MODE:
4278 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_FLOW_CONTROL_MODE\n"));
4279 status = bthci_CmdWriteFlowControlMode(padapter, pHciCmd);
4281 case HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT:
4282 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4283 status = bthci_CmdReadBestEffortFlushTimeout(padapter, pHciCmd);
4285 case HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT:
4286 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4287 status = bthci_CmdWriteBestEffortFlushTimeout(padapter, pHciCmd);
4289 case HCI_SHORT_RANGE_MODE:
4290 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SHORT_RANGE_MODE\n"));
4291 status = bthci_CmdShortRangeMode(padapter, pHciCmd);
4293 case HCI_HOST_BUFFER_SIZE:
4294 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_BUFFER_SIZE\n"));
4295 status = bthci_CmdHostBufferSize(padapter, pHciCmd);
4298 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFSetEventMaskCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4299 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4300 status = bthci_UnknownCMD(padapter, pHciCmd);
4306 static enum hci_status
4307 bthci_HandleOGFStatusParameters(struct rtw_adapter *padapter,
4308 struct packet_irp_hcicmd_data *pHciCmd)
4310 enum hci_status status = HCI_STATUS_SUCCESS;
4312 switch (pHciCmd->OCF) {
4313 case HCI_READ_FAILED_CONTACT_COUNTER:
4314 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FAILED_CONTACT_COUNTER\n"));
4315 status = bthci_CmdReadFailedContactCounter(padapter, pHciCmd);
4317 case HCI_RESET_FAILED_CONTACT_COUNTER:
4318 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET_FAILED_CONTACT_COUNTER\n"));
4319 status = bthci_CmdResetFailedContactCounter(padapter, pHciCmd);
4321 case HCI_READ_LINK_QUALITY:
4322 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_QUALITY\n"));
4323 status = bthci_CmdReadLinkQuality(padapter, pHciCmd);
4326 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_RSSI\n"));
4327 status = bthci_CmdReadRSSI(padapter);
4329 case HCI_READ_LOCAL_AMP_INFO:
4330 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_INFO\n"));
4331 status = bthci_CmdReadLocalAMPInfo(padapter);
4333 case HCI_READ_LOCAL_AMP_ASSOC:
4334 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_ASSOC\n"));
4335 status = bthci_CmdReadLocalAMPAssoc(padapter, pHciCmd);
4337 case HCI_WRITE_REMOTE_AMP_ASSOC:
4338 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_REMOTE_AMP_ASSOC\n"));
4339 status = bthci_CmdWriteRemoteAMPAssoc(padapter, pHciCmd);
4342 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFStatusParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4343 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4344 status = bthci_UnknownCMD(padapter, pHciCmd);
4350 static enum hci_status
4351 bthci_HandleOGFLinkControlCMD(struct rtw_adapter *padapter,
4352 struct packet_irp_hcicmd_data *pHciCmd)
4354 enum hci_status status = HCI_STATUS_SUCCESS;
4356 switch (pHciCmd->OCF) {
4357 case HCI_CREATE_PHYSICAL_LINK:
4358 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_PHYSICAL_LINK\n"));
4359 status = bthci_CmdCreatePhysicalLink(padapter, pHciCmd);
4361 case HCI_ACCEPT_PHYSICAL_LINK:
4362 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_PHYSICAL_LINK\n"));
4363 status = bthci_CmdAcceptPhysicalLink(padapter, pHciCmd);
4365 case HCI_DISCONNECT_PHYSICAL_LINK:
4366 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK\n"));
4367 status = bthci_CmdDisconnectPhysicalLink(padapter, pHciCmd);
4369 case HCI_CREATE_LOGICAL_LINK:
4370 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_LOGICAL_LINK\n"));
4371 status = bthci_CmdCreateLogicalLink(padapter, pHciCmd);
4373 case HCI_ACCEPT_LOGICAL_LINK:
4374 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_LOGICAL_LINK\n"));
4375 status = bthci_CmdAcceptLogicalLink(padapter, pHciCmd);
4377 case HCI_DISCONNECT_LOGICAL_LINK:
4378 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_LOGICAL_LINK\n"));
4379 status = bthci_CmdDisconnectLogicalLink(padapter, pHciCmd);
4381 case HCI_LOGICAL_LINK_CANCEL:
4382 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_LOGICAL_LINK_CANCEL\n"));
4383 status = bthci_CmdLogicalLinkCancel(padapter, pHciCmd);
4385 case HCI_FLOW_SPEC_MODIFY:
4386 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_FLOW_SPEC_MODIFY\n"));
4387 status = bthci_CmdFlowSpecModify(padapter, pHciCmd);
4390 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFLinkControlCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4391 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4392 status = bthci_UnknownCMD(padapter, pHciCmd);
4398 static enum hci_status
4399 bthci_HandleOGFTestingCMD(struct rtw_adapter *padapter,
4400 struct packet_irp_hcicmd_data *pHciCmd)
4402 enum hci_status status = HCI_STATUS_SUCCESS;
4403 switch (pHciCmd->OCF) {
4404 case HCI_ENABLE_DEVICE_UNDER_TEST_MODE:
4405 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_DEVICE_UNDER_TEST_MODE\n"));
4406 bthci_CmdEnableDeviceUnderTestMode(padapter, pHciCmd);
4408 case HCI_AMP_TEST_END:
4409 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_END\n"));
4410 bthci_CmdAMPTestEnd(padapter, pHciCmd);
4412 case HCI_AMP_TEST_COMMAND:
4413 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_COMMAND\n"));
4414 bthci_CmdAMPTestCommand(padapter, pHciCmd);
4416 case HCI_ENABLE_AMP_RECEIVER_REPORTS:
4417 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_AMP_RECEIVER_REPORTS\n"));
4418 bthci_CmdEnableAMPReceiverReports(padapter, pHciCmd);
4421 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4422 status = bthci_UnknownCMD(padapter, pHciCmd);
4428 static enum hci_status
4429 bthci_HandleOGFExtension(struct rtw_adapter *padapter,
4430 struct packet_irp_hcicmd_data *pHciCmd)
4432 enum hci_status status = HCI_STATUS_SUCCESS;
4433 switch (pHciCmd->OCF) {
4434 case HCI_SET_ACL_LINK_DATA_FLOW_MODE:
4435 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_DATA_FLOW_MODE\n"));
4436 status = bthci_CmdSetACLLinkDataFlowMode(padapter, pHciCmd);
4438 case HCI_SET_ACL_LINK_STATUS:
4439 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_STATUS\n"));
4440 status = bthci_CmdSetACLLinkStatus(padapter, pHciCmd);
4442 case HCI_SET_SCO_LINK_STATUS:
4443 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_SCO_LINK_STATUS\n"));
4444 status = bthci_CmdSetSCOLinkStatus(padapter, pHciCmd);
4446 case HCI_SET_RSSI_VALUE:
4447 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("HCI_SET_RSSI_VALUE\n"));
4448 status = bthci_CmdSetRSSIValue(padapter, pHciCmd);
4450 case HCI_SET_CURRENT_BLUETOOTH_STATUS:
4451 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_CURRENT_BLUETOOTH_STATUS\n"));
4452 status = bthci_CmdSetCurrentBluetoothStatus(padapter, pHciCmd);
4454 /* The following is for RTK8723 */
4456 case HCI_EXTENSION_VERSION_NOTIFY:
4457 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_EXTENSION_VERSION_NOTIFY\n"));
4458 status = bthci_CmdExtensionVersionNotify(padapter, pHciCmd);
4460 case HCI_LINK_STATUS_NOTIFY:
4461 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_LINK_STATUS_NOTIFY\n"));
4462 status = bthci_CmdLinkStatusNotify(padapter, pHciCmd);
4464 case HCI_BT_OPERATION_NOTIFY:
4465 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_BT_OPERATION_NOTIFY\n"));
4466 status = bthci_CmdBtOperationNotify(padapter, pHciCmd);
4468 case HCI_ENABLE_WIFI_SCAN_NOTIFY:
4469 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_ENABLE_WIFI_SCAN_NOTIFY\n"));
4470 status = bthci_CmdEnableWifiScanNotify(padapter, pHciCmd);
4473 /* The following is for IVT */
4474 case HCI_WIFI_CURRENT_CHANNEL:
4475 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_CHANNEL\n"));
4476 status = bthci_CmdWIFICurrentChannel(padapter, pHciCmd);
4478 case HCI_WIFI_CURRENT_BANDWIDTH:
4479 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_BANDWIDTH\n"));
4480 status = bthci_CmdWIFICurrentBandwidth(padapter, pHciCmd);
4482 case HCI_WIFI_CONNECTION_STATUS:
4483 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CONNECTION_STATUS\n"));
4484 status = bthci_CmdWIFIConnectionStatus(padapter, pHciCmd);
4488 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_UNKNOWN_COMMAND\n"));
4489 status = bthci_UnknownCMD(padapter, pHciCmd);
4496 bthci_StateStarting(struct rtw_adapter *padapter,
4497 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4499 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4500 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4502 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Starting], "));
4504 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4505 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4506 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4507 pBtMgnt->bNeedNotifyAMPNoCap = true;
4508 BTHCI_DisconnectPeer(padapter, EntryNum);
4510 case STATE_CMD_DISCONNECT_PHY_LINK:
4511 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4513 bthci_EventDisconnectPhyLinkComplete(padapter,
4515 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4518 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4520 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4522 BTHCI_DisconnectPeer(padapter, EntryNum);
4524 case STATE_CMD_MAC_START_COMPLETE:
4525 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_START_COMPLETE\n"));
4526 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR)
4527 bthci_EventChannelSelected(padapter, EntryNum);
4530 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4536 bthci_StateConnecting(struct rtw_adapter *padapter,
4537 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4539 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4540 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4542 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connecting], "));
4544 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4545 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4546 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4547 pBtMgnt->bNeedNotifyAMPNoCap = true;
4548 BTHCI_DisconnectPeer(padapter, EntryNum);
4550 case STATE_CMD_MAC_CONNECT_COMPLETE:
4551 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_COMPLETE\n"));
4553 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_JOINER) {
4554 RT_TRACE(_module_rtl871x_security_c_,
4555 _drv_info_, ("StateConnecting \n"));
4558 case STATE_CMD_DISCONNECT_PHY_LINK:
4559 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4561 bthci_EventDisconnectPhyLinkComplete(padapter,
4563 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4566 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4568 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4570 BTHCI_DisconnectPeer(padapter, EntryNum);
4573 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4574 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4575 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONTROLLER_BUSY;
4576 /* Because this state cmd is caused by the BTHCI_EventAMPStatusChange(), */
4577 /* we don't need to send event in the following BTHCI_DisconnectPeer() again. */
4578 pBtMgnt->bNeedNotifyAMPNoCap = false;
4579 BTHCI_DisconnectPeer(padapter, EntryNum);
4582 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4588 bthci_StateConnected(struct rtw_adapter *padapter,
4589 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4591 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4592 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4593 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4595 u16 logicHandle = 0;
4597 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connected], "));
4599 case STATE_CMD_DISCONNECT_PHY_LINK:
4600 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4602 /* When we are trying to disconnect the phy link, we should disconnect log link first, */
4603 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
4604 if (pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle != 0) {
4605 logicHandle = pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle;
4607 bthci_EventDisconnectLogicalLinkComplete(padapter, HCI_STATUS_SUCCESS,
4608 logicHandle, pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason);
4610 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle = 0;
4614 bthci_EventDisconnectPhyLinkComplete(padapter,
4616 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4619 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4621 BTHCI_DisconnectPeer(padapter, EntryNum);
4624 case STATE_CMD_MAC_DISCONNECT_INDICATE:
4625 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_DISCONNECT_INDICATE\n"));
4627 bthci_EventDisconnectPhyLinkComplete(padapter,
4629 /* TODO: Remote Host not local host */
4630 HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST,
4632 BTHCI_DisconnectPeer(padapter, EntryNum);
4635 case STATE_CMD_ENTER_STATE:
4636 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4638 if (pBtMgnt->bBTConnectInProgress) {
4639 pBtMgnt->bBTConnectInProgress = false;
4640 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4642 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_CONNECTED;
4643 pBTInfo->BtAsocEntry[EntryNum].b4waySuccess = true;
4644 pBtMgnt->bStartSendSupervisionPkt = true;
4646 /* for rate adaptive */
4648 rtl8723a_update_ramask(padapter,
4649 MAX_FW_SUPPORT_MACID_NUM-1-EntryNum, 0);
4651 HalSetBrateCfg23a(padapter, padapter->mlmepriv.cur_network.network.SupportedRates);
4652 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
4655 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4661 bthci_StateAuth(struct rtw_adapter *padapter, enum hci_state_with_cmd StateCmd,
4664 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4665 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4667 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Authenticating], "));
4669 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4670 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4671 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4672 pBtMgnt->bNeedNotifyAMPNoCap = true;
4673 BTHCI_DisconnectPeer(padapter, EntryNum);
4675 case STATE_CMD_DISCONNECT_PHY_LINK:
4676 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4677 bthci_EventDisconnectPhyLinkComplete(padapter,
4679 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4682 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4684 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4686 BTHCI_DisconnectPeer(padapter, EntryNum);
4688 case STATE_CMD_4WAY_FAILED:
4689 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_FAILED\n"));
4691 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_AUTH_FAIL;
4692 pBtMgnt->bNeedNotifyAMPNoCap = true;
4694 BTHCI_DisconnectPeer(padapter, EntryNum);
4696 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4698 case STATE_CMD_4WAY_SUCCESSED:
4699 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_SUCCESSED\n"));
4701 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_SUCCESS, EntryNum, INVALID_PL_HANDLE);
4703 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4705 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4708 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4714 bthci_StateDisconnecting(struct rtw_adapter *padapter,
4715 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4717 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4718 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4720 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnecting], "));
4722 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4723 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4724 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4725 bthci_EventPhysicalLinkComplete(padapter,
4726 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus,
4727 EntryNum, INVALID_PL_HANDLE);
4730 if (pBtMgnt->bBTConnectInProgress) {
4731 pBtMgnt->bBTConnectInProgress = false;
4732 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4735 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4737 case STATE_CMD_DISCONNECT_PHY_LINK:
4738 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4740 bthci_EventDisconnectPhyLinkComplete(padapter,
4742 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4745 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4747 BTHCI_DisconnectPeer(padapter, EntryNum);
4750 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4756 bthci_StateDisconnected(struct rtw_adapter *padapter,
4757 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4759 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4760 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4761 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4762 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4764 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnected], "));
4766 case STATE_CMD_CREATE_PHY_LINK:
4767 case STATE_CMD_ACCEPT_PHY_LINK:
4768 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4769 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CREATE_PHY_LINK\n"));
4771 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ACCEPT_PHY_LINK\n"));
4773 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], Disable IPS and LPS\n"));
4774 ips_leave23a(padapter);
4775 LPS_Leave23a(padapter);
4777 pBtMgnt->bPhyLinkInProgress = true;
4778 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
4779 pBtMgnt->CurrentBTConnectionCnt++;
4780 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d\n",
4781 pBtMgnt->CurrentBTConnectionCnt));
4782 pBtMgnt->BtOperationOn = true;
4783 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation ON!! CurrentConnectEntryNum = %d\n",
4784 pBtMgnt->CurrentConnectEntryNum));
4786 if (pBtMgnt->bBTConnectInProgress) {
4787 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONTROLLER_BUSY, INVALID_ENTRY_NUM, pBtMgnt->BtCurrentPhyLinkhandle);
4788 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4792 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4793 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_CREATOR;
4795 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_JOINER;
4797 /* 1. MAC not yet in selected channel */
4798 while (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)) {
4799 RTPRINT(FIOCTL, IOCTL_STATE, ("Scan/Roaming/Wifi Link is in Progress, wait 200 ms\n"));
4802 /* 2. MAC already in selected channel */
4803 RTPRINT(FIOCTL, IOCTL_STATE, ("Channel is Ready\n"));
4804 mod_timer(&pBTInfo->BTHCIJoinTimeoutTimer,
4805 jiffies + msecs_to_jiffies(pBtHciInfo->ConnAcceptTimeout));
4807 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = true;
4809 case STATE_CMD_DISCONNECT_PHY_LINK:
4810 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4812 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4814 bthci_EventDisconnectPhyLinkComplete(padapter,
4816 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4819 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4820 bthci_EventPhysicalLinkComplete(padapter,
4821 HCI_STATUS_UNKNOW_CONNECT_ID,
4822 EntryNum, INVALID_PL_HANDLE);
4825 if (pBtMgnt->bBTConnectInProgress) {
4826 pBtMgnt->bBTConnectInProgress = false;
4827 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4829 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4830 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4832 case STATE_CMD_ENTER_STATE:
4833 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4836 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4841 void BTHCI_EventParse(struct rtw_adapter *padapter, void *pEvntData, u32 dataLen)
4845 u8 BTHCI_HsConnectionEstablished(struct rtw_adapter *padapter)
4847 u8 bBtConnectionExist = false;
4848 struct bt_30info *pBtinfo = GET_BT_INFO(padapter);
4851 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
4852 if (pBtinfo->BtAsocEntry[i].b4waySuccess) {
4853 bBtConnectionExist = true;
4858 /*RTPRINT(FIOCTL, IOCTL_STATE, (" BTHCI_HsConnectionEstablished(), connection exist = %d\n", bBtConnectionExist)); */
4860 return bBtConnectionExist;
4864 BTHCI_CheckProfileExist(struct rtw_adapter *padapter,
4865 enum bt_traffic_mode_profile Profile)
4867 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4868 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4869 u8 IsPRofile = false;
4872 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4873 if (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile == Profile) {
4882 void BTHCI_UpdateBTProfileRTKToMoto(struct rtw_adapter *padapter)
4884 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4885 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4888 pBtMgnt->ExtConfig.NumberOfSCO = 0;
4890 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4891 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
4893 if (pBtMgnt->ExtConfig.linkInfo[i].BTProfile == BT_PROFILE_SCO)
4894 pBtMgnt->ExtConfig.NumberOfSCO++;
4896 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = pBtMgnt->ExtConfig.linkInfo[i].BTProfile;
4897 switch (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile) {
4898 case BT_PROFILE_SCO:
4900 case BT_PROFILE_PAN:
4901 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_BE;
4902 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4904 case BT_PROFILE_A2DP:
4905 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GULB;
4906 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_GULB;
4908 case BT_PROFILE_HID:
4909 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GUL;
4910 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4917 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RTK, NumberOfHandle = %d, NumberOfSCO = %d\n",
4918 pBtMgnt->ExtConfig.NumberOfHandle, pBtMgnt->ExtConfig.NumberOfSCO));
4921 void BTHCI_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
4923 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4924 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4926 if (pBtMgnt->ExtConfig.bEnableWifiScanNotify)
4927 bthci_EventExtWifiScanNotify(padapter, scanType);
4932 struct rtw_adapter *padapter,
4934 enum hci_state_with_cmd StateCmd,
4938 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4939 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4941 if (EntryNum == 0xff) {
4942 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, error EntryNum = 0x%x \n", EntryNum));
4945 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, EntryNum = 0x%x, CurrentState = 0x%x, BtNextState = 0x%x, StateCmd = 0x%x , StateToEnter = 0x%x\n",
4946 EntryNum, pBTInfo->BtAsocEntry[EntryNum].BtCurrentState, pBTInfo->BtAsocEntry[EntryNum].BtNextState, StateCmd, StateToEnter));
4948 if (pBTInfo->BtAsocEntry[EntryNum].BtNextState & StateToEnter) {
4949 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = StateToEnter;
4951 switch (StateToEnter) {
4952 case HCI_STATE_STARTING:
4953 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTING;
4954 bthci_StateStarting(padapter, StateCmd, EntryNum);
4956 case HCI_STATE_CONNECTING:
4957 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTING | HCI_STATE_DISCONNECTING | HCI_STATE_AUTHENTICATING;
4958 bthci_StateConnecting(padapter, StateCmd, EntryNum);
4960 case HCI_STATE_AUTHENTICATING:
4961 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTED;
4962 bthci_StateAuth(padapter, StateCmd, EntryNum);
4964 case HCI_STATE_CONNECTED:
4965 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTED | HCI_STATE_DISCONNECTING;
4966 bthci_StateConnected(padapter, StateCmd, EntryNum);
4968 case HCI_STATE_DISCONNECTING:
4969 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_DISCONNECTING;
4970 bthci_StateDisconnecting(padapter, StateCmd, EntryNum);
4972 case HCI_STATE_DISCONNECTED:
4973 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_STARTING | HCI_STATE_CONNECTING;
4974 bthci_StateDisconnected(padapter, StateCmd, EntryNum);
4977 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Unknown state to enter!!!\n"));
4981 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Wrong state to enter\n"));
4984 /* 20100325 Joseph: Disable/Enable IPS/LPS according to BT status. */
4985 if (!pBtMgnt->bBTConnectInProgress && !pBtMgnt->BtOperationOn) {
4986 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], ips_enter23a()\n"));
4987 ips_enter23a(padapter);
4991 void BTHCI_DisconnectPeer(struct rtw_adapter *padapter, u8 EntryNum)
4993 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4994 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4996 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" BTHCI_DisconnectPeer()\n"));
4998 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, EntryNum);
5000 if (pBTInfo->BtAsocEntry[EntryNum].bUsed) {
5001 /*BTPKT_SendDeauthentication(padapter, pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, unspec_reason); not porting yet */
5004 if (pBtMgnt->bBTConnectInProgress) {
5005 pBtMgnt->bBTConnectInProgress = false;
5006 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
5009 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
5011 if (pBtMgnt->bNeedNotifyAMPNoCap) {
5012 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT AMPStatus], set to invalid in BTHCI_DisconnectPeer()\n"));
5013 BTHCI_EventAMPStatusChange(padapter, AMP_STATUS_NO_CAPACITY_FOR_BT);
5017 void BTHCI_EventNumOfCompletedDataBlocks(struct rtw_adapter *padapter)
5019 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
5020 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5021 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
5022 u8 localBuf[TmpLocalBufSize] = "";
5023 u8 *pRetPar, *pTriple;
5024 u8 len = 0, i, j, handleNum = 0;
5025 struct packet_irp_hcievent_data *PPacketIrpEvent;
5026 u16 *pu2Temp, *pPackets, *pHandle, *pDblocks;
5029 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5031 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS)) {
5032 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Num Of Completed DataBlocks, Ignore to send NumOfCompletedDataBlocksEvent due to event mask page 2\n"));
5036 /* Return parameters starts from here */
5037 pRetPar = &PPacketIrpEvent->Data[0];
5038 pTriple = &pRetPar[3];
5039 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
5041 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
5042 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle) {
5044 pHandle = (u16 *)&pTriple[0]; /* Handle[i] */
5045 pPackets = (u16 *)&pTriple[2]; /* Num_Of_Completed_Packets[i] */
5046 pDblocks = (u16 *)&pTriple[4]; /* Num_Of_Completed_Blocks[i] */
5047 *pHandle = pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle;
5048 *pPackets = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5049 *pDblocks = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5050 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount) {
5052 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL,
5053 ("[BT event], Num Of Completed DataBlocks, Handle = 0x%x, Num_Of_Completed_Packets = 0x%x, Num_Of_Completed_Blocks = 0x%x\n",
5054 *pHandle, *pPackets, *pDblocks));
5056 pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount = 0;
5063 pRetPar[2] = handleNum; /* Number_of_Handles */
5065 pu2Temp = (u16 *)&pRetPar[0];
5066 *pu2Temp = BTTotalDataBlockNum;
5069 PPacketIrpEvent->EventCode = HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS;
5070 PPacketIrpEvent->Length = len;
5071 if (handleNum && sent)
5072 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
5075 void BTHCI_EventAMPStatusChange(struct rtw_adapter *padapter, u8 AMP_Status)
5077 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5078 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
5079 struct packet_irp_hcievent_data *PPacketIrpEvent;
5081 u8 localBuf[7] = "";
5084 if (AMP_Status == AMP_STATUS_NO_CAPACITY_FOR_BT) {
5085 pBtMgnt->BTNeedAMPStatusChg = true;
5086 pBtMgnt->bNeedNotifyAMPNoCap = false;
5088 BTHCI_DisconnectAll(padapter);
5089 } else if (AMP_Status == AMP_STATUS_FULL_CAPACITY_FOR_BT) {
5090 pBtMgnt->BTNeedAMPStatusChg = false;
5093 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5094 /* Return parameters starts from here */
5095 pRetPar = &PPacketIrpEvent->Data[0];
5097 pRetPar[0] = 0; /* Status */
5099 pRetPar[1] = AMP_Status; /* AMP_Status */
5102 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_STATUS_CHANGE;
5103 PPacketIrpEvent->Length = len;
5104 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS)
5105 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_STATE), ("[BT event], AMP Status Change, AMP_Status = %d\n", AMP_Status));
5108 void BTHCI_DisconnectAll(struct rtw_adapter *padapter)
5110 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5113 RTPRINT(FIOCTL, IOCTL_STATE, (" DisconnectALL()\n"));
5115 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
5116 if (pBTInfo->BtAsocEntry[i].b4waySuccess) {
5117 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, i);
5118 } else if (pBTInfo->BtAsocEntry[i].bUsed) {
5119 if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_CONNECTING) {
5120 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5121 } else if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_DISCONNECTING) {
5122 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5130 struct rtw_adapter *padapter,
5131 struct packet_irp_hcicmd_data *pHciCmd
5134 enum hci_status status = HCI_STATUS_SUCCESS;
5135 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5136 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
5138 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("\n"));
5139 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI Command start, OGF = 0x%x, OCF = 0x%x, Length = 0x%x\n",
5140 pHciCmd->OGF, pHciCmd->OCF, pHciCmd->Length));
5141 if (pHciCmd->Length) {
5142 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "HCI Command, Hex Data :\n",
5143 &pHciCmd->Data[0], pHciCmd->Length);
5145 if (pHciCmd->OGF == OGF_EXTENSION) {
5146 if (pHciCmd->OCF == HCI_SET_RSSI_VALUE)
5147 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("[BT cmd], "));
5149 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[BT cmd], "));
5151 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("[BT cmd], "));
5154 pBtDbg->dbgHciInfo.hciCmdCnt++;
5156 switch (pHciCmd->OGF) {
5157 case LINK_CONTROL_COMMANDS:
5158 status = bthci_HandleOGFLinkControlCMD(padapter, pHciCmd);
5160 case HOLD_MODE_COMMAND:
5162 case OGF_SET_EVENT_MASK_COMMAND:
5163 status = bthci_HandleOGFSetEventMaskCMD(padapter, pHciCmd);
5165 case OGF_INFORMATIONAL_PARAMETERS:
5166 status = bthci_HandleOGFInformationalParameters(padapter, pHciCmd);
5168 case OGF_STATUS_PARAMETERS:
5169 status = bthci_HandleOGFStatusParameters(padapter, pHciCmd);
5171 case OGF_TESTING_COMMANDS:
5172 status = bthci_HandleOGFTestingCMD(padapter, pHciCmd);
5175 status = bthci_HandleOGFExtension(padapter, pHciCmd);
5178 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI Command(), Unknown OGF = 0x%x\n", pHciCmd->OGF));
5179 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
5180 status = bthci_UnknownCMD(padapter, pHciCmd);
5183 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("HCI Command execution end!!\n"));
5188 /* ===== End of sync from SD7 driver COMMOM/bt_hci.c ===== */
5190 static const char *const BtStateString[] = {
5198 "BT_ACL_INQ_OR_PAG",
5199 "BT_STATE_NOT_DEFINED"
5202 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
5204 static void btdm_SetFwIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
5206 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5207 u8 H2C_Parameter[1] = {0};
5210 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Ignore Wlan_Act !!\n"));
5211 H2C_Parameter[0] |= BIT(0); /* function enable */
5212 pHalData->bt_coexist.bFWCoexistAllOff = false;
5214 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT don't ignore Wlan_Act !!\n"));
5217 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, write 0x25 = 0x%02x\n",
5220 FillH2CCmd(padapter, BT_IGNORE_WLAN_ACT_EID, 1, H2C_Parameter);
5223 static void btdm_NotifyFwScan(struct rtw_adapter *padapter, u8 scanType)
5225 u8 H2C_Parameter[1] = {0};
5227 if (scanType == true)
5228 H2C_Parameter[0] = 0x1;
5230 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Notify FW for wifi scan, write 0x3b = 0x%02x\n",
5233 FillH2CCmd(padapter, 0x3b, 1, H2C_Parameter);
5236 static void btdm_1AntSetPSMode(struct rtw_adapter *padapter,
5237 u8 enable, u8 smartps, u8 mode)
5239 struct pwrctrl_priv *pwrctrl;
5241 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current LPS(%s, %d), smartps =%d\n", enable == true?"ON":"OFF", mode, smartps));
5243 pwrctrl = &padapter->pwrctrlpriv;
5245 if (enable == true) {
5246 rtw_set_ps_mode23a(padapter, PS_MODE_MIN, smartps, mode);
5248 rtw_set_ps_mode23a(padapter, PS_MODE_ACTIVE, 0, 0);
5249 LPS_RF_ON_check23a(padapter, 100);
5253 static void btdm_1AntTSFSwitch(struct rtw_adapter *padapter, u8 enable)
5257 oldVal = rtl8723au_read8(padapter, 0x550);
5260 newVal = oldVal | EN_BCN_FUNCTION;
5262 newVal = oldVal & ~EN_BCN_FUNCTION;
5264 if (oldVal != newVal)
5265 rtl8723au_write8(padapter, 0x550, newVal);
5268 static u8 btdm_Is1AntPsTdmaStateChange(struct rtw_adapter *padapter)
5270 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5271 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5273 if ((pBtdm8723->bPrePsTdmaOn != pBtdm8723->bCurPsTdmaOn) ||
5274 (pBtdm8723->prePsTdma != pBtdm8723->curPsTdma))
5280 /* Before enter TDMA, make sure Power Saving is enable! */
5283 struct rtw_adapter *padapter,
5288 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5289 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5291 pBtdm8723->bCurPsTdmaOn = bTurnOn;
5292 pBtdm8723->curPsTdma = type;
5295 case 1: /* A2DP Level-1 or FTP/OPP */
5297 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5298 /* wide duration for WiFi */
5299 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x0, 0x58);
5302 case 2: /* A2DP Level-2 */
5303 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5304 /* normal duration for WiFi */
5305 BTDM_SetFw3a(padapter, 0xd3, 0x12, 0x12, 0x0, 0x58);
5308 case 3: /* BT FTP/OPP */
5309 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5310 /* normal duration for WiFi */
5311 BTDM_SetFw3a(padapter, 0xd3, 0x30, 0x03, 0x10, 0x58);
5315 case 4: /* for wifi scan & BT is connected */
5316 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5317 /* protect 3 beacons in 3-beacon period & no Tx pause at BT slot */
5318 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x0);
5321 case 5: /* for WiFi connected-busy & BT is Non-Connected-Idle */
5322 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5323 /* SCO mode, Ant fixed at WiFi, WLAN_Act toggle */
5324 BTDM_SetFw3a(padapter, 0x61, 0x15, 0x03, 0x31, 0x00);
5327 case 9: /* ACL high-retry type - 2 */
5328 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5329 /* narrow duration for WiFi */
5330 BTDM_SetFw3a(padapter, 0xd3, 0xa, 0xa, 0x0, 0x58); /* narrow duration for WiFi */
5333 case 10: /* for WiFi connect idle & BT ACL busy or WiFi Connected-Busy & BT is Inquiry */
5334 if (btdm_Is1AntPsTdmaStateChange(padapter))
5335 BTDM_SetFw3a(padapter, 0x13, 0xa, 0xa, 0x0, 0x40);
5337 case 11: /* ACL high-retry type - 3 */
5338 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5339 /* narrow duration for WiFi */
5340 BTDM_SetFw3a(padapter, 0xd3, 0x05, 0x05, 0x00, 0x58);
5343 case 12: /* for WiFi Connected-Busy & BT is Connected-Idle */
5344 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5345 /* Allow High-Pri BT */
5346 BTDM_SetFw3a(padapter, 0xeb, 0x0a, 0x03, 0x31, 0x18);
5349 case 20: /* WiFi only busy , TDMA mode for power saving */
5350 if (btdm_Is1AntPsTdmaStateChange(padapter))
5351 BTDM_SetFw3a(padapter, 0x13, 0x25, 0x25, 0x00, 0x00);
5353 case 27: /* WiFi DHCP/Site Survey & BT SCO busy */
5354 if (btdm_Is1AntPsTdmaStateChange(padapter))
5355 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x31, 0x98);
5357 case 28: /* WiFi DHCP/Site Survey & BT idle */
5358 if (btdm_Is1AntPsTdmaStateChange(padapter))
5359 BTDM_SetFw3a(padapter, 0x69, 0x25, 0x03, 0x31, 0x00);
5361 case 29: /* WiFi DHCP/Site Survey & BT ACL busy */
5362 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5363 BTDM_SetFw3a(padapter, 0xeb, 0x1a, 0x1a, 0x01, 0x18);
5364 rtl8723au_write32(padapter, 0x6c0, 0x5afa5afa);
5365 rtl8723au_write32(padapter, 0x6c4, 0x5afa5afa);
5368 case 30: /* WiFi idle & BT Inquiry */
5369 if (btdm_Is1AntPsTdmaStateChange(padapter))
5370 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x00);
5372 case 31: /* BT HID */
5373 if (btdm_Is1AntPsTdmaStateChange(padapter))
5374 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x58);
5376 case 32: /* BT SCO & Inquiry */
5377 if (btdm_Is1AntPsTdmaStateChange(padapter))
5378 BTDM_SetFw3a(padapter, 0xab, 0x0a, 0x03, 0x11, 0x98);
5380 case 33: /* BT SCO & WiFi site survey */
5381 if (btdm_Is1AntPsTdmaStateChange(padapter))
5382 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x30, 0x98);
5384 case 34: /* BT HID & WiFi site survey */
5385 if (btdm_Is1AntPsTdmaStateChange(padapter))
5386 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x18);
5388 case 35: /* BT HID & WiFi Connecting */
5389 if (btdm_Is1AntPsTdmaStateChange(padapter))
5390 BTDM_SetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x00, 0x18);
5394 /* disable PS-TDMA */
5397 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5398 /* Antenna control by PTA, 0x870 = 0x310 */
5399 BTDM_SetFw3a(padapter, 0x8, 0x0, 0x0, 0x0, 0x0);
5404 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5405 /* Antenna control by PTA, 0x870 = 0x310 */
5406 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5408 /* Switch Antenna to BT */
5409 rtl8723au_write16(padapter, 0x860, 0x210);
5410 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x210, Switch Antenna to BT\n"));
5413 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5414 /* Antenna control by PTA, 0x870 = 0x310 */
5415 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5417 /* Switch Antenna to WiFi */
5418 rtl8723au_write16(padapter, 0x860, 0x110);
5419 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x110, Switch Antenna to WiFi\n"));
5424 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current TDMA(%s, %d)\n",
5425 pBtdm8723->bCurPsTdmaOn?"ON":"OFF", pBtdm8723->curPsTdma));
5427 /* update pre state */
5428 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
5429 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
5433 _btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn, u8 smartps,
5434 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5436 struct pwrctrl_priv *pwrctrl;
5437 struct hal_data_8723a *pHalData;
5438 struct btdm_8723a_1ant *pBtdm8723;
5442 if (!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) &&
5443 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
5444 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5447 psOption &= ~BIT(0);
5449 RTPRINT(FBT, BT_TRACE,
5450 ("[BTCoex], Set LPS(%s, %d) TDMA(%s, %d)\n",
5451 bPSEn == true?"ON":"OFF", psOption,
5452 bTDMAOn == true?"ON":"OFF", tdmaType));
5454 pwrctrl = &padapter->pwrctrlpriv;
5455 pHalData = GET_HAL_DATA(padapter);
5456 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5459 if (pBtdm8723->bWiFiHalt) {
5460 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Halt!!\n"));
5464 if (pwrctrl->bInSuspend) {
5465 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Suspend!!\n"));
5469 if (padapter->bDriverStopped) {
5470 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi driver stopped!!\n"));
5474 if (padapter->bSurpriseRemoved) {
5475 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi Surprise Removed!!\n"));
5479 psMode = PS_MODE_MIN;
5481 psMode = PS_MODE_ACTIVE;
5485 if (psMode != pwrctrl->pwr_mode) {
5487 } else if (psMode != PS_MODE_ACTIVE) {
5488 if (psOption != pwrctrl->bcn_ant_mode)
5490 else if (smartps != pwrctrl->smart_ps)
5500 if (pBtdm8723->bCurPsTdmaOn) {
5502 btdm_1AntPsTdma(padapter, false, tdmaType);
5504 if (!rtl8723a_BT_enabled(padapter) ||
5505 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_NO_CONNECTION) ||
5506 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_CONNECT_IDLE) ||
5508 btdm_1AntPsTdma(padapter, false, 9);
5510 btdm_1AntPsTdma(padapter, false, 0);
5514 /* change Power Save State */
5515 btdm_1AntSetPSMode(padapter, bPSEn, smartps, psOption);
5518 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5522 btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn,
5523 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5525 _btdm_1AntSetPSTDMA(padapter, bPSEn, 0, psOption, bTDMAOn, tdmaType);
5528 static void btdm_1AntWifiParaAdjust(struct rtw_adapter *padapter, u8 bEnable)
5530 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5531 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5534 pBtdm8723->curWifiPara = 1;
5535 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5536 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_LOW_PENALTY);
5538 pBtdm8723->curWifiPara = 2;
5539 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5540 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_NORMAL);
5545 static void btdm_1AntPtaParaReload(struct rtw_adapter *padapter)
5548 rtl8723au_write8(padapter, 0x6cc, 0x0); /* 1-Ant coex */
5549 rtl8723au_write32(padapter, 0x6c8, 0xffff); /* wifi break table */
5550 rtl8723au_write32(padapter, 0x6c4, 0x55555555); /* coex table */
5552 /* Antenna switch control parameter */
5553 rtl8723au_write32(padapter, 0x858, 0xaaaaaaaa);
5554 if (IS_8723A_A_CUT(GET_HAL_DATA(padapter)->VersionID)) {
5555 /* SPDT(connected with TRSW) control by hardware PTA */
5556 rtl8723au_write32(padapter, 0x870, 0x0);
5557 rtl8723au_write8(padapter, 0x40, 0x24);
5559 rtl8723au_write8(padapter, 0x40, 0x20);
5560 /* set antenna at bt side if ANTSW is software control */
5561 rtl8723au_write16(padapter, 0x860, 0x210);
5562 /* SPDT(connected with TRSW) control by hardware PTA */
5563 rtl8723au_write32(padapter, 0x870, 0x300);
5564 /* ANTSW keep by GNT_BT */
5565 rtl8723au_write32(padapter, 0x874, 0x22804000);
5568 /* coexistence parameters */
5569 rtl8723au_write8(padapter, 0x778, 0x1); /* enable RTK mode PTA */
5571 /* BT don't ignore WLAN_Act */
5572 btdm_SetFwIgnoreWlanAct(padapter, false);
5577 *1: upgrade (add WiFi duration time)
5579 *-1: downgrade (add BT duration time)
5581 static s8 btdm_1AntTdmaJudgement(struct rtw_adapter *padapter, u8 retry)
5583 struct hal_data_8723a *pHalData;
5584 struct btdm_8723a_1ant *pBtdm8723;
5585 static s8 up, dn, m = 1, n = 3, WaitCount;
5588 pHalData = GET_HAL_DATA(padapter);
5589 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5592 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5603 /* no retry in the last 2-second duration */
5609 /* retry = 0 in consecutive 3m*(2s), add WiFi duration */
5617 } else if (retry <= 3) {
5618 /* retry<= 3 in the last 2-second duration */
5625 /* retry<= 3 in consecutive 2*(2s), minus WiFi duration (add BT duration) */
5628 /* record how many time downgrad WiFi duration */
5633 /* the max number of m is 20 */
5634 /* the longest time of upgrade WiFi duration is 20*3*2s = 120s */
5642 /* retry count > 3 */
5643 /* retry>3, minus WiFi duration (add BT duration) */
5646 /* record how many time downgrad WiFi duration */
5661 static void btdm_1AntTdmaDurationAdjustForACL(struct rtw_adapter *padapter)
5663 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5664 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5666 if (pBtdm8723->psTdmaGlobalCnt != pBtdm8723->psTdmaMonitorCnt) {
5667 pBtdm8723->psTdmaMonitorCnt = 0;
5668 pBtdm8723->psTdmaGlobalCnt = 0;
5670 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5671 btdm_1AntSetPSTDMA(padapter, true, 0, true, 2);
5672 pBtdm8723->psTdmaDuAdjType = 2;
5674 /* Now we only have 4 level Ps Tdma, */
5675 /* if that's not the following 4 level(will changed by wifi scan, dhcp...), */
5676 /* then we have to adjust it back to the previous record one. */
5677 if ((pBtdm8723->curPsTdma != 1) &&
5678 (pBtdm8723->curPsTdma != 2) &&
5679 (pBtdm8723->curPsTdma != 9) &&
5680 (pBtdm8723->curPsTdma != 11)) {
5681 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5685 judge = btdm_1AntTdmaJudgement(padapter, pHalData->bt_coexist.halCoex8723.btRetryCnt);
5687 if (pBtdm8723->curPsTdma == 1) {
5688 /* Decrease WiFi duration for high BT retry */
5689 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5690 pBtdm8723->psTdmaDuAdjType = 9;
5692 pBtdm8723->psTdmaDuAdjType = 2;
5693 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5694 } else if (pBtdm8723->curPsTdma == 2) {
5695 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5696 pBtdm8723->psTdmaDuAdjType = 9;
5697 } else if (pBtdm8723->curPsTdma == 9) {
5698 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5699 pBtdm8723->psTdmaDuAdjType = 11;
5701 } else if (judge == 1) {
5702 if (pBtdm8723->curPsTdma == 11) {
5703 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5704 pBtdm8723->psTdmaDuAdjType = 9;
5705 } else if (pBtdm8723->curPsTdma == 9) {
5706 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5707 pBtdm8723->psTdmaDuAdjType = 9;
5709 pBtdm8723->psTdmaDuAdjType = 2;
5710 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5711 } else if (pBtdm8723->curPsTdma == 2) {
5712 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5713 pBtdm8723->psTdmaDuAdjType = 9;
5715 pBtdm8723->psTdmaDuAdjType = 1;
5716 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5720 RTPRINT(FBT, BT_TRACE,
5721 ("[BTCoex], ACL current TDMA(%s, %d)\n",
5722 (pBtdm8723->bCurPsTdmaOn ? "ON" : "OFF"), pBtdm8723->curPsTdma));
5724 pBtdm8723->psTdmaMonitorCnt++;
5727 static void btdm_1AntCoexProcessForWifiConnect(struct rtw_adapter *padapter)
5729 struct mlme_priv *pmlmepriv;
5730 struct hal_data_8723a *pHalData;
5731 struct bt_coexist_8723a *pBtCoex;
5732 struct btdm_8723a_1ant *pBtdm8723;
5735 pmlmepriv = &padapter->mlmepriv;
5736 pHalData = GET_HAL_DATA(padapter);
5737 pBtCoex = &pHalData->bt_coexist.halCoex8723;
5738 pBtdm8723 = &pBtCoex->btdm1Ant;
5739 BtState = pBtCoex->c2hBtInfo;
5741 RTPRINT(FBT, BT_TRACE, ("[BTCoex], WiFi is %s\n",
5742 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
5743 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is %s\n",
5744 BtStateString[BtState]));
5746 padapter->pwrctrlpriv.btcoex_rfon = false;
5748 if (!BTDM_IsWifiBusy(padapter) &&
5749 !check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE) &&
5750 (BtState == BT_INFO_STATE_NO_CONNECTION ||
5751 BtState == BT_INFO_STATE_CONNECT_IDLE)) {
5753 case BT_INFO_STATE_NO_CONNECTION:
5754 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 9);
5756 case BT_INFO_STATE_CONNECT_IDLE:
5757 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 0);
5762 case BT_INFO_STATE_NO_CONNECTION:
5763 case BT_INFO_STATE_CONNECT_IDLE:
5765 btdm_1AntSetPSTDMA(padapter, false, 0, true, 5);
5766 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5767 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5769 case BT_INFO_STATE_ACL_INQ_OR_PAG:
5770 RTPRINT(FBT, BT_TRACE,
5771 ("[BTCoex], BT PROFILE is "
5772 "BT_INFO_STATE_ACL_INQ_OR_PAG\n"));
5773 case BT_INFO_STATE_INQ_OR_PAG:
5774 padapter->pwrctrlpriv.btcoex_rfon = true;
5775 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
5777 case BT_INFO_STATE_SCO_ONLY_BUSY:
5778 case BT_INFO_STATE_ACL_SCO_BUSY:
5779 if (true == pBtCoex->bC2hBtInquiryPage)
5780 btdm_1AntSetPSTDMA(padapter, false, 0,
5783 #ifdef BTCOEX_CMCC_TEST
5784 btdm_1AntSetPSTDMA(padapter, false, 0,
5786 #else /* !BTCOEX_CMCC_TEST */
5787 btdm_1AntSetPSTDMA(padapter, false, 0,
5789 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
5790 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
5791 #endif /* !BTCOEX_CMCC_TEST */
5794 case BT_INFO_STATE_ACL_ONLY_BUSY:
5795 padapter->pwrctrlpriv.btcoex_rfon = true;
5796 if (pBtCoex->c2hBtProfile == BT_INFO_HID) {
5797 RTPRINT(FBT, BT_TRACE,
5798 ("[BTCoex], BT PROFILE is HID\n"));
5799 btdm_1AntSetPSTDMA(padapter, true, 0, true, 31);
5800 } else if (pBtCoex->c2hBtProfile == BT_INFO_FTP) {
5801 RTPRINT(FBT, BT_TRACE,
5802 ("[BTCoex], BT PROFILE is FTP/OPP\n"));
5803 btdm_1AntSetPSTDMA(padapter, true, 0, true, 3);
5804 } else if (pBtCoex->c2hBtProfile == (BT_INFO_A2DP|BT_INFO_FTP)) {
5805 RTPRINT(FBT, BT_TRACE,
5806 ("[BTCoex], BT PROFILE is A2DP_FTP\n"));
5807 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5809 if (pBtCoex->c2hBtProfile == BT_INFO_A2DP)
5810 RTPRINT(FBT, BT_TRACE,
5811 ("[BTCoex], BT PROFILE is "
5814 RTPRINT(FBT, BT_TRACE,
5815 ("[BTCoex], BT PROFILE is "
5816 "UNKNOWN(0x%02X)! Use A2DP "
5818 pBtCoex->c2hBtProfile));
5819 btdm_1AntTdmaDurationAdjustForACL(padapter);
5825 pBtdm8723->psTdmaGlobalCnt++;
5829 btdm_1AntUpdateHalRAMask(struct rtw_adapter *padapter, u32 mac_id, u32 filter)
5834 u8 shortGIrate = false;
5835 int supportRateNum = 0;
5836 struct sta_info *psta;
5837 struct hal_data_8723a *pHalData;
5838 struct dm_priv *pdmpriv;
5839 struct mlme_ext_priv *pmlmeext;
5840 struct mlme_ext_info *pmlmeinfo;
5841 struct wlan_bssid_ex *cur_network;
5843 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d, filter = 0x%08x!!\n",
5844 __func__, mac_id, filter));
5846 pHalData = GET_HAL_DATA(padapter);
5847 pdmpriv = &pHalData->dmpriv;
5848 pmlmeext = &padapter->mlmeextpriv;
5849 pmlmeinfo = &pmlmeext->mlmext_info;
5850 cur_network = &pmlmeinfo->network;
5852 if (mac_id >= NUM_STA) { /* CAM_SIZE */
5853 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d illegal!!\n",
5858 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
5860 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, Can't find station!!\n",
5868 case 0:/* for infra mode */
5870 rtw_get_rateset_len23a(cur_network->SupportedRates);
5871 mask = update_supported_rate23a(cur_network->SupportedRates,
5873 mask |= (pmlmeinfo->HT_enable) ?
5874 update_MSC_rate23a(&pmlmeinfo->HT_caps):0;
5875 if (support_short_GI23a(padapter, &pmlmeinfo->HT_caps))
5878 case 1:/* for broadcast/multicast */
5879 supportRateNum = rtw_get_rateset_len23a(
5880 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5881 mask = update_basic_rate23a(cur_network->SupportedRates,
5884 default: /* for each sta in IBSS */
5885 supportRateNum = rtw_get_rateset_len23a(
5886 pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5887 mask = update_supported_rate23a(cur_network->SupportedRates,
5891 mask |= ((raid<<28)&0xf0000000);
5894 init_rate = get_highest_rate_idx23a(mask)&0x3f;
5896 if (pHalData->fw_ractrl) {
5899 arg = mac_id&0x1f;/* MACID */
5901 if (true == shortGIrate)
5904 RTPRINT(FBT, BT_TRACE,
5905 ("[BTCoex], Update FW RAID entry, MASK = 0x%08x, "
5906 "arg = 0x%02x\n", mask, arg));
5908 rtl8723a_set_raid_cmd(padapter, mask, arg);
5911 init_rate |= BIT(6);
5913 rtl8723au_write8(padapter, REG_INIDATA_RATE_SEL + mac_id,
5917 psta->init_rate = init_rate;
5918 pdmpriv->INIDATA_RATE[mac_id] = init_rate;
5922 btdm_1AntUpdateHalRAMaskForSCO(struct rtw_adapter *padapter, u8 forceUpdate)
5924 struct btdm_8723a_1ant *pBtdm8723;
5925 struct sta_priv *pstapriv;
5926 struct wlan_bssid_ex *cur_network;
5927 struct sta_info *psta;
5931 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5933 if (pBtdm8723->bRAChanged == true && forceUpdate == false)
5936 pstapriv = &padapter->stapriv;
5937 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5938 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5939 macid = psta->mac_id;
5941 filter |= BIT(_1M_RATE_);
5942 filter |= BIT(_2M_RATE_);
5943 filter |= BIT(_5M_RATE_);
5944 filter |= BIT(_11M_RATE_);
5945 filter |= BIT(_6M_RATE_);
5946 filter |= BIT(_9M_RATE_);
5948 btdm_1AntUpdateHalRAMask(padapter, macid, filter);
5950 pBtdm8723->bRAChanged = true;
5953 static void btdm_1AntRecoverHalRAMask(struct rtw_adapter *padapter)
5955 struct btdm_8723a_1ant *pBtdm8723;
5956 struct sta_priv *pstapriv;
5957 struct wlan_bssid_ex *cur_network;
5958 struct sta_info *psta;
5960 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5962 if (pBtdm8723->bRAChanged == false)
5965 pstapriv = &padapter->stapriv;
5966 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5967 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5969 Update_RA_Entry23a(padapter, psta);
5971 pBtdm8723->bRAChanged = false;
5975 btdm_1AntBTStateChangeHandler(struct rtw_adapter *padapter,
5976 enum bt_state_1ant oldState,
5977 enum bt_state_1ant newState)
5979 struct hal_data_8723a *phaldata;
5980 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT state change, %s => %s\n",
5981 BtStateString[oldState],
5982 BtStateString[newState]));
5984 /* BT default ignore wlan active, */
5985 /* WiFi MUST disable this when BT is enable */
5986 if (newState > BT_INFO_STATE_DISABLED)
5987 btdm_SetFwIgnoreWlanAct(padapter, false);
5989 if ((check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
5990 (BTDM_IsWifiConnectionExist(padapter))) {
5991 if ((newState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
5992 (newState == BT_INFO_STATE_ACL_SCO_BUSY)) {
5993 btdm_1AntUpdateHalRAMaskForSCO(padapter, false);
5995 /* Recover original RA setting */
5996 btdm_1AntRecoverHalRAMask(padapter);
5999 phaldata = GET_HAL_DATA(padapter);
6000 phaldata->bt_coexist.halCoex8723.btdm1Ant.bRAChanged = false;
6003 if (oldState == newState)
6006 if (oldState == BT_INFO_STATE_ACL_ONLY_BUSY) {
6007 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
6008 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCnt = 0;
6009 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
6012 if ((oldState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6013 (oldState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6014 struct hal_data_8723a *Hal = GET_HAL_DATA(padapter);
6015 Hal->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
6018 /* Active 2Ant mechanism when BT Connected */
6019 if ((oldState == BT_INFO_STATE_DISABLED) ||
6020 (oldState == BT_INFO_STATE_NO_CONNECTION)) {
6021 if ((newState != BT_INFO_STATE_DISABLED) &&
6022 (newState != BT_INFO_STATE_NO_CONNECTION)) {
6023 BTDM_SetSwRfRxLpfCorner(padapter,
6024 BT_RF_RX_LPF_CORNER_SHRINK);
6025 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6026 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6029 if ((newState == BT_INFO_STATE_DISABLED) ||
6030 (newState == BT_INFO_STATE_NO_CONNECTION)) {
6031 BTDM_SetSwRfRxLpfCorner(padapter,
6032 BT_RF_RX_LPF_CORNER_RESUME);
6033 BTDM_AGCTable(padapter, BT_AGCTABLE_OFF);
6034 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_OFF);
6039 static void btdm_1AntBtCoexistHandler(struct rtw_adapter *padapter)
6041 struct hal_data_8723a *pHalData;
6042 struct bt_coexist_8723a *pBtCoex8723;
6043 struct btdm_8723a_1ant *pBtdm8723;
6045 pHalData = GET_HAL_DATA(padapter);
6046 pBtCoex8723 = &pHalData->bt_coexist.halCoex8723;
6047 pBtdm8723 = &pBtCoex8723->btdm1Ant;
6048 padapter->pwrctrlpriv.btcoex_rfon = false;
6049 if (!rtl8723a_BT_enabled(padapter)) {
6050 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is disabled\n"));
6052 if (BTDM_IsWifiConnectionExist(padapter)) {
6053 RTPRINT(FBT, BT_TRACE,
6054 ("[BTCoex], wifi is connected\n"));
6056 if (BTDM_IsWifiBusy(padapter)) {
6057 RTPRINT(FBT, BT_TRACE,
6058 ("[BTCoex], Wifi is busy\n"));
6059 btdm_1AntSetPSTDMA(padapter, false, 0,
6062 RTPRINT(FBT, BT_TRACE,
6063 ("[BTCoex], Wifi is idle\n"));
6064 _btdm_1AntSetPSTDMA(padapter, true, 2, 1,
6068 RTPRINT(FBT, BT_TRACE,
6069 ("[BTCoex], wifi is disconnected\n"));
6071 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6074 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is enabled\n"));
6076 if (BTDM_IsWifiConnectionExist(padapter)) {
6077 RTPRINT(FBT, BT_TRACE,
6078 ("[BTCoex], wifi is connected\n"));
6080 btdm_1AntWifiParaAdjust(padapter, true);
6081 btdm_1AntCoexProcessForWifiConnect(padapter);
6083 RTPRINT(FBT, BT_TRACE,
6084 ("[BTCoex], wifi is disconnected\n"));
6086 /* Antenna switch at BT side(0x870 = 0x300,
6087 0x860 = 0x210) after PSTDMA off */
6088 btdm_1AntWifiParaAdjust(padapter, false);
6089 btdm_1AntSetPSTDMA(padapter, false, 0, false, 0);
6093 btdm_1AntBTStateChangeHandler(padapter, pBtCoex8723->prec2hBtInfo,
6094 pBtCoex8723->c2hBtInfo);
6095 pBtCoex8723->prec2hBtInfo = pBtCoex8723->c2hBtInfo;
6098 void BTDM_1AntSignalCompensation(struct rtw_adapter *padapter,
6099 u8 *rssi_wifi, u8 *rssi_bt)
6101 struct hal_data_8723a *pHalData;
6102 struct btdm_8723a_1ant *pBtdm8723;
6103 u8 RSSI_WiFi_Cmpnstn, RSSI_BT_Cmpnstn;
6105 pHalData = GET_HAL_DATA(padapter);
6106 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
6107 RSSI_WiFi_Cmpnstn = 0;
6108 RSSI_BT_Cmpnstn = 0;
6110 switch (pBtdm8723->curPsTdma) {
6111 case 1: /* WiFi 52ms */
6112 RSSI_WiFi_Cmpnstn = 11; /* 22*0.48 */
6114 case 2: /* WiFi 36ms */
6115 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6117 case 9: /* WiFi 20ms */
6118 RSSI_WiFi_Cmpnstn = 18; /* 22*0.80 */
6120 case 11: /* WiFi 10ms */
6121 RSSI_WiFi_Cmpnstn = 20; /* 22*0.90 */
6123 case 4: /* WiFi 21ms */
6124 RSSI_WiFi_Cmpnstn = 17; /* 22*0.79 */
6126 case 16: /* WiFi 24ms */
6127 RSSI_WiFi_Cmpnstn = 18; /* 22*0.76 */
6129 case 18: /* WiFi 37ms */
6130 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6132 case 23: /* Level-1, Antenna switch to BT at all time */
6133 case 24: /* Level-2, Antenna switch to BT at all time */
6134 case 25: /* Level-3a, Antenna switch to BT at all time */
6135 case 26: /* Level-3b, Antenna switch to BT at all time */
6136 case 27: /* Level-3b, Antenna switch to BT at all time */
6137 case 33: /* BT SCO & WiFi site survey */
6138 RSSI_WiFi_Cmpnstn = 22;
6144 if (rssi_wifi && RSSI_WiFi_Cmpnstn) {
6145 RTPRINT(FBT, BT_TRACE,
6146 ("[BTCoex], 1AntSgnlCmpnstn, case %d, WiFiCmpnstn "
6147 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6148 RSSI_WiFi_Cmpnstn, *rssi_wifi,
6149 *rssi_wifi+RSSI_WiFi_Cmpnstn));
6150 *rssi_wifi += RSSI_WiFi_Cmpnstn;
6153 if (rssi_bt && RSSI_BT_Cmpnstn) {
6154 RTPRINT(FBT, BT_TRACE,
6155 ("[BTCoex], 1AntSgnlCmpnstn, case %d, BTCmpnstn "
6156 "=%d(%d => %d)\n", pBtdm8723->curPsTdma,
6157 RSSI_BT_Cmpnstn, *rssi_bt, *rssi_bt+RSSI_BT_Cmpnstn));
6158 *rssi_bt += RSSI_BT_Cmpnstn;
6162 static void BTDM_1AntParaInit(struct rtw_adapter *padapter)
6164 struct hal_data_8723a *pHalData;
6165 struct bt_coexist_8723a *pBtCoex;
6166 struct btdm_8723a_1ant *pBtdm8723;
6168 pHalData = GET_HAL_DATA(padapter);
6169 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6170 pBtdm8723 = &pBtCoex->btdm1Ant;
6172 /* Enable counter statistics */
6173 rtl8723au_write8(padapter, 0x76e, 0x4);
6174 btdm_1AntPtaParaReload(padapter);
6176 pBtdm8723->wifiRssiThresh = 48;
6178 pBtdm8723->bWiFiHalt = false;
6179 pBtdm8723->bRAChanged = false;
6181 if ((pBtCoex->c2hBtInfo != BT_INFO_STATE_DISABLED) &&
6182 (pBtCoex->c2hBtInfo != BT_INFO_STATE_NO_CONNECTION)) {
6183 BTDM_SetSwRfRxLpfCorner(padapter, BT_RF_RX_LPF_CORNER_SHRINK);
6184 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6185 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6189 static void BTDM_1AntForHalt(struct rtw_adapter *padapter)
6191 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for halt\n"));
6193 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6196 btdm_1AntWifiParaAdjust(padapter, false);
6198 /* don't use btdm_1AntSetPSTDMA() here */
6199 /* it will call rtw_set_ps_mode23a() and request pwrpriv->lock. */
6200 /* This will lead to deadlock, if this function is called in IPS */
6201 /* Lucas@20130205 */
6202 btdm_1AntPsTdma(padapter, false, 0);
6204 btdm_SetFwIgnoreWlanAct(padapter, true);
6207 static void BTDM_1AntLpsLeave(struct rtw_adapter *padapter)
6209 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for LPS Leave\n"));
6211 /* Prevent from entering LPS again */
6212 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt =
6215 btdm_1AntSetPSTDMA(padapter, false, 0, false, 8);
6216 /*btdm_1AntPsTdma(padapter, false, 8); */
6219 static void BTDM_1AntWifiAssociateNotify(struct rtw_adapter *padapter, u8 type)
6221 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6223 RTPRINT(FBT, BT_TRACE,
6224 ("\n[BTCoex], 1Ant for associate, type =%d\n", type));
6227 rtl8723a_CheckAntenna_Selection(padapter);
6228 if (!rtl8723a_BT_enabled(padapter))
6229 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6231 struct bt_coexist_8723a *pBtCoex;
6234 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6235 BtState = pBtCoex->c2hBtInfo;
6237 btdm_1AntTSFSwitch(padapter, true);
6239 if (BtState == BT_INFO_STATE_NO_CONNECTION ||
6240 BtState == BT_INFO_STATE_CONNECT_IDLE) {
6241 btdm_1AntSetPSTDMA(padapter, false, 0,
6243 } else if (BtState == BT_INFO_STATE_SCO_ONLY_BUSY ||
6244 BtState == BT_INFO_STATE_ACL_SCO_BUSY) {
6245 btdm_1AntSetPSTDMA(padapter, false, 0,
6247 rtl8723au_write32(padapter, 0x6c0, 0x5a5a5a5a);
6248 rtl8723au_write32(padapter, 0x6c4, 0x5a5a5a5a);
6249 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY ||
6250 BtState == BT_INFO_STATE_ACL_INQ_OR_PAG) {
6251 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6252 btdm_1AntSetPSTDMA(padapter, false, 0,
6255 btdm_1AntSetPSTDMA(padapter, false, 0,
6260 if (!rtl8723a_BT_enabled(padapter)) {
6261 if (!BTDM_IsWifiConnectionExist(padapter)) {
6262 btdm_1AntPsTdma(padapter, false, 0);
6263 btdm_1AntTSFSwitch(padapter, false);
6267 btdm_1AntBtCoexistHandler(padapter);
6272 BTDM_1AntMediaStatusNotify(struct rtw_adapter *padapter,
6273 enum rt_media_status mstatus)
6275 struct bt_coexist_8723a *pBtCoex;
6277 pBtCoex = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723;
6279 RTPRINT(FBT, BT_TRACE,
6280 ("\n\n[BTCoex]******************************\n"));
6281 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatus, WiFi %s !!\n",
6282 mstatus == RT_MEDIA_CONNECT?"CONNECT":"DISCONNECT"));
6283 RTPRINT(FBT, BT_TRACE, ("[BTCoex]******************************\n"));
6285 if (RT_MEDIA_CONNECT == mstatus) {
6286 if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) {
6287 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_SCO_ONLY_BUSY ||
6288 pBtCoex->c2hBtInfo == BT_INFO_STATE_ACL_SCO_BUSY)
6289 btdm_1AntUpdateHalRAMaskForSCO(padapter, true);
6292 padapter->pwrctrlpriv.DelayLPSLastTimeStamp = jiffies;
6293 BTDM_1AntForDhcp(padapter);
6295 /* DBG_8723A("%s rtl8723a_DeinitAntenna_Selection\n",
6297 rtl8723a_DeinitAntenna_Selection(padapter);
6298 btdm_1AntBtCoexistHandler(padapter);
6299 pBtCoex->btdm1Ant.bRAChanged = false;
6303 void BTDM_1AntForDhcp(struct rtw_adapter *padapter)
6305 struct hal_data_8723a *pHalData;
6307 struct bt_coexist_8723a *pBtCoex;
6308 struct btdm_8723a_1ant *pBtdm8723;
6310 pHalData = GET_HAL_DATA(padapter);
6311 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6312 BtState = pBtCoex->c2hBtInfo;
6313 pBtdm8723 = &pBtCoex->btdm1Ant;
6315 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for DHCP\n"));
6316 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, WiFi is %s\n",
6317 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6318 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, %s\n",
6319 BtStateString[BtState]));
6321 BTDM_1AntWifiAssociateNotify(padapter, true);
6324 static void BTDM_1AntWifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
6326 struct hal_data_8723a *pHalData;
6328 struct bt_coexist_8723a *pBtCoex;
6329 struct btdm_8723a_1ant *pBtdm8723;
6331 pHalData = GET_HAL_DATA(padapter);
6332 BtState = pHalData->bt_coexist.halCoex8723.c2hBtInfo;
6333 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6334 pBtdm8723 = &pBtCoex->btdm1Ant;
6336 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for wifi scan =%d!!\n",
6338 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, WiFi is %s\n",
6339 BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6340 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, %s\n",
6341 BtStateString[BtState]));
6344 rtl8723a_CheckAntenna_Selection(padapter);
6345 if (!rtl8723a_BT_enabled(padapter)) {
6346 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6347 } else if (BTDM_IsWifiConnectionExist(padapter) == false) {
6348 BTDM_1AntWifiAssociateNotify(padapter, true);
6350 if ((BtState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6351 (BtState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6352 if (pBtCoex->bC2hBtInquiryPage) {
6353 btdm_1AntSetPSTDMA(padapter, false, 0,
6356 padapter->pwrctrlpriv.btcoex_rfon =
6358 btdm_1AntSetPSTDMA(padapter, true, 0,
6361 } else if (true == pBtCoex->bC2hBtInquiryPage) {
6362 padapter->pwrctrlpriv.btcoex_rfon = true;
6363 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
6364 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY) {
6365 padapter->pwrctrlpriv.btcoex_rfon = true;
6366 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6367 btdm_1AntSetPSTDMA(padapter, true, 0,
6370 btdm_1AntSetPSTDMA(padapter, true, 0,
6373 padapter->pwrctrlpriv.btcoex_rfon = true;
6374 btdm_1AntSetPSTDMA(padapter, true, 0, true, 5);
6378 btdm_NotifyFwScan(padapter, 1);
6380 /* WiFi_Finish_Scan */
6381 btdm_NotifyFwScan(padapter, 0);
6382 btdm_1AntBtCoexistHandler(padapter);
6386 static void BTDM_1AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
6388 struct hal_data_8723a *pHalData;
6389 struct bt_30info *pBTInfo;
6390 struct bt_mgnt *pBtMgnt;
6391 struct bt_coexist_8723a *pBtCoex;
6394 pHalData = GET_HAL_DATA(padapter);
6395 pBTInfo = GET_BT_INFO(padapter);
6396 pBtMgnt = &pBTInfo->BtMgnt;
6397 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6399 u1tmp = pBtCoex->c2hBtInfoOriginal;
6400 /* sco BUSY bit is not used on voice over PCM platform */
6401 btState = u1tmp & 0xF;
6402 pBtCoex->c2hBtProfile = u1tmp & 0xE0;
6404 /* default set bt to idle state. */
6405 pBtMgnt->ExtConfig.bBTBusy = false;
6406 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
6408 /* check BIT2 first ==> check if bt is under inquiry or page scan */
6409 if (btState & BIT(2))
6410 pBtCoex->bC2hBtInquiryPage = true;
6412 pBtCoex->bC2hBtInquiryPage = false;
6415 if (!(btState & BIT(0)))
6416 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
6419 pBtCoex->c2hBtInfo = BT_INFO_STATE_CONNECT_IDLE;
6420 else if (btState == 0x9) {
6421 if (pBtCoex->bC2hBtInquiryPage == true)
6422 pBtCoex->c2hBtInfo =
6423 BT_INFO_STATE_ACL_INQ_OR_PAG;
6425 pBtCoex->c2hBtInfo =
6426 BT_INFO_STATE_ACL_ONLY_BUSY;
6427 pBtMgnt->ExtConfig.bBTBusy = true;
6428 } else if (btState == 0x3) {
6429 pBtCoex->c2hBtInfo = BT_INFO_STATE_SCO_ONLY_BUSY;
6430 pBtMgnt->ExtConfig.bBTBusy = true;
6431 } else if (btState == 0xb) {
6432 pBtCoex->c2hBtInfo = BT_INFO_STATE_ACL_SCO_BUSY;
6433 pBtMgnt->ExtConfig.bBTBusy = true;
6435 pBtCoex->c2hBtInfo = BT_INFO_STATE_MAX;
6436 if (pBtMgnt->ExtConfig.bBTBusy)
6437 pHalData->bt_coexist.CurrentState &=
6438 ~BT_COEX_STATE_BT_IDLE;
6441 if (BT_INFO_STATE_NO_CONNECTION == pBtCoex->c2hBtInfo ||
6442 BT_INFO_STATE_CONNECT_IDLE == pBtCoex->c2hBtInfo) {
6443 if (pBtCoex->bC2hBtInquiryPage)
6444 pBtCoex->c2hBtInfo = BT_INFO_STATE_INQ_OR_PAG;
6447 RTPRINT(FBT, BT_TRACE, ("[BTC2H], %s(%d)\n",
6448 BtStateString[pBtCoex->c2hBtInfo], pBtCoex->c2hBtInfo));
6450 if (pBtCoex->c2hBtProfile != BT_INFO_HID)
6451 pBtCoex->c2hBtProfile &= ~BT_INFO_HID;
6454 void BTDM_1AntBtCoexist8723A(struct rtw_adapter *padapter)
6456 struct mlme_priv *pmlmepriv;
6457 struct hal_data_8723a *pHalData;
6458 unsigned long delta_time;
6460 pmlmepriv = &padapter->mlmepriv;
6461 pHalData = GET_HAL_DATA(padapter);
6463 if (check_fwstate(pmlmepriv, WIFI_SITE_MONITOR)) {
6464 /* already done in BTDM_1AntForScan() */
6465 RTPRINT(FBT, BT_TRACE,
6466 ("[BTCoex], wifi is under scan progress!!\n"));
6470 if (check_fwstate(pmlmepriv, WIFI_UNDER_LINKING)) {
6471 RTPRINT(FBT, BT_TRACE,
6472 ("[BTCoex], wifi is under link progress!!\n"));
6476 /* under DHCP(Special packet) */
6477 delta_time = jiffies - padapter->pwrctrlpriv.DelayLPSLastTimeStamp;
6478 delta_time = jiffies_to_msecs(delta_time);
6479 if (delta_time < 500) {
6480 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is under DHCP "
6481 "progress(%li ms)!!\n", delta_time));
6485 BTDM_CheckWiFiState(padapter);
6487 btdm_1AntBtCoexistHandler(padapter);
6490 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
6492 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
6494 /* local function start with btdm_ */
6495 static u8 btdm_ActionAlgorithm(struct rtw_adapter *padapter)
6497 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
6498 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
6499 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6500 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6501 u8 bScoExist = false, bBtLinkExist = false, bBtHsModeExist = false;
6502 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
6504 if (pBtMgnt->ExtConfig.NumberOfHandle)
6505 bBtLinkExist = true;
6506 if (pBtMgnt->ExtConfig.NumberOfSCO)
6508 if (BT_HsConnectionEstablished(padapter))
6509 bBtHsModeExist = true;
6511 /* here we get BT status first */
6513 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
6515 if ((bScoExist) || (bBtHsModeExist) ||
6516 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID))) {
6517 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO or HID or HS exists, set BT non-idle !!!\n"));
6518 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6521 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6522 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP))) {
6523 if (BTDM_BtTxRxCounterL(padapter) < 100) {
6524 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx < 100, set BT connected-idle!!!\n"));
6525 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6527 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx >= 100, set BT non-idle!!!\n"));
6528 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6532 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6533 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6534 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6535 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6536 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6538 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6539 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6540 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6541 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6542 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6546 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6547 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, set BT non-idle!!!\n"));
6548 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6551 /* Pan+A2dp profile */
6552 if ((pBtMgnt->ExtConfig.NumberOfHandle == 2) &&
6553 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) &&
6554 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6555 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6556 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6557 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6559 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6560 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6561 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6562 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6563 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6567 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6568 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, set BT non-idle!!!\n"));
6569 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6573 if (BT_2ANT_BT_STATUS_IDLE != pBtdm8723->btStatus)
6574 pBtMgnt->ExtConfig.bBTBusy = true;
6576 pBtMgnt->ExtConfig.bBTBusy = false;
6578 if (!bBtLinkExist) {
6579 RTPRINT(FBT, BT_TRACE, ("[BTCoex], No profile exists!!!\n"));
6583 if (pBtMgnt->ExtConfig.NumberOfHandle == 1) {
6585 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
6586 algorithm = BT_2ANT_COEX_ALGO_SCO;
6588 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6589 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID only\n"));
6590 algorithm = BT_2ANT_COEX_ALGO_HID;
6591 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6592 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP only\n"));
6593 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6594 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6595 if (bBtHsModeExist) {
6596 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(HS) only\n"));
6597 algorithm = BT_2ANT_COEX_ALGO_PANHS;
6599 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR) only\n"));
6600 algorithm = BT_2ANT_COEX_ALGO_PANEDR;
6603 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d \n",
6604 pBtMgnt->ExtConfig.NumberOfHandle));
6607 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 2) {
6609 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6610 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
6611 algorithm = BT_2ANT_COEX_ALGO_HID;
6612 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6613 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
6614 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6615 if (bBtHsModeExist) {
6616 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
6617 algorithm = BT_2ANT_COEX_ALGO_SCO;
6619 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
6620 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6623 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched ACL profile for NumberOfHandle =%d\n",
6624 pBtMgnt->ExtConfig.NumberOfHandle));
6627 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6628 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6629 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
6630 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6631 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6632 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6633 if (bBtHsModeExist) {
6634 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
6635 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6637 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
6638 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6640 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6641 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6642 if (bBtHsModeExist) {
6643 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
6644 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6646 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
6647 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
6650 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6651 pBtMgnt->ExtConfig.NumberOfHandle));
6654 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 3) {
6656 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6657 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6658 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP\n"));
6659 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6660 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6661 if (bBtHsModeExist) {
6662 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));
6663 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6665 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));
6666 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6668 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6669 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6670 if (bBtHsModeExist) {
6671 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(HS)\n"));
6672 algorithm = BT_2ANT_COEX_ALGO_SCO;
6674 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(EDR)\n"));
6677 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6678 pBtMgnt->ExtConfig.NumberOfHandle));
6681 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6682 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6683 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6684 if (bBtHsModeExist) {
6685 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
6686 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANHS;
6688 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
6689 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
6692 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6693 pBtMgnt->ExtConfig.NumberOfHandle));
6696 } else if (pBtMgnt->ExtConfig.NumberOfHandle >= 3) {
6698 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6699 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6700 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6702 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
6704 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(EDR)\n"));
6706 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6707 pBtMgnt->ExtConfig.NumberOfHandle));
6710 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6711 pBtMgnt->ExtConfig.NumberOfHandle));
6717 static u8 btdm_NeedToDecBtPwr(struct rtw_adapter *padapter)
6719 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6722 if (BT_Operation(padapter)) {
6723 if (pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB > 47) {
6724 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for HS mode!!\n"));
6727 RTPRINT(FBT, BT_TRACE, ("NO Need to decrease bt power for HS mode!!\n"));
6730 if (BTDM_IsWifiConnectionExist(padapter)) {
6731 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for Wifi is connected!!\n"));
6739 btdm_SetCoexTable(struct rtw_adapter *padapter, u32 val0x6c0,
6740 u32 val0x6c8, u8 val0x6cc)
6742 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c0 = 0x%x\n", val0x6c0));
6743 rtl8723au_write32(padapter, 0x6c0, val0x6c0);
6745 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c8 = 0x%x\n", val0x6c8));
6746 rtl8723au_write32(padapter, 0x6c8, val0x6c8);
6748 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6cc = 0x%x\n", val0x6cc));
6749 rtl8723au_write8(padapter, 0x6cc, val0x6cc);
6753 btdm_SetSwFullTimeDacSwing(struct rtw_adapter *padapter, u8 bSwDacSwingOn,
6756 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6758 if (bSwDacSwingOn) {
6759 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing = 0x%x\n", swDacSwingLvl));
6760 PHY_SetBBReg(padapter, 0x880, 0xff000000, swDacSwingLvl);
6761 pHalData->bt_coexist.bSWCoexistAllOff = false;
6763 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing Off!\n"));
6764 PHY_SetBBReg(padapter, 0x880, 0xff000000, 0xc0);
6769 btdm_SetFwDacSwingLevel(struct rtw_adapter *padapter, u8 dacSwingLvl)
6771 u8 H2C_Parameter[1] = {0};
6773 H2C_Parameter[0] = dacSwingLvl;
6775 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Set Dac Swing Level = 0x%x\n", dacSwingLvl));
6776 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write 0x29 = 0x%x\n", H2C_Parameter[0]));
6778 FillH2CCmd(padapter, 0x29, 1, H2C_Parameter);
6781 static void btdm_2AntDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
6783 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6784 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6786 RTPRINT(FBT, BT_TRACE,
6787 ("[BTCoex], Dec BT power = %s\n",
6788 ((bDecBtPwr) ? "ON" : "OFF")));
6789 pBtdm8723->bCurDecBtPwr = bDecBtPwr;
6791 if (pBtdm8723->bPreDecBtPwr == pBtdm8723->bCurDecBtPwr)
6794 BTDM_SetFwDecBtPwr(padapter, pBtdm8723->bCurDecBtPwr);
6796 pBtdm8723->bPreDecBtPwr = pBtdm8723->bCurDecBtPwr;
6800 btdm_2AntFwDacSwingLvl(struct rtw_adapter *padapter, u8 fwDacSwingLvl)
6802 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6803 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6805 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW Dac Swing level = %d\n", fwDacSwingLvl));
6806 pBtdm8723->curFwDacSwingLvl = fwDacSwingLvl;
6808 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preFwDacSwingLvl =%d, curFwDacSwingLvl =%d\n", */
6809 /*pBtdm8723->preFwDacSwingLvl, pBtdm8723->curFwDacSwingLvl)); */
6811 if (pBtdm8723->preFwDacSwingLvl == pBtdm8723->curFwDacSwingLvl)
6814 btdm_SetFwDacSwingLevel(padapter, pBtdm8723->curFwDacSwingLvl);
6816 pBtdm8723->preFwDacSwingLvl = pBtdm8723->curFwDacSwingLvl;
6820 btdm_2AntRfShrink(struct rtw_adapter *padapter, u8 bRxRfShrinkOn)
6822 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6823 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6825 RTPRINT(FBT, BT_TRACE,
6826 ("[BTCoex], turn Rx RF Shrink = %s\n",
6827 ((bRxRfShrinkOn) ? "ON" : "OFF")));
6828 pBtdm8723->bCurRfRxLpfShrink = bRxRfShrinkOn;
6830 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreRfRxLpfShrink =%d, bCurRfRxLpfShrink =%d\n", */
6831 /*pBtdm8723->bPreRfRxLpfShrink, pBtdm8723->bCurRfRxLpfShrink)); */
6833 if (pBtdm8723->bPreRfRxLpfShrink == pBtdm8723->bCurRfRxLpfShrink)
6836 BTDM_SetSwRfRxLpfCorner(padapter, (u8)pBtdm8723->bCurRfRxLpfShrink);
6838 pBtdm8723->bPreRfRxLpfShrink = pBtdm8723->bCurRfRxLpfShrink;
6842 btdm_2AntLowPenaltyRa(struct rtw_adapter *padapter, u8 bLowPenaltyRa)
6844 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6845 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6847 RTPRINT(FBT, BT_TRACE,
6848 ("[BTCoex], turn LowPenaltyRA = %s\n",
6849 ((bLowPenaltyRa) ? "ON" : "OFF")));
6850 pBtdm8723->bCurLowPenaltyRa = bLowPenaltyRa;
6852 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreLowPenaltyRa =%d, bCurLowPenaltyRa =%d\n", */
6853 /*pBtdm8723->bPreLowPenaltyRa, pBtdm8723->bCurLowPenaltyRa)); */
6855 if (pBtdm8723->bPreLowPenaltyRa == pBtdm8723->bCurLowPenaltyRa)
6858 BTDM_SetSwPenaltyTxRateAdaptive(padapter, (u8)pBtdm8723->bCurLowPenaltyRa);
6860 pBtdm8723->bPreLowPenaltyRa = pBtdm8723->bCurLowPenaltyRa;
6864 btdm_2AntDacSwing(struct rtw_adapter *padapter,
6865 u8 bDacSwingOn, u32 dacSwingLvl)
6867 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6868 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6870 RTPRINT(FBT, BT_TRACE,
6871 ("[BTCoex], turn DacSwing =%s, dacSwingLvl = 0x%x\n",
6872 (bDacSwingOn ? "ON" : "OFF"), dacSwingLvl));
6873 pBtdm8723->bCurDacSwingOn = bDacSwingOn;
6874 pBtdm8723->curDacSwingLvl = dacSwingLvl;
6876 if ((pBtdm8723->bPreDacSwingOn == pBtdm8723->bCurDacSwingOn) &&
6877 (pBtdm8723->preDacSwingLvl == pBtdm8723->curDacSwingLvl))
6881 btdm_SetSwFullTimeDacSwing(padapter, bDacSwingOn, dacSwingLvl);
6883 pBtdm8723->bPreDacSwingOn = pBtdm8723->bCurDacSwingOn;
6884 pBtdm8723->preDacSwingLvl = pBtdm8723->curDacSwingLvl;
6887 static void btdm_2AntAdcBackOff(struct rtw_adapter *padapter, u8 bAdcBackOff)
6889 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6890 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6892 RTPRINT(FBT, BT_TRACE,
6893 ("[BTCoex], turn AdcBackOff = %s\n",
6894 ((bAdcBackOff) ? "ON" : "OFF")));
6895 pBtdm8723->bCurAdcBackOff = bAdcBackOff;
6897 if (pBtdm8723->bPreAdcBackOff == pBtdm8723->bCurAdcBackOff)
6900 BTDM_BBBackOffLevel(padapter, (u8)pBtdm8723->bCurAdcBackOff);
6902 pBtdm8723->bPreAdcBackOff = pBtdm8723->bCurAdcBackOff;
6905 static void btdm_2AntAgcTable(struct rtw_adapter *padapter, u8 bAgcTableEn)
6907 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6908 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6910 RTPRINT(FBT, BT_TRACE,
6911 ("[BTCoex], %s Agc Table\n", ((bAgcTableEn) ? "Enable" : "Disable")));
6912 pBtdm8723->bCurAgcTableEn = bAgcTableEn;
6914 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreAgcTableEn =%d, bCurAgcTableEn =%d\n", */
6915 /*pBtdm8723->bPreAgcTableEn, pBtdm8723->bCurAgcTableEn)); */
6917 if (pBtdm8723->bPreAgcTableEn == pBtdm8723->bCurAgcTableEn)
6920 BTDM_AGCTable(padapter, (u8)bAgcTableEn);
6922 pBtdm8723->bPreAgcTableEn = pBtdm8723->bCurAgcTableEn;
6926 btdm_2AntCoexTable(struct rtw_adapter *padapter,
6927 u32 val0x6c0, u32 val0x6c8, u8 val0x6cc)
6929 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6930 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6932 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write Coex Table 0x6c0 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
6933 val0x6c0, val0x6c8, val0x6cc));
6934 pBtdm8723->curVal0x6c0 = val0x6c0;
6935 pBtdm8723->curVal0x6c8 = val0x6c8;
6936 pBtdm8723->curVal0x6cc = val0x6cc;
6938 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n", */
6939 /*pBtdm8723->preVal0x6c0, pBtdm8723->preVal0x6c8, pBtdm8723->preVal0x6cc)); */
6940 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n", */
6941 /*pBtdm8723->curVal0x6c0, pBtdm8723->curVal0x6c8, pBtdm8723->curVal0x6cc)); */
6943 if ((pBtdm8723->preVal0x6c0 == pBtdm8723->curVal0x6c0) &&
6944 (pBtdm8723->preVal0x6c8 == pBtdm8723->curVal0x6c8) &&
6945 (pBtdm8723->preVal0x6cc == pBtdm8723->curVal0x6cc))
6948 btdm_SetCoexTable(padapter, val0x6c0, val0x6c8, val0x6cc);
6950 pBtdm8723->preVal0x6c0 = pBtdm8723->curVal0x6c0;
6951 pBtdm8723->preVal0x6c8 = pBtdm8723->curVal0x6c8;
6952 pBtdm8723->preVal0x6cc = pBtdm8723->curVal0x6cc;
6955 static void btdm_2AntIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
6957 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6958 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6960 RTPRINT(FBT, BT_TRACE,
6961 ("[BTCoex], turn Ignore WlanAct %s\n", (bEnable ? "ON" : "OFF")));
6962 pBtdm8723->bCurIgnoreWlanAct = bEnable;
6965 if (pBtdm8723->bPreIgnoreWlanAct == pBtdm8723->bCurIgnoreWlanAct)
6968 btdm_SetFwIgnoreWlanAct(padapter, bEnable);
6969 pBtdm8723->bPreIgnoreWlanAct = pBtdm8723->bCurIgnoreWlanAct;
6973 btdm_2AntSetFw3a(struct rtw_adapter *padapter, u8 byte1, u8 byte2,
6974 u8 byte3, u8 byte4, u8 byte5)
6976 u8 H2C_Parameter[5] = {0};
6978 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6980 /* byte1[1:0] != 0 means enable pstdma */
6981 /* for 2Ant bt coexist, if byte1 != 0 means enable pstdma */
6983 pHalData->bt_coexist.bFWCoexistAllOff = false;
6984 H2C_Parameter[0] = byte1;
6985 H2C_Parameter[1] = byte2;
6986 H2C_Parameter[2] = byte3;
6987 H2C_Parameter[3] = byte4;
6988 H2C_Parameter[4] = byte5;
6990 pHalData->bt_coexist.fw3aVal[0] = byte1;
6991 pHalData->bt_coexist.fw3aVal[1] = byte2;
6992 pHalData->bt_coexist.fw3aVal[2] = byte3;
6993 pHalData->bt_coexist.fw3aVal[3] = byte4;
6994 pHalData->bt_coexist.fw3aVal[4] = byte5;
6996 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%x%08x\n",
6998 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
7000 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
7003 static void btdm_2AntPsTdma(struct rtw_adapter *padapter, u8 bTurnOn, u8 type)
7005 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7006 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7008 u8 bTurnOnByCnt = false;
7009 u8 psTdmaTypeByCnt = 0;
7011 btTxRxCnt = BTDM_BtTxRxCounterH(padapter)+BTDM_BtTxRxCounterL(padapter);
7012 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT TxRx Counters = %d\n", btTxRxCnt));
7013 if (btTxRxCnt > 3000) {
7014 bTurnOnByCnt = true;
7015 psTdmaTypeByCnt = 8;
7017 RTPRINT(FBT, BT_TRACE,
7018 ("[BTCoex], For BTTxRxCounters, turn %s PS TDMA, type =%d\n",
7019 (bTurnOnByCnt ? "ON" : "OFF"), psTdmaTypeByCnt));
7020 pBtdm8723->bCurPsTdmaOn = bTurnOnByCnt;
7021 pBtdm8723->curPsTdma = psTdmaTypeByCnt;
7023 RTPRINT(FBT, BT_TRACE,
7024 ("[BTCoex], turn %s PS TDMA, type =%d\n",
7025 (bTurnOn ? "ON" : "OFF"), type));
7026 pBtdm8723->bCurPsTdmaOn = bTurnOn;
7027 pBtdm8723->curPsTdma = type;
7030 if ((pBtdm8723->bPrePsTdmaOn == pBtdm8723->bCurPsTdmaOn) &&
7031 (pBtdm8723->prePsTdma == pBtdm8723->curPsTdma))
7038 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
7041 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
7044 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
7047 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0xa1, 0x80);
7050 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7053 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7056 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7059 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0x20, 0x80);
7062 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
7065 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
7068 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
7071 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7074 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7077 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7080 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7083 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0x20, 0x98);
7086 btdm_2AntSetFw3a(padapter, 0xa3, 0x2f, 0x2f, 0x20, 0x80);
7089 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7092 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0xa1, 0x98);
7095 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0x20, 0x98);
7099 /* disable PS tdma */
7102 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7105 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x0, 0x0);
7108 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7113 /* update pre state */
7114 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
7115 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
7118 static void btdm_2AntBtInquiryPage(struct rtw_adapter *padapter)
7120 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7121 btdm_2AntIgnoreWlanAct(padapter, false);
7122 btdm_2AntPsTdma(padapter, true, 8);
7125 static u8 btdm_HoldForBtInqPage(struct rtw_adapter *padapter)
7127 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7128 u32 curTime = jiffies;
7130 if (pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
7131 /* bt inquiry or page is started. */
7132 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime == 0) {
7133 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = curTime;
7134 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page is started at time : 0x%lx \n",
7135 pHalData->bt_coexist.halCoex8723.btInqPageStartTime));
7138 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page started time : 0x%lx, curTime : 0x%x \n",
7139 pHalData->bt_coexist.halCoex8723.btInqPageStartTime, curTime));
7141 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7142 if (((curTime - pHalData->bt_coexist.halCoex8723.btInqPageStartTime)/1000000) >= 10) {
7143 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page >= 10sec!!!"));
7144 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = 0;
7148 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7149 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7150 btdm_2AntIgnoreWlanAct(padapter, false);
7151 btdm_2AntPsTdma(padapter, true, 8);
7158 static u8 btdm_Is2Ant8723ACommonAction(struct rtw_adapter *padapter)
7160 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7161 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7164 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));
7166 if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7167 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7168 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7169 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt idle!!\n"));
7171 btdm_2AntLowPenaltyRa(padapter, false);
7172 btdm_2AntRfShrink(padapter, false);
7173 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7175 btdm_2AntIgnoreWlanAct(padapter, false);
7176 btdm_2AntPsTdma(padapter, false, 0);
7177 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7178 btdm_2AntDecBtPwr(padapter, false);
7180 btdm_2AntAgcTable(padapter, false);
7181 btdm_2AntAdcBackOff(padapter, false);
7182 btdm_2AntDacSwing(padapter, false, 0xc0);
7185 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7186 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7187 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7188 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT idle!!\n"));
7190 btdm_2AntLowPenaltyRa(padapter, true);
7191 btdm_2AntRfShrink(padapter, false);
7192 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7194 btdm_2AntIgnoreWlanAct(padapter, false);
7195 btdm_2AntPsTdma(padapter, false, 0);
7196 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7197 btdm_2AntDecBtPwr(padapter, true);
7199 btdm_2AntAgcTable(padapter, false);
7200 btdm_2AntAdcBackOff(padapter, false);
7201 btdm_2AntDacSwing(padapter, false, 0xc0);
7204 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7205 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7206 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7207 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt connected idle!!\n"));
7209 btdm_2AntLowPenaltyRa(padapter, true);
7210 btdm_2AntRfShrink(padapter, true);
7211 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7213 btdm_2AntIgnoreWlanAct(padapter, false);
7214 btdm_2AntPsTdma(padapter, false, 0);
7215 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7216 btdm_2AntDecBtPwr(padapter, false);
7218 btdm_2AntAgcTable(padapter, false);
7219 btdm_2AntAdcBackOff(padapter, false);
7220 btdm_2AntDacSwing(padapter, false, 0xc0);
7223 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7224 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7225 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7226 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + Bt connected idle!!\n"));
7228 btdm_2AntLowPenaltyRa(padapter, true);
7229 btdm_2AntRfShrink(padapter, true);
7230 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7232 btdm_2AntIgnoreWlanAct(padapter, false);
7233 btdm_2AntPsTdma(padapter, false, 0);
7234 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7235 btdm_2AntDecBtPwr(padapter, true);
7237 btdm_2AntAgcTable(padapter, false);
7238 btdm_2AntAdcBackOff(padapter, false);
7239 btdm_2AntDacSwing(padapter, false, 0xc0);
7242 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7243 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7244 (BT_2ANT_BT_STATUS_NON_IDLE == pBtdm8723->btStatus)) {
7245 RTPRINT(FBT, BT_TRACE, ("Wifi idle + BT non-idle!!\n"));
7247 btdm_2AntLowPenaltyRa(padapter, true);
7248 btdm_2AntRfShrink(padapter, true);
7249 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7251 btdm_2AntIgnoreWlanAct(padapter, false);
7252 btdm_2AntPsTdma(padapter, false, 0);
7253 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7254 btdm_2AntDecBtPwr(padapter, false);
7256 btdm_2AntAgcTable(padapter, false);
7257 btdm_2AntAdcBackOff(padapter, false);
7258 btdm_2AntDacSwing(padapter, false, 0xc0);
7262 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT non-idle!!\n"));
7263 btdm_2AntLowPenaltyRa(padapter, true);
7264 btdm_2AntRfShrink(padapter, true);
7265 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7266 btdm_2AntIgnoreWlanAct(padapter, false);
7267 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7275 btdm_2AntTdmaDurationAdjust(struct rtw_adapter *padapter, u8 bScoHid,
7276 u8 bTxPause, u8 maxInterval)
7278 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7279 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7280 static s32 up, dn, m, n, WaitCount;
7281 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
7284 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));
7286 if (pBtdm8723->bResetTdmaAdjust) {
7287 pBtdm8723->bResetTdmaAdjust = false;
7288 RTPRINT(FBT, BT_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
7291 if (maxInterval == 1) {
7292 btdm_2AntPsTdma(padapter, true, 15);
7293 pBtdm8723->psTdmaDuAdjType = 15;
7294 } else if (maxInterval == 2) {
7295 btdm_2AntPsTdma(padapter, true, 15);
7296 pBtdm8723->psTdmaDuAdjType = 15;
7297 } else if (maxInterval == 3) {
7298 btdm_2AntPsTdma(padapter, true, 15);
7299 pBtdm8723->psTdmaDuAdjType = 15;
7301 btdm_2AntPsTdma(padapter, true, 15);
7302 pBtdm8723->psTdmaDuAdjType = 15;
7305 if (maxInterval == 1) {
7306 btdm_2AntPsTdma(padapter, true, 11);
7307 pBtdm8723->psTdmaDuAdjType = 11;
7308 } else if (maxInterval == 2) {
7309 btdm_2AntPsTdma(padapter, true, 11);
7310 pBtdm8723->psTdmaDuAdjType = 11;
7311 } else if (maxInterval == 3) {
7312 btdm_2AntPsTdma(padapter, true, 11);
7313 pBtdm8723->psTdmaDuAdjType = 11;
7315 btdm_2AntPsTdma(padapter, true, 11);
7316 pBtdm8723->psTdmaDuAdjType = 11;
7321 if (maxInterval == 1) {
7322 btdm_2AntPsTdma(padapter, true, 7);
7323 pBtdm8723->psTdmaDuAdjType = 7;
7324 } else if (maxInterval == 2) {
7325 btdm_2AntPsTdma(padapter, true, 7);
7326 pBtdm8723->psTdmaDuAdjType = 7;
7327 } else if (maxInterval == 3) {
7328 btdm_2AntPsTdma(padapter, true, 7);
7329 pBtdm8723->psTdmaDuAdjType = 7;
7331 btdm_2AntPsTdma(padapter, true, 7);
7332 pBtdm8723->psTdmaDuAdjType = 7;
7335 if (maxInterval == 1) {
7336 btdm_2AntPsTdma(padapter, true, 3);
7337 pBtdm8723->psTdmaDuAdjType = 3;
7338 } else if (maxInterval == 2) {
7339 btdm_2AntPsTdma(padapter, true, 3);
7340 pBtdm8723->psTdmaDuAdjType = 3;
7341 } else if (maxInterval == 3) {
7342 btdm_2AntPsTdma(padapter, true, 3);
7343 pBtdm8723->psTdmaDuAdjType = 3;
7345 btdm_2AntPsTdma(padapter, true, 3);
7346 pBtdm8723->psTdmaDuAdjType = 3;
7357 /* accquire the BT TRx retry count from BT_Info byte2 */
7358 retryCount = pHalData->bt_coexist.halCoex8723.btRetryCnt;
7359 RTPRINT(FBT, BT_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));
7363 if (retryCount == 0) { /* no retry in the last 2-second duration */
7370 if (up >= n) { /* if ³sÄò n Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */
7376 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
7378 } else if (retryCount <= 3) { /* <= 3 retry in the last 2-second duration */
7385 if (dn == 2) { /* if ³sÄò 2 Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */
7387 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7391 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7399 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
7401 } else { /* retry count > 3, ¥un1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */
7403 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7407 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7414 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
7417 RTPRINT(FBT, BT_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));
7418 if (maxInterval == 1) {
7420 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7421 if (pBtdm8723->curPsTdma == 1) {
7422 btdm_2AntPsTdma(padapter, true, 5);
7423 pBtdm8723->psTdmaDuAdjType = 5;
7424 } else if (pBtdm8723->curPsTdma == 2) {
7425 btdm_2AntPsTdma(padapter, true, 6);
7426 pBtdm8723->psTdmaDuAdjType = 6;
7427 } else if (pBtdm8723->curPsTdma == 3) {
7428 btdm_2AntPsTdma(padapter, true, 7);
7429 pBtdm8723->psTdmaDuAdjType = 7;
7430 } else if (pBtdm8723->curPsTdma == 4) {
7431 btdm_2AntPsTdma(padapter, true, 8);
7432 pBtdm8723->psTdmaDuAdjType = 8;
7434 if (pBtdm8723->curPsTdma == 9) {
7435 btdm_2AntPsTdma(padapter, true, 13);
7436 pBtdm8723->psTdmaDuAdjType = 13;
7437 } else if (pBtdm8723->curPsTdma == 10) {
7438 btdm_2AntPsTdma(padapter, true, 14);
7439 pBtdm8723->psTdmaDuAdjType = 14;
7440 } else if (pBtdm8723->curPsTdma == 11) {
7441 btdm_2AntPsTdma(padapter, true, 15);
7442 pBtdm8723->psTdmaDuAdjType = 15;
7443 } else if (pBtdm8723->curPsTdma == 12) {
7444 btdm_2AntPsTdma(padapter, true, 16);
7445 pBtdm8723->psTdmaDuAdjType = 16;
7449 if (pBtdm8723->curPsTdma == 5) {
7450 btdm_2AntPsTdma(padapter, true, 6);
7451 pBtdm8723->psTdmaDuAdjType = 6;
7452 } else if (pBtdm8723->curPsTdma == 6) {
7453 btdm_2AntPsTdma(padapter, true, 7);
7454 pBtdm8723->psTdmaDuAdjType = 7;
7455 } else if (pBtdm8723->curPsTdma == 7) {
7456 btdm_2AntPsTdma(padapter, true, 8);
7457 pBtdm8723->psTdmaDuAdjType = 8;
7458 } else if (pBtdm8723->curPsTdma == 13) {
7459 btdm_2AntPsTdma(padapter, true, 14);
7460 pBtdm8723->psTdmaDuAdjType = 14;
7461 } else if (pBtdm8723->curPsTdma == 14) {
7462 btdm_2AntPsTdma(padapter, true, 15);
7463 pBtdm8723->psTdmaDuAdjType = 15;
7464 } else if (pBtdm8723->curPsTdma == 15) {
7465 btdm_2AntPsTdma(padapter, true, 16);
7466 pBtdm8723->psTdmaDuAdjType = 16;
7468 } else if (result == 1) {
7469 if (pBtdm8723->curPsTdma == 8) {
7470 btdm_2AntPsTdma(padapter, true, 7);
7471 pBtdm8723->psTdmaDuAdjType = 7;
7472 } else if (pBtdm8723->curPsTdma == 7) {
7473 btdm_2AntPsTdma(padapter, true, 6);
7474 pBtdm8723->psTdmaDuAdjType = 6;
7475 } else if (pBtdm8723->curPsTdma == 6) {
7476 btdm_2AntPsTdma(padapter, true, 5);
7477 pBtdm8723->psTdmaDuAdjType = 5;
7478 } else if (pBtdm8723->curPsTdma == 16) {
7479 btdm_2AntPsTdma(padapter, true, 15);
7480 pBtdm8723->psTdmaDuAdjType = 15;
7481 } else if (pBtdm8723->curPsTdma == 15) {
7482 btdm_2AntPsTdma(padapter, true, 14);
7483 pBtdm8723->psTdmaDuAdjType = 14;
7484 } else if (pBtdm8723->curPsTdma == 14) {
7485 btdm_2AntPsTdma(padapter, true, 13);
7486 pBtdm8723->psTdmaDuAdjType = 13;
7490 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7491 if (pBtdm8723->curPsTdma == 5) {
7492 btdm_2AntPsTdma(padapter, true, 1);
7493 pBtdm8723->psTdmaDuAdjType = 1;
7494 } else if (pBtdm8723->curPsTdma == 6) {
7495 btdm_2AntPsTdma(padapter, true, 2);
7496 pBtdm8723->psTdmaDuAdjType = 2;
7497 } else if (pBtdm8723->curPsTdma == 7) {
7498 btdm_2AntPsTdma(padapter, true, 3);
7499 pBtdm8723->psTdmaDuAdjType = 3;
7500 } else if (pBtdm8723->curPsTdma == 8) {
7501 btdm_2AntPsTdma(padapter, true, 4);
7502 pBtdm8723->psTdmaDuAdjType = 4;
7504 if (pBtdm8723->curPsTdma == 13) {
7505 btdm_2AntPsTdma(padapter, true, 9);
7506 pBtdm8723->psTdmaDuAdjType = 9;
7507 } else if (pBtdm8723->curPsTdma == 14) {
7508 btdm_2AntPsTdma(padapter, true, 10);
7509 pBtdm8723->psTdmaDuAdjType = 10;
7510 } else if (pBtdm8723->curPsTdma == 15) {
7511 btdm_2AntPsTdma(padapter, true, 11);
7512 pBtdm8723->psTdmaDuAdjType = 11;
7513 } else if (pBtdm8723->curPsTdma == 16) {
7514 btdm_2AntPsTdma(padapter, true, 12);
7515 pBtdm8723->psTdmaDuAdjType = 12;
7519 if (pBtdm8723->curPsTdma == 1) {
7520 btdm_2AntPsTdma(padapter, true, 2);
7521 pBtdm8723->psTdmaDuAdjType = 2;
7522 } else if (pBtdm8723->curPsTdma == 2) {
7523 btdm_2AntPsTdma(padapter, true, 3);
7524 pBtdm8723->psTdmaDuAdjType = 3;
7525 } else if (pBtdm8723->curPsTdma == 3) {
7526 btdm_2AntPsTdma(padapter, true, 4);
7527 pBtdm8723->psTdmaDuAdjType = 4;
7528 } else if (pBtdm8723->curPsTdma == 9) {
7529 btdm_2AntPsTdma(padapter, true, 10);
7530 pBtdm8723->psTdmaDuAdjType = 10;
7531 } else if (pBtdm8723->curPsTdma == 10) {
7532 btdm_2AntPsTdma(padapter, true, 11);
7533 pBtdm8723->psTdmaDuAdjType = 11;
7534 } else if (pBtdm8723->curPsTdma == 11) {
7535 btdm_2AntPsTdma(padapter, true, 12);
7536 pBtdm8723->psTdmaDuAdjType = 12;
7538 } else if (result == 1) {
7539 if (pBtdm8723->curPsTdma == 4) {
7540 btdm_2AntPsTdma(padapter, true, 3);
7541 pBtdm8723->psTdmaDuAdjType = 3;
7542 } else if (pBtdm8723->curPsTdma == 3) {
7543 btdm_2AntPsTdma(padapter, true, 2);
7544 pBtdm8723->psTdmaDuAdjType = 2;
7545 } else if (pBtdm8723->curPsTdma == 2) {
7546 btdm_2AntPsTdma(padapter, true, 1);
7547 pBtdm8723->psTdmaDuAdjType = 1;
7548 } else if (pBtdm8723->curPsTdma == 12) {
7549 btdm_2AntPsTdma(padapter, true, 11);
7550 pBtdm8723->psTdmaDuAdjType = 11;
7551 } else if (pBtdm8723->curPsTdma == 11) {
7552 btdm_2AntPsTdma(padapter, true, 10);
7553 pBtdm8723->psTdmaDuAdjType = 10;
7554 } else if (pBtdm8723->curPsTdma == 10) {
7555 btdm_2AntPsTdma(padapter, true, 9);
7556 pBtdm8723->psTdmaDuAdjType = 9;
7560 } else if (maxInterval == 2) {
7562 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7563 if (pBtdm8723->curPsTdma == 1) {
7564 btdm_2AntPsTdma(padapter, true, 6);
7565 pBtdm8723->psTdmaDuAdjType = 6;
7566 } else if (pBtdm8723->curPsTdma == 2) {
7567 btdm_2AntPsTdma(padapter, true, 6);
7568 pBtdm8723->psTdmaDuAdjType = 6;
7569 } else if (pBtdm8723->curPsTdma == 3) {
7570 btdm_2AntPsTdma(padapter, true, 7);
7571 pBtdm8723->psTdmaDuAdjType = 7;
7572 } else if (pBtdm8723->curPsTdma == 4) {
7573 btdm_2AntPsTdma(padapter, true, 8);
7574 pBtdm8723->psTdmaDuAdjType = 8;
7576 if (pBtdm8723->curPsTdma == 9) {
7577 btdm_2AntPsTdma(padapter, true, 14);
7578 pBtdm8723->psTdmaDuAdjType = 14;
7579 } else if (pBtdm8723->curPsTdma == 10) {
7580 btdm_2AntPsTdma(padapter, true, 14);
7581 pBtdm8723->psTdmaDuAdjType = 14;
7582 } else if (pBtdm8723->curPsTdma == 11) {
7583 btdm_2AntPsTdma(padapter, true, 15);
7584 pBtdm8723->psTdmaDuAdjType = 15;
7585 } else if (pBtdm8723->curPsTdma == 12) {
7586 btdm_2AntPsTdma(padapter, true, 16);
7587 pBtdm8723->psTdmaDuAdjType = 16;
7590 if (pBtdm8723->curPsTdma == 5) {
7591 btdm_2AntPsTdma(padapter, true, 6);
7592 pBtdm8723->psTdmaDuAdjType = 6;
7593 } else if (pBtdm8723->curPsTdma == 6) {
7594 btdm_2AntPsTdma(padapter, true, 7);
7595 pBtdm8723->psTdmaDuAdjType = 7;
7596 } else if (pBtdm8723->curPsTdma == 7) {
7597 btdm_2AntPsTdma(padapter, true, 8);
7598 pBtdm8723->psTdmaDuAdjType = 8;
7599 } else if (pBtdm8723->curPsTdma == 13) {
7600 btdm_2AntPsTdma(padapter, true, 14);
7601 pBtdm8723->psTdmaDuAdjType = 14;
7602 } else if (pBtdm8723->curPsTdma == 14) {
7603 btdm_2AntPsTdma(padapter, true, 15);
7604 pBtdm8723->psTdmaDuAdjType = 15;
7605 } else if (pBtdm8723->curPsTdma == 15) {
7606 btdm_2AntPsTdma(padapter, true, 16);
7607 pBtdm8723->psTdmaDuAdjType = 16;
7609 } else if (result == 1) {
7610 if (pBtdm8723->curPsTdma == 8) {
7611 btdm_2AntPsTdma(padapter, true, 7);
7612 pBtdm8723->psTdmaDuAdjType = 7;
7613 } else if (pBtdm8723->curPsTdma == 7) {
7614 btdm_2AntPsTdma(padapter, true, 6);
7615 pBtdm8723->psTdmaDuAdjType = 6;
7616 } else if (pBtdm8723->curPsTdma == 6) {
7617 btdm_2AntPsTdma(padapter, true, 6);
7618 pBtdm8723->psTdmaDuAdjType = 6;
7619 } else if (pBtdm8723->curPsTdma == 16) {
7620 btdm_2AntPsTdma(padapter, true, 15);
7621 pBtdm8723->psTdmaDuAdjType = 15;
7622 } else if (pBtdm8723->curPsTdma == 15) {
7623 btdm_2AntPsTdma(padapter, true, 14);
7624 pBtdm8723->psTdmaDuAdjType = 14;
7625 } else if (pBtdm8723->curPsTdma == 14) {
7626 btdm_2AntPsTdma(padapter, true, 14);
7627 pBtdm8723->psTdmaDuAdjType = 14;
7631 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7632 if (pBtdm8723->curPsTdma == 5) {
7633 btdm_2AntPsTdma(padapter, true, 2);
7634 pBtdm8723->psTdmaDuAdjType = 2;
7635 } else if (pBtdm8723->curPsTdma == 6) {
7636 btdm_2AntPsTdma(padapter, true, 2);
7637 pBtdm8723->psTdmaDuAdjType = 2;
7638 } else if (pBtdm8723->curPsTdma == 7) {
7639 btdm_2AntPsTdma(padapter, true, 3);
7640 pBtdm8723->psTdmaDuAdjType = 3;
7641 } else if (pBtdm8723->curPsTdma == 8) {
7642 btdm_2AntPsTdma(padapter, true, 4);
7643 pBtdm8723->psTdmaDuAdjType = 4;
7645 if (pBtdm8723->curPsTdma == 13) {
7646 btdm_2AntPsTdma(padapter, true, 10);
7647 pBtdm8723->psTdmaDuAdjType = 10;
7648 } else if (pBtdm8723->curPsTdma == 14) {
7649 btdm_2AntPsTdma(padapter, true, 10);
7650 pBtdm8723->psTdmaDuAdjType = 10;
7651 } else if (pBtdm8723->curPsTdma == 15) {
7652 btdm_2AntPsTdma(padapter, true, 11);
7653 pBtdm8723->psTdmaDuAdjType = 11;
7654 } else if (pBtdm8723->curPsTdma == 16) {
7655 btdm_2AntPsTdma(padapter, true, 12);
7656 pBtdm8723->psTdmaDuAdjType = 12;
7659 if (pBtdm8723->curPsTdma == 1) {
7660 btdm_2AntPsTdma(padapter, true, 2);
7661 pBtdm8723->psTdmaDuAdjType = 2;
7662 } else if (pBtdm8723->curPsTdma == 2) {
7663 btdm_2AntPsTdma(padapter, true, 3);
7664 pBtdm8723->psTdmaDuAdjType = 3;
7665 } else if (pBtdm8723->curPsTdma == 3) {
7666 btdm_2AntPsTdma(padapter, true, 4);
7667 pBtdm8723->psTdmaDuAdjType = 4;
7668 } else if (pBtdm8723->curPsTdma == 9) {
7669 btdm_2AntPsTdma(padapter, true, 10);
7670 pBtdm8723->psTdmaDuAdjType = 10;
7671 } else if (pBtdm8723->curPsTdma == 10) {
7672 btdm_2AntPsTdma(padapter, true, 11);
7673 pBtdm8723->psTdmaDuAdjType = 11;
7674 } else if (pBtdm8723->curPsTdma == 11) {
7675 btdm_2AntPsTdma(padapter, true, 12);
7676 pBtdm8723->psTdmaDuAdjType = 12;
7678 } else if (result == 1) {
7679 if (pBtdm8723->curPsTdma == 4) {
7680 btdm_2AntPsTdma(padapter, true, 3);
7681 pBtdm8723->psTdmaDuAdjType = 3;
7682 } else if (pBtdm8723->curPsTdma == 3) {
7683 btdm_2AntPsTdma(padapter, true, 2);
7684 pBtdm8723->psTdmaDuAdjType = 2;
7685 } else if (pBtdm8723->curPsTdma == 2) {
7686 btdm_2AntPsTdma(padapter, true, 2);
7687 pBtdm8723->psTdmaDuAdjType = 2;
7688 } else if (pBtdm8723->curPsTdma == 12) {
7689 btdm_2AntPsTdma(padapter, true, 11);
7690 pBtdm8723->psTdmaDuAdjType = 11;
7691 } else if (pBtdm8723->curPsTdma == 11) {
7692 btdm_2AntPsTdma(padapter, true, 10);
7693 pBtdm8723->psTdmaDuAdjType = 10;
7694 } else if (pBtdm8723->curPsTdma == 10) {
7695 btdm_2AntPsTdma(padapter, true, 10);
7696 pBtdm8723->psTdmaDuAdjType = 10;
7700 } else if (maxInterval == 3) {
7702 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7703 if (pBtdm8723->curPsTdma == 1) {
7704 btdm_2AntPsTdma(padapter, true, 7);
7705 pBtdm8723->psTdmaDuAdjType = 7;
7706 } else if (pBtdm8723->curPsTdma == 2) {
7707 btdm_2AntPsTdma(padapter, true, 7);
7708 pBtdm8723->psTdmaDuAdjType = 7;
7709 } else if (pBtdm8723->curPsTdma == 3) {
7710 btdm_2AntPsTdma(padapter, true, 7);
7711 pBtdm8723->psTdmaDuAdjType = 7;
7712 } else if (pBtdm8723->curPsTdma == 4) {
7713 btdm_2AntPsTdma(padapter, true, 8);
7714 pBtdm8723->psTdmaDuAdjType = 8;
7716 if (pBtdm8723->curPsTdma == 9) {
7717 btdm_2AntPsTdma(padapter, true, 15);
7718 pBtdm8723->psTdmaDuAdjType = 15;
7719 } else if (pBtdm8723->curPsTdma == 10) {
7720 btdm_2AntPsTdma(padapter, true, 15);
7721 pBtdm8723->psTdmaDuAdjType = 15;
7722 } else if (pBtdm8723->curPsTdma == 11) {
7723 btdm_2AntPsTdma(padapter, true, 15);
7724 pBtdm8723->psTdmaDuAdjType = 15;
7725 } else if (pBtdm8723->curPsTdma == 12) {
7726 btdm_2AntPsTdma(padapter, true, 16);
7727 pBtdm8723->psTdmaDuAdjType = 16;
7730 if (pBtdm8723->curPsTdma == 5) {
7731 btdm_2AntPsTdma(padapter, true, 7);
7732 pBtdm8723->psTdmaDuAdjType = 7;
7733 } else if (pBtdm8723->curPsTdma == 6) {
7734 btdm_2AntPsTdma(padapter, true, 7);
7735 pBtdm8723->psTdmaDuAdjType = 7;
7736 } else if (pBtdm8723->curPsTdma == 7) {
7737 btdm_2AntPsTdma(padapter, true, 8);
7738 pBtdm8723->psTdmaDuAdjType = 8;
7739 } else if (pBtdm8723->curPsTdma == 13) {
7740 btdm_2AntPsTdma(padapter, true, 15);
7741 pBtdm8723->psTdmaDuAdjType = 15;
7742 } else if (pBtdm8723->curPsTdma == 14) {
7743 btdm_2AntPsTdma(padapter, true, 15);
7744 pBtdm8723->psTdmaDuAdjType = 15;
7745 } else if (pBtdm8723->curPsTdma == 15) {
7746 btdm_2AntPsTdma(padapter, true, 16);
7747 pBtdm8723->psTdmaDuAdjType = 16;
7749 } else if (result == 1) {
7750 if (pBtdm8723->curPsTdma == 8) {
7751 btdm_2AntPsTdma(padapter, true, 7);
7752 pBtdm8723->psTdmaDuAdjType = 7;
7753 } else if (pBtdm8723->curPsTdma == 7) {
7754 btdm_2AntPsTdma(padapter, true, 7);
7755 pBtdm8723->psTdmaDuAdjType = 7;
7756 } else if (pBtdm8723->curPsTdma == 6) {
7757 btdm_2AntPsTdma(padapter, true, 7);
7758 pBtdm8723->psTdmaDuAdjType = 7;
7759 } else if (pBtdm8723->curPsTdma == 16) {
7760 btdm_2AntPsTdma(padapter, true, 15);
7761 pBtdm8723->psTdmaDuAdjType = 15;
7762 } else if (pBtdm8723->curPsTdma == 15) {
7763 btdm_2AntPsTdma(padapter, true, 15);
7764 pBtdm8723->psTdmaDuAdjType = 15;
7765 } else if (pBtdm8723->curPsTdma == 14) {
7766 btdm_2AntPsTdma(padapter, true, 15);
7767 pBtdm8723->psTdmaDuAdjType = 15;
7771 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7772 if (pBtdm8723->curPsTdma == 5) {
7773 btdm_2AntPsTdma(padapter, true, 3);
7774 pBtdm8723->psTdmaDuAdjType = 3;
7775 } else if (pBtdm8723->curPsTdma == 6) {
7776 btdm_2AntPsTdma(padapter, true, 3);
7777 pBtdm8723->psTdmaDuAdjType = 3;
7778 } else if (pBtdm8723->curPsTdma == 7) {
7779 btdm_2AntPsTdma(padapter, true, 3);
7780 pBtdm8723->psTdmaDuAdjType = 3;
7781 } else if (pBtdm8723->curPsTdma == 8) {
7782 btdm_2AntPsTdma(padapter, true, 4);
7783 pBtdm8723->psTdmaDuAdjType = 4;
7785 if (pBtdm8723->curPsTdma == 13) {
7786 btdm_2AntPsTdma(padapter, true, 11);
7787 pBtdm8723->psTdmaDuAdjType = 11;
7788 } else if (pBtdm8723->curPsTdma == 14) {
7789 btdm_2AntPsTdma(padapter, true, 11);
7790 pBtdm8723->psTdmaDuAdjType = 11;
7791 } else if (pBtdm8723->curPsTdma == 15) {
7792 btdm_2AntPsTdma(padapter, true, 11);
7793 pBtdm8723->psTdmaDuAdjType = 11;
7794 } else if (pBtdm8723->curPsTdma == 16) {
7795 btdm_2AntPsTdma(padapter, true, 12);
7796 pBtdm8723->psTdmaDuAdjType = 12;
7799 if (pBtdm8723->curPsTdma == 1) {
7800 btdm_2AntPsTdma(padapter, true, 3);
7801 pBtdm8723->psTdmaDuAdjType = 3;
7802 } else if (pBtdm8723->curPsTdma == 2) {
7803 btdm_2AntPsTdma(padapter, true, 3);
7804 pBtdm8723->psTdmaDuAdjType = 3;
7805 } else if (pBtdm8723->curPsTdma == 3) {
7806 btdm_2AntPsTdma(padapter, true, 4);
7807 pBtdm8723->psTdmaDuAdjType = 4;
7808 } else if (pBtdm8723->curPsTdma == 9) {
7809 btdm_2AntPsTdma(padapter, true, 11);
7810 pBtdm8723->psTdmaDuAdjType = 11;
7811 } else if (pBtdm8723->curPsTdma == 10) {
7812 btdm_2AntPsTdma(padapter, true, 11);
7813 pBtdm8723->psTdmaDuAdjType = 11;
7814 } else if (pBtdm8723->curPsTdma == 11) {
7815 btdm_2AntPsTdma(padapter, true, 12);
7816 pBtdm8723->psTdmaDuAdjType = 12;
7818 } else if (result == 1) {
7819 if (pBtdm8723->curPsTdma == 4) {
7820 btdm_2AntPsTdma(padapter, true, 3);
7821 pBtdm8723->psTdmaDuAdjType = 3;
7822 } else if (pBtdm8723->curPsTdma == 3) {
7823 btdm_2AntPsTdma(padapter, true, 3);
7824 pBtdm8723->psTdmaDuAdjType = 3;
7825 } else if (pBtdm8723->curPsTdma == 2) {
7826 btdm_2AntPsTdma(padapter, true, 3);
7827 pBtdm8723->psTdmaDuAdjType = 3;
7828 } else if (pBtdm8723->curPsTdma == 12) {
7829 btdm_2AntPsTdma(padapter, true, 11);
7830 pBtdm8723->psTdmaDuAdjType = 11;
7831 } else if (pBtdm8723->curPsTdma == 11) {
7832 btdm_2AntPsTdma(padapter, true, 11);
7833 pBtdm8723->psTdmaDuAdjType = 11;
7834 } else if (pBtdm8723->curPsTdma == 10) {
7835 btdm_2AntPsTdma(padapter, true, 11);
7836 pBtdm8723->psTdmaDuAdjType = 11;
7842 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type : recordPsTdma =%d\n", pBtdm8723->psTdmaDuAdjType));
7843 /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
7844 /* then we have to adjust it back to the previous record one. */
7845 if (pBtdm8723->curPsTdma != pBtdm8723->psTdmaDuAdjType) {
7846 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma =%d, recordPsTdma =%d\n",
7847 pBtdm8723->curPsTdma, pBtdm8723->psTdmaDuAdjType));
7849 if (!check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
7850 btdm_2AntPsTdma(padapter, true, pBtdm8723->psTdmaDuAdjType);
7852 RTPRINT(FBT, BT_TRACE, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
7856 /* default Action */
7857 /* SCO only or SCO+PAN(HS) */
7858 static void btdm_2Ant8723ASCOAction(struct rtw_adapter *padapter)
7860 u8 btRssiState, btRssiState1;
7862 if (btdm_NeedToDecBtPwr(padapter))
7863 btdm_2AntDecBtPwr(padapter, true);
7865 btdm_2AntDecBtPwr(padapter, false);
7867 if (BTDM_IsHT40(padapter)) {
7868 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7869 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7871 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7872 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7873 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7874 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7875 btdm_2AntPsTdma(padapter, true, 11);
7877 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7878 btdm_2AntPsTdma(padapter, true, 15);
7882 btdm_2AntAgcTable(padapter, false);
7883 btdm_2AntAdcBackOff(padapter, true);
7884 btdm_2AntDacSwing(padapter, false, 0xc0);
7886 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7887 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7888 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7891 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7892 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7893 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7894 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7895 btdm_2AntPsTdma(padapter, true, 11);
7897 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7898 btdm_2AntPsTdma(padapter, true, 15);
7902 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7903 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7904 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7905 btdm_2AntAgcTable(padapter, true);
7906 btdm_2AntAdcBackOff(padapter, true);
7907 btdm_2AntDacSwing(padapter, false, 0xc0);
7909 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7910 btdm_2AntAgcTable(padapter, false);
7911 btdm_2AntAdcBackOff(padapter, false);
7912 btdm_2AntDacSwing(padapter, false, 0xc0);
7917 static void btdm_2Ant8723AHIDAction(struct rtw_adapter *padapter)
7919 u8 btRssiState, btRssiState1;
7921 if (btdm_NeedToDecBtPwr(padapter))
7922 btdm_2AntDecBtPwr(padapter, true);
7924 btdm_2AntDecBtPwr(padapter, false);
7926 if (BTDM_IsHT40(padapter)) {
7927 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7928 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7930 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7931 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7932 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7933 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7934 btdm_2AntPsTdma(padapter, true, 9);
7936 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7937 btdm_2AntPsTdma(padapter, true, 13);
7941 btdm_2AntAgcTable(padapter, false);
7942 btdm_2AntAdcBackOff(padapter, false);
7943 btdm_2AntDacSwing(padapter, false, 0xc0);
7945 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7946 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7947 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7950 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7951 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7952 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7953 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7954 btdm_2AntPsTdma(padapter, true, 9);
7956 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7957 btdm_2AntPsTdma(padapter, true, 13);
7961 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7962 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7963 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7964 btdm_2AntAgcTable(padapter, true);
7965 btdm_2AntAdcBackOff(padapter, true);
7966 btdm_2AntDacSwing(padapter, false, 0xc0);
7968 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7969 btdm_2AntAgcTable(padapter, false);
7970 btdm_2AntAdcBackOff(padapter, false);
7971 btdm_2AntDacSwing(padapter, false, 0xc0);
7976 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
7977 static void btdm_2Ant8723AA2DPAction(struct rtw_adapter *padapter)
7979 u8 btRssiState, btRssiState1;
7980 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7981 u8 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
7983 if (btdm_NeedToDecBtPwr(padapter))
7984 btdm_2AntDecBtPwr(padapter, true);
7986 btdm_2AntDecBtPwr(padapter, false);
7988 if (BTDM_IsHT40(padapter)) {
7989 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7990 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7993 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7994 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7995 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7996 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7998 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7999 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8000 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
8002 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8003 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8006 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8007 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8008 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8009 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
8011 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8012 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8017 btdm_2AntAgcTable(padapter, false);
8018 btdm_2AntAdcBackOff(padapter, true);
8019 btdm_2AntDacSwing(padapter, false, 0xc0);
8021 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8022 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8023 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8026 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8027 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8028 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8029 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8030 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8031 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8032 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
8034 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8035 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8038 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8039 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8040 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8041 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
8043 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8044 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8049 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8050 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8051 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8052 btdm_2AntAgcTable(padapter, true);
8053 btdm_2AntAdcBackOff(padapter, true);
8054 btdm_2AntDacSwing(padapter, false, 0xc0);
8056 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8057 btdm_2AntAgcTable(padapter, false);
8058 btdm_2AntAdcBackOff(padapter, false);
8059 btdm_2AntDacSwing(padapter, false, 0xc0);
8064 static void btdm_2Ant8723APANEDRAction(struct rtw_adapter *padapter)
8066 u8 btRssiState, btRssiState1;
8068 if (btdm_NeedToDecBtPwr(padapter))
8069 btdm_2AntDecBtPwr(padapter, true);
8071 btdm_2AntDecBtPwr(padapter, false);
8073 if (BTDM_IsHT40(padapter)) {
8074 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8075 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8078 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8079 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8080 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8081 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8082 btdm_2AntPsTdma(padapter, true, 2);
8084 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8085 btdm_2AntPsTdma(padapter, true, 6);
8089 btdm_2AntAgcTable(padapter, false);
8090 btdm_2AntAdcBackOff(padapter, true);
8091 btdm_2AntDacSwing(padapter, false, 0xc0);
8093 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8094 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8095 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8098 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8099 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8100 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8101 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8102 btdm_2AntPsTdma(padapter, true, 2);
8104 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8105 btdm_2AntPsTdma(padapter, true, 6);
8109 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8110 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8111 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8112 btdm_2AntAgcTable(padapter, true);
8113 btdm_2AntAdcBackOff(padapter, true);
8114 btdm_2AntDacSwing(padapter, false, 0xc0);
8116 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8117 btdm_2AntAgcTable(padapter, false);
8118 btdm_2AntAdcBackOff(padapter, false);
8119 btdm_2AntDacSwing(padapter, false, 0xc0);
8125 static void btdm_2Ant8723APANHSAction(struct rtw_adapter *padapter)
8129 if (BTDM_IsHT40(padapter)) {
8130 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8131 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8133 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8134 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8135 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8136 btdm_2AntDecBtPwr(padapter, true);
8138 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8139 btdm_2AntDecBtPwr(padapter, false);
8141 btdm_2AntPsTdma(padapter, false, 0);
8144 btdm_2AntAgcTable(padapter, false);
8145 btdm_2AntAdcBackOff(padapter, true);
8146 btdm_2AntDacSwing(padapter, false, 0xc0);
8148 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8149 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8151 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8152 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8153 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high\n"));
8155 btdm_2AntDecBtPwr(padapter, true);
8156 btdm_2AntPsTdma(padapter, false, 0);
8159 btdm_2AntAgcTable(padapter, true);
8160 btdm_2AntAdcBackOff(padapter, true);
8161 btdm_2AntDacSwing(padapter, false, 0xc0);
8163 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low\n"));
8165 btdm_2AntDecBtPwr(padapter, false);
8166 btdm_2AntPsTdma(padapter, false, 0);
8169 btdm_2AntAgcTable(padapter, false);
8170 btdm_2AntAdcBackOff(padapter, false);
8171 btdm_2AntDacSwing(padapter, false, 0xc0);
8177 static void btdm_2Ant8723APANEDRA2DPAction(struct rtw_adapter *padapter)
8179 u8 btRssiState, btRssiState1, btInfoExt;
8180 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8182 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8184 if (btdm_NeedToDecBtPwr(padapter))
8185 btdm_2AntDecBtPwr(padapter, true);
8187 btdm_2AntDecBtPwr(padapter, false);
8189 if (BTDM_IsHT40(padapter)) {
8190 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8191 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8193 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8194 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8195 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8197 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8199 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8200 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8201 btdm_2AntPsTdma(padapter, true, 4);
8203 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8204 btdm_2AntPsTdma(padapter, true, 2);
8207 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8209 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8210 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8211 btdm_2AntPsTdma(padapter, true, 8);
8213 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8214 btdm_2AntPsTdma(padapter, true, 6);
8219 btdm_2AntAgcTable(padapter, false);
8220 btdm_2AntAdcBackOff(padapter, true);
8221 btdm_2AntDacSwing(padapter, false, 0xc0);
8223 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8224 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8225 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8227 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8228 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8229 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8230 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8232 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8233 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8234 btdm_2AntPsTdma(padapter, true, 4);
8236 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8237 btdm_2AntPsTdma(padapter, true, 2);
8240 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8242 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8243 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8244 btdm_2AntPsTdma(padapter, true, 8);
8246 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8247 btdm_2AntPsTdma(padapter, true, 6);
8252 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8253 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8254 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8255 btdm_2AntAgcTable(padapter, true);
8256 btdm_2AntAdcBackOff(padapter, true);
8257 btdm_2AntDacSwing(padapter, false, 0xc0);
8259 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8260 btdm_2AntAgcTable(padapter, false);
8261 btdm_2AntAdcBackOff(padapter, false);
8262 btdm_2AntDacSwing(padapter, false, 0xc0);
8267 static void btdm_2Ant8723APANEDRHIDAction(struct rtw_adapter *padapter)
8269 u8 btRssiState, btRssiState1;
8271 if (btdm_NeedToDecBtPwr(padapter))
8272 btdm_2AntDecBtPwr(padapter, true);
8274 btdm_2AntDecBtPwr(padapter, false);
8276 if (BTDM_IsHT40(padapter)) {
8277 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8278 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8280 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8281 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8282 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8283 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8284 btdm_2AntPsTdma(padapter, true, 10);
8286 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8287 btdm_2AntPsTdma(padapter, true, 14);
8291 btdm_2AntAgcTable(padapter, false);
8292 btdm_2AntAdcBackOff(padapter, true);
8293 btdm_2AntDacSwing(padapter, false, 0xc0);
8295 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8296 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8297 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8300 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8301 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8302 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8303 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8304 btdm_2AntPsTdma(padapter, true, 10);
8306 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8307 btdm_2AntPsTdma(padapter, true, 14);
8311 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8312 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8313 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8314 btdm_2AntAgcTable(padapter, true);
8315 btdm_2AntAdcBackOff(padapter, true);
8316 btdm_2AntDacSwing(padapter, false, 0xc0);
8318 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8319 btdm_2AntAgcTable(padapter, false);
8320 btdm_2AntAdcBackOff(padapter, false);
8321 btdm_2AntDacSwing(padapter, false, 0xc0);
8326 /* HID+A2DP+PAN(EDR) */
8327 static void btdm_2Ant8723AHIDA2DPPANEDRAction(struct rtw_adapter *padapter)
8329 u8 btRssiState, btRssiState1, btInfoExt;
8330 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8332 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8334 if (btdm_NeedToDecBtPwr(padapter))
8335 btdm_2AntDecBtPwr(padapter, true);
8337 btdm_2AntDecBtPwr(padapter, false);
8339 if (BTDM_IsHT40(padapter)) {
8340 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8341 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8342 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8343 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8344 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8345 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8347 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8348 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8349 btdm_2AntPsTdma(padapter, true, 12);
8351 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8352 btdm_2AntPsTdma(padapter, true, 10);
8355 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8356 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8357 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8358 btdm_2AntPsTdma(padapter, true, 16);
8360 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8361 btdm_2AntPsTdma(padapter, true, 14);
8366 btdm_2AntAgcTable(padapter, false);
8367 btdm_2AntAdcBackOff(padapter, true);
8368 btdm_2AntDacSwing(padapter, false, 0xc0);
8370 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8371 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 37, 0);
8372 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8373 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8374 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8375 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8376 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8378 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8379 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8380 btdm_2AntPsTdma(padapter, true, 12);
8382 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8383 btdm_2AntPsTdma(padapter, true, 10);
8386 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8387 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8388 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8389 btdm_2AntPsTdma(padapter, true, 16);
8391 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8392 btdm_2AntPsTdma(padapter, true, 14);
8397 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8398 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8399 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8400 btdm_2AntAgcTable(padapter, true);
8401 btdm_2AntAdcBackOff(padapter, true);
8402 btdm_2AntDacSwing(padapter, false, 0xc0);
8404 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8405 btdm_2AntAgcTable(padapter, false);
8406 btdm_2AntAdcBackOff(padapter, false);
8407 btdm_2AntDacSwing(padapter, false, 0xc0);
8412 static void btdm_2Ant8723AHIDA2DPAction(struct rtw_adapter *padapter)
8414 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8415 u8 btRssiState, btRssiState1, btInfoExt;
8417 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8419 if (btdm_NeedToDecBtPwr(padapter))
8420 btdm_2AntDecBtPwr(padapter, true);
8422 btdm_2AntDecBtPwr(padapter, false);
8424 if (BTDM_IsHT40(padapter)) {
8425 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8426 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8427 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8428 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8429 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8430 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8432 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8433 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8434 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8436 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8437 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8440 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8441 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8442 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8443 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8445 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8446 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8450 btdm_2AntAgcTable(padapter, false);
8451 btdm_2AntAdcBackOff(padapter, true);
8452 btdm_2AntDacSwing(padapter, false, 0xc0);
8454 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8455 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8456 btRssiState1 = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8458 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8459 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8460 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8461 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8463 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8464 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8465 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8467 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8468 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8471 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8472 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8473 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8474 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8476 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8477 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8480 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8481 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8482 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8484 btdm_2AntAgcTable(padapter, true);
8485 btdm_2AntAdcBackOff(padapter, true);
8486 btdm_2AntDacSwing(padapter, false, 0xc0);
8488 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8490 btdm_2AntAgcTable(padapter, false);
8491 btdm_2AntAdcBackOff(padapter, false);
8492 btdm_2AntDacSwing(padapter, false, 0xc0);
8497 static void btdm_2Ant8723AA2dp(struct rtw_adapter *padapter)
8499 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8500 u8 btRssiState, btRssiState1, btInfoExt;
8502 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8504 if (btdm_NeedToDecBtPwr(padapter))
8505 btdm_2AntDecBtPwr(padapter, true);
8507 btdm_2AntDecBtPwr(padapter, false);
8509 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8510 btdm_2AntIgnoreWlanAct(padapter, false);
8512 if (BTDM_IsHT40(padapter)) {
8513 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8514 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8516 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8517 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8518 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8519 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8520 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8522 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8523 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8527 btdm_2AntAgcTable(padapter, false);
8528 btdm_2AntAdcBackOff(padapter, true);
8529 btdm_2AntDacSwing(padapter, false, 0xc0);
8531 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8532 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8533 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8536 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8537 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8538 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8539 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8540 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8542 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8543 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8547 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8548 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8549 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8550 btdm_2AntAgcTable(padapter, true);
8551 btdm_2AntAdcBackOff(padapter, true);
8552 btdm_2AntDacSwing(padapter, false, 0xc0);
8554 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8555 btdm_2AntAgcTable(padapter, false);
8556 btdm_2AntAdcBackOff(padapter, false);
8557 btdm_2AntDacSwing(padapter, false, 0xc0);
8562 /* extern function start with BTDM_ */
8563 static void BTDM_2AntParaInit(struct rtw_adapter *padapter)
8566 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8567 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8569 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2Ant Parameter Init!!\n"));
8571 /* Enable counter statistics */
8572 rtl8723au_write8(padapter, 0x76e, 0x4);
8573 rtl8723au_write8(padapter, 0x778, 0x3);
8574 rtl8723au_write8(padapter, 0x40, 0x20);
8576 /* force to reset coex mechanism */
8577 pBtdm8723->preVal0x6c0 = 0x0;
8578 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8580 pBtdm8723->bPrePsTdmaOn = true;
8581 btdm_2AntPsTdma(padapter, false, 0);
8583 pBtdm8723->preFwDacSwingLvl = 0x10;
8584 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8586 pBtdm8723->bPreDecBtPwr = true;
8587 btdm_2AntDecBtPwr(padapter, false);
8589 pBtdm8723->bPreAgcTableEn = true;
8590 btdm_2AntAgcTable(padapter, false);
8592 pBtdm8723->bPreAdcBackOff = true;
8593 btdm_2AntAdcBackOff(padapter, false);
8595 pBtdm8723->bPreLowPenaltyRa = true;
8596 btdm_2AntLowPenaltyRa(padapter, false);
8598 pBtdm8723->bPreRfRxLpfShrink = true;
8599 btdm_2AntRfShrink(padapter, false);
8601 pBtdm8723->bPreDacSwingOn = true;
8602 btdm_2AntDacSwing(padapter, false, 0xc0);
8604 pBtdm8723->bPreIgnoreWlanAct = true;
8605 btdm_2AntIgnoreWlanAct(padapter, false);
8608 static void BTDM_2AntHwCoexAllOff8723A(struct rtw_adapter *padapter)
8610 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8613 static void BTDM_2AntFwCoexAllOff8723A(struct rtw_adapter *padapter)
8615 btdm_2AntIgnoreWlanAct(padapter, false);
8616 btdm_2AntPsTdma(padapter, false, 0);
8617 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8618 btdm_2AntDecBtPwr(padapter, false);
8621 static void BTDM_2AntSwCoexAllOff8723A(struct rtw_adapter *padapter)
8623 btdm_2AntAgcTable(padapter, false);
8624 btdm_2AntAdcBackOff(padapter, false);
8625 btdm_2AntLowPenaltyRa(padapter, false);
8626 btdm_2AntRfShrink(padapter, false);
8627 btdm_2AntDacSwing(padapter, false, 0xc0);
8630 static void BTDM_2AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
8632 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8633 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8634 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8635 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8637 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
8638 u8 bBtLinkExist = false, bBtHsModeExist = false;
8640 btInfo = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8641 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8643 /* check BIT2 first ==> check if bt is under inquiry or page scan */
8644 if (btInfo & BIT(2)) {
8645 if (!pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
8646 pBtMgnt->ExtConfig.bHoldForBtOperation = true;
8647 pBtMgnt->ExtConfig.bHoldPeriodCnt = 1;
8648 btdm_2AntBtInquiryPage(padapter);
8650 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8651 btdm_HoldForBtInqPage(padapter);
8653 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = true;
8656 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = false;
8657 pBtMgnt->ExtConfig.bHoldForBtOperation = false;
8658 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8661 RTPRINT(FBT, BT_TRACE,
8662 ("[BTC2H], pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage =%x pBtMgnt->ExtConfig.bHoldPeriodCnt =%x pBtMgnt->ExtConfig.bHoldForBtOperation =%x\n",
8663 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage,
8664 pBtMgnt->ExtConfig.bHoldPeriodCnt,
8665 pBtMgnt->ExtConfig.bHoldForBtOperation));
8667 RTPRINT(FBT, BT_TRACE,
8668 ("[BTC2H], btInfo =%x pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal =%x\n",
8669 btInfo, pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal));
8670 if (btInfo&BT_INFO_ACL) {
8671 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = true btInfo =%x\n", btInfo));
8672 bBtLinkExist = true;
8673 if (((btInfo&(BT_INFO_FTP|BT_INFO_A2DP|BT_INFO_HID|BT_INFO_SCO_BUSY)) != 0) ||
8674 pHalData->bt_coexist.halCoex8723.btRetryCnt > 0) {
8675 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
8677 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
8680 if (btInfo&BT_INFO_SCO || btInfo&BT_INFO_SCO_BUSY) {
8681 if (btInfo&BT_INFO_FTP || btInfo&BT_INFO_A2DP || btInfo&BT_INFO_HID) {
8682 switch (btInfo&0xe0) {
8684 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
8685 algorithm = BT_2ANT_COEX_ALGO_HID;
8688 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
8691 if (bBtHsModeExist) {
8692 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
8693 algorithm = BT_2ANT_COEX_ALGO_SCO;
8695 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
8696 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8699 case (BT_INFO_HID | BT_INFO_A2DP):
8700 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8701 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8703 case (BT_INFO_HID | BT_INFO_FTP):
8704 if (bBtHsModeExist) {
8705 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8706 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8708 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8709 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8712 case (BT_INFO_A2DP | BT_INFO_FTP):
8713 if (bBtHsModeExist) {
8714 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8715 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8717 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8718 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8721 case (BT_INFO_HID | BT_INFO_A2DP | BT_INFO_FTP):
8722 if (bBtHsModeExist) {
8723 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8724 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8726 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8727 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8732 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
8733 algorithm = BT_2ANT_COEX_ALGO_SCO;
8736 RTPRINT(FBT, BT_TRACE, ("[BTCoex], non SCO\n"));
8737 switch (btInfo&0xe0) {
8739 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID\n"));
8740 algorithm = BT_2ANT_COEX_ALGO_HID;
8743 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP\n"));
8744 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8747 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR)\n"));
8748 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8750 case (BT_INFO_HID | BT_INFO_A2DP):
8751 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8752 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8754 case (BT_INFO_HID|BT_INFO_FTP):
8755 if (bBtHsModeExist) {
8756 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8757 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8759 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8760 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8763 case (BT_INFO_A2DP|BT_INFO_FTP):
8764 if (bBtHsModeExist) {
8765 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8766 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8768 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8769 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8772 case (BT_INFO_HID|BT_INFO_A2DP|BT_INFO_FTP):
8773 if (bBtHsModeExist) {
8774 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8775 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8777 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8778 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8785 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = false\n"));
8786 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8789 pBtdm8723->curAlgorithm = algorithm;
8790 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8793 BTDM_CheckWiFiState(padapter);
8794 if (pBtMgnt->ExtConfig.bManualControl) {
8795 RTPRINT(FBT, BT_TRACE, ("Action Manual control, won't execute bt coexist mechanism!!\n"));
8800 void BTDM_2AntBtCoexist8723A(struct rtw_adapter *padapter)
8802 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8803 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8804 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
8805 u8 btInfoOriginal = 0;
8806 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8807 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8809 if (BTDM_BtProfileSupport(padapter)) {
8810 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8811 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8814 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8815 RTPRINT(FBT, BT_TRACE, ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8816 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8817 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8818 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8819 /* next time the coexist parameters should be reset again. */
8821 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8826 if (pBtDbg->dbgCtrl)
8827 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8829 pBtdm8723->curAlgorithm = btdm_ActionAlgorithm(padapter);
8830 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8832 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8833 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8834 pBtdm8723->bResetTdmaAdjust = true;
8836 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8837 RTPRINT(FBT, BT_TRACE, ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8838 pBtdm8723->preAlgorithm, pBtdm8723->curAlgorithm));
8839 pBtdm8723->bResetTdmaAdjust = true;
8841 switch (pBtdm8723->curAlgorithm) {
8842 case BT_2ANT_COEX_ALGO_SCO:
8843 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8844 btdm_2Ant8723ASCOAction(padapter);
8846 case BT_2ANT_COEX_ALGO_HID:
8847 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8848 btdm_2Ant8723AHIDAction(padapter);
8850 case BT_2ANT_COEX_ALGO_A2DP:
8851 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8852 btdm_2Ant8723AA2DPAction(padapter);
8854 case BT_2ANT_COEX_ALGO_PANEDR:
8855 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8856 btdm_2Ant8723APANEDRAction(padapter);
8858 case BT_2ANT_COEX_ALGO_PANHS:
8859 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8860 btdm_2Ant8723APANHSAction(padapter);
8862 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8863 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8864 btdm_2Ant8723APANEDRA2DPAction(padapter);
8866 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8867 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8868 btdm_2Ant8723APANEDRHIDAction(padapter);
8870 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8871 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8872 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8874 case BT_2ANT_COEX_ALGO_HID_A2DP:
8875 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8876 btdm_2Ant8723AHIDA2DPAction(padapter);
8879 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8880 btdm_2Ant8723AA2DPAction(padapter);
8883 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8886 RTPRINT(FBT, BT_TRACE, ("[BTCoex] Get bt info by fw!!\n"));
8887 /* msg shows c2h rsp for bt_info is received or not. */
8888 if (pHalData->bt_coexist.halCoex8723.bC2hBtInfoReqSent)
8889 RTPRINT(FBT, BT_TRACE, ("[BTCoex] c2h for btInfo not rcvd yet!!\n"));
8891 btInfoOriginal = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8893 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8894 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8897 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8898 RTPRINT(FBT, BT_TRACE,
8899 ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8900 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8901 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8902 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8903 /* next time the coexist parameters should be reset again. */
8905 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8910 if (pBtDbg->dbgCtrl)
8911 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8912 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8913 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8914 pBtdm8723->bResetTdmaAdjust = true;
8916 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8917 RTPRINT(FBT, BT_TRACE,
8918 ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8919 pBtdm8723->preAlgorithm,
8920 pBtdm8723->curAlgorithm));
8921 pBtdm8723->bResetTdmaAdjust = true;
8923 switch (pBtdm8723->curAlgorithm) {
8924 case BT_2ANT_COEX_ALGO_SCO:
8925 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8926 btdm_2Ant8723ASCOAction(padapter);
8928 case BT_2ANT_COEX_ALGO_HID:
8929 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8930 btdm_2Ant8723AHIDAction(padapter);
8932 case BT_2ANT_COEX_ALGO_A2DP:
8933 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8934 btdm_2Ant8723AA2dp(padapter);
8936 case BT_2ANT_COEX_ALGO_PANEDR:
8937 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8938 btdm_2Ant8723APANEDRAction(padapter);
8940 case BT_2ANT_COEX_ALGO_PANHS:
8941 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8942 btdm_2Ant8723APANHSAction(padapter);
8944 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8945 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8946 btdm_2Ant8723APANEDRA2DPAction(padapter);
8948 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8949 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8950 btdm_2Ant8723APANEDRHIDAction(padapter);
8952 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8953 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8954 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8956 case BT_2ANT_COEX_ALGO_HID_A2DP:
8957 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8958 btdm_2Ant8723AHIDA2DPAction(padapter);
8961 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8962 btdm_2Ant8723AA2DPAction(padapter);
8965 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8970 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
8972 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
8974 static u8 btCoexDbgBuf[BT_TMP_BUF_SIZE];
8976 static const char *const BtProfileString[] = {
8984 static const char *const BtSpecString[] = {
8994 static const char *const BtLinkRoleString[] = {
8999 static u8 btdm_BtWifiAntNum(struct rtw_adapter *padapter)
9001 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9002 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9004 if (Ant_x2 == pHalData->bt_coexist.BT_Ant_Num) {
9005 if (Ant_x2 == pBtCoex->TotalAntNum)
9015 static void btdm_BtHwCountersMonitor(struct rtw_adapter *padapter)
9017 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9018 u32 regHPTxRx, regLPTxRx, u4Tmp;
9019 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
9021 regHPTxRx = REG_HIGH_PRIORITY_TXRX;
9022 regLPTxRx = REG_LOW_PRIORITY_TXRX;
9024 u4Tmp = rtl8723au_read32(padapter, regHPTxRx);
9025 regHPTx = u4Tmp & bMaskLWord;
9026 regHPRx = (u4Tmp & bMaskHWord)>>16;
9028 u4Tmp = rtl8723au_read32(padapter, regLPTxRx);
9029 regLPTx = u4Tmp & bMaskLWord;
9030 regLPRx = (u4Tmp & bMaskHWord)>>16;
9032 pHalData->bt_coexist.halCoex8723.highPriorityTx = regHPTx;
9033 pHalData->bt_coexist.halCoex8723.highPriorityRx = regHPRx;
9034 pHalData->bt_coexist.halCoex8723.lowPriorityTx = regLPTx;
9035 pHalData->bt_coexist.halCoex8723.lowPriorityRx = regLPRx;
9037 RTPRINT(FBT, BT_TRACE, ("High Priority Tx/Rx = %d / %d\n", regHPTx, regHPRx));
9038 RTPRINT(FBT, BT_TRACE, ("Low Priority Tx/Rx = %d / %d\n", regLPTx, regLPRx));
9041 rtl8723au_write8(padapter, 0x76e, 0xc);
9044 /* This function check if 8723 bt is disabled */
9045 static void btdm_BtEnableDisableCheck8723A(struct rtw_adapter *padapter)
9048 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9050 #ifdef CHECK_BT_EXIST_FROM_REG
9053 /* ox68[28]= 1 => BT enable; otherwise disable */
9054 val8 = rtl8723au_read8(padapter, 0x6B);
9055 if (!(val8 & BIT(4)))
9059 pHalData->bt_coexist.bCurBtDisabled = false;
9061 pHalData->bt_coexist.bCurBtDisabled = true;
9063 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0 &&
9064 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0 &&
9065 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0 &&
9066 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0)
9068 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xeaea &&
9069 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xeaea &&
9070 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xeaea &&
9071 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xeaea)
9073 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xffff &&
9074 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xffff &&
9075 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xffff &&
9076 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xffff)
9079 pHalData->bt_coexist.btActiveZeroCnt = 0;
9080 pHalData->bt_coexist.bCurBtDisabled = false;
9081 RTPRINT(FBT, BT_TRACE, ("8723A BT is enabled !!\n"));
9083 pHalData->bt_coexist.btActiveZeroCnt++;
9084 RTPRINT(FBT, BT_TRACE, ("8723A bt all counters = 0, %d times!!\n",
9085 pHalData->bt_coexist.btActiveZeroCnt));
9086 if (pHalData->bt_coexist.btActiveZeroCnt >= 2) {
9087 pHalData->bt_coexist.bCurBtDisabled = true;
9088 RTPRINT(FBT, BT_TRACE, ("8723A BT is disabled !!\n"));
9093 if (!pHalData->bt_coexist.bCurBtDisabled) {
9094 if (BTDM_IsWifiConnectionExist(padapter))
9095 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
9097 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_DISCONNECT);
9100 if (pHalData->bt_coexist.bPreBtDisabled !=
9101 pHalData->bt_coexist.bCurBtDisabled) {
9102 RTPRINT(FBT, BT_TRACE, ("8723A BT is from %s to %s!!\n",
9103 (pHalData->bt_coexist.bPreBtDisabled ? "disabled":"enabled"),
9104 (pHalData->bt_coexist.bCurBtDisabled ? "disabled":"enabled")));
9105 pHalData->bt_coexist.bPreBtDisabled = pHalData->bt_coexist.bCurBtDisabled;
9109 static void btdm_BTCoexist8723AHandler(struct rtw_adapter *padapter)
9111 struct hal_data_8723a *pHalData;
9113 pHalData = GET_HAL_DATA(padapter);
9115 if (btdm_BtWifiAntNum(padapter) == Ant_x2) {
9116 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2 Ant mechanism\n"));
9117 BTDM_2AntBtCoexist8723A(padapter);
9119 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1 Ant mechanism\n"));
9120 BTDM_1AntBtCoexist8723A(padapter);
9123 if (!BTDM_IsSameCoexistState(padapter)) {
9124 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x\n",
9125 pHalData->bt_coexist.PreviousState,
9126 pHalData->bt_coexist.CurrentState));
9127 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
9129 RTPRINT(FBT, BT_TRACE, ("["));
9130 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT30)
9131 RTPRINT(FBT, BT_TRACE, ("BT 3.0, "));
9132 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT20)
9133 RTPRINT(FBT, BT_TRACE, ("HT20, "));
9134 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT40)
9135 RTPRINT(FBT, BT_TRACE, ("HT40, "));
9136 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_LEGACY)
9137 RTPRINT(FBT, BT_TRACE, ("Legacy, "));
9138 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_LOW)
9139 RTPRINT(FBT, BT_TRACE, ("Rssi_Low, "));
9140 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_MEDIUM)
9141 RTPRINT(FBT, BT_TRACE, ("Rssi_Mid, "));
9142 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_HIGH)
9143 RTPRINT(FBT, BT_TRACE, ("Rssi_High, "));
9144 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_IDLE)
9145 RTPRINT(FBT, BT_TRACE, ("Wifi_Idle, "));
9146 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_UPLINK)
9147 RTPRINT(FBT, BT_TRACE, ("Wifi_Uplink, "));
9148 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_DOWNLINK)
9149 RTPRINT(FBT, BT_TRACE, ("Wifi_Downlink, "));
9150 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)
9151 RTPRINT(FBT, BT_TRACE, ("BT_idle, "));
9152 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_HID)
9153 RTPRINT(FBT, BT_TRACE, ("PRO_HID, "));
9154 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_A2DP)
9155 RTPRINT(FBT, BT_TRACE, ("PRO_A2DP, "));
9156 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_PAN)
9157 RTPRINT(FBT, BT_TRACE, ("PRO_PAN, "));
9158 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_SCO)
9159 RTPRINT(FBT, BT_TRACE, ("PRO_SCO, "));
9160 RTPRINT(FBT, BT_TRACE, ("]\n"));
9164 /* extern function start with BTDM_ */
9165 u32 BTDM_BtTxRxCounterH(struct rtw_adapter *padapter)
9167 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9170 counters = pHalData->bt_coexist.halCoex8723.highPriorityTx+
9171 pHalData->bt_coexist.halCoex8723.highPriorityRx;
9175 u32 BTDM_BtTxRxCounterL(struct rtw_adapter *padapter)
9177 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9180 counters = pHalData->bt_coexist.halCoex8723.lowPriorityTx+
9181 pHalData->bt_coexist.halCoex8723.lowPriorityRx ;
9185 void BTDM_SetFwChnlInfo(struct rtw_adapter *padapter, enum rt_media_status mstatus)
9187 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9188 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9189 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9190 u8 H2C_Parameter[3] = {0};
9194 if (RT_MEDIA_CONNECT == mstatus)
9195 H2C_Parameter[0] = 0x1; /* 0: disconnected, 1:connected */
9197 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) {
9199 chnl = pmlmeext->cur_channel;
9200 if (BTDM_IsHT40(padapter)) {
9201 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
9203 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
9206 H2C_Parameter[1] = chnl;
9207 } else { /* check if HS link is exists */
9209 if (BT_Operation(padapter))
9210 H2C_Parameter[1] = pBtMgnt->BTChannel;
9212 H2C_Parameter[1] = pmlmeext->cur_channel;
9215 if (BTDM_IsHT40(padapter))
9216 H2C_Parameter[2] = 0x30;
9218 H2C_Parameter[2] = 0x20;
9220 FillH2CCmd(padapter, 0x19, 3, H2C_Parameter);
9223 u8 BTDM_IsWifiConnectionExist(struct rtw_adapter *padapter)
9227 if (BTHCI_HsConnectionEstablished(padapter))
9230 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true)
9237 struct rtw_adapter *padapter,
9245 u8 H2C_Parameter[5] = {0};
9247 if (rtl8723a_BT_using_antenna_1(padapter)) {
9248 if ((!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
9249 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
9250 /* for softap mode */
9251 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9252 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9253 u8 BtState = pBtCoex->c2hBtInfo;
9255 if ((BtState != BT_INFO_STATE_NO_CONNECTION) &&
9256 (BtState != BT_INFO_STATE_CONNECT_IDLE)) {
9257 if (byte1 & BIT(4)) {
9269 H2C_Parameter[0] = byte1;
9270 H2C_Parameter[1] = byte2;
9271 H2C_Parameter[2] = byte3;
9272 H2C_Parameter[3] = byte4;
9273 H2C_Parameter[4] = byte5;
9275 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%02x%08x\n",
9277 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
9279 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
9282 void BTDM_QueryBtInformation(struct rtw_adapter *padapter)
9284 u8 H2C_Parameter[1] = {0};
9285 struct hal_data_8723a *pHalData;
9286 struct bt_coexist_8723a *pBtCoex;
9288 pHalData = GET_HAL_DATA(padapter);
9289 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9291 if (!rtl8723a_BT_enabled(padapter)) {
9292 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9293 pBtCoex->bC2hBtInfoReqSent = false;
9297 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9298 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9300 if (pBtCoex->bC2hBtInfoReqSent == true)
9301 RTPRINT(FBT, BT_TRACE, ("[BTCoex], didn't recv previous BtInfo report!\n"));
9303 pBtCoex->bC2hBtInfoReqSent = true;
9305 H2C_Parameter[0] |= BIT(0); /* trigger */
9307 /*RTPRINT(FBT, BT_TRACE, ("[BTCoex], Query Bt information, write 0x38 = 0x%x\n", */
9308 /*H2C_Parameter[0])); */
9310 FillH2CCmd(padapter, 0x38, 1, H2C_Parameter);
9313 void BTDM_SetSwRfRxLpfCorner(struct rtw_adapter *padapter, u8 type)
9315 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9317 if (BT_RF_RX_LPF_CORNER_SHRINK == type) {
9318 /* Shrink RF Rx LPF corner */
9319 RTPRINT(FBT, BT_TRACE, ("Shrink RF Rx LPF corner!!\n"));
9320 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, 0xf0ff7);
9321 pHalData->bt_coexist.bSWCoexistAllOff = false;
9322 } else if (BT_RF_RX_LPF_CORNER_RESUME == type) {
9323 /* Resume RF Rx LPF corner */
9324 RTPRINT(FBT, BT_TRACE, ("Resume RF Rx LPF corner!!\n"));
9325 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, pHalData->bt_coexist.BtRfRegOrigin1E);
9330 BTDM_SetSwPenaltyTxRateAdaptive(
9331 struct rtw_adapter *padapter,
9335 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9338 tmpU1 = rtl8723au_read8(padapter, 0x4fd);
9340 if (BT_TX_RATE_ADAPTIVE_LOW_PENALTY == raType) {
9342 pHalData->bt_coexist.bSWCoexistAllOff = false;
9343 } else if (BT_TX_RATE_ADAPTIVE_NORMAL == raType) {
9347 rtl8723au_write8(padapter, 0x4fd, tmpU1);
9350 void BTDM_SetFwDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
9352 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9353 u8 H2C_Parameter[1] = {0};
9355 H2C_Parameter[0] = 0;
9358 H2C_Parameter[0] |= BIT(1);
9359 pHalData->bt_coexist.bFWCoexistAllOff = false;
9362 RTPRINT(FBT, BT_TRACE, ("[BTCoex], decrease Bt Power : %s, write 0x21 = 0x%x\n",
9363 (bDecBtPwr ? "Yes!!" : "No!!"), H2C_Parameter[0]));
9365 FillH2CCmd(padapter, 0x21, 1, H2C_Parameter);
9368 u8 BTDM_BtProfileSupport(struct rtw_adapter *padapter)
9371 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9372 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9373 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9375 if (pBtMgnt->bSupportProfile &&
9376 !pHalData->bt_coexist.halCoex8723.bForceFwBtInfo)
9382 static void BTDM_AdjustForBtOperation8723A(struct rtw_adapter *padapter)
9384 /* BTDM_2AntAdjustForBtOperation8723(padapter); */
9387 static void BTDM_FwC2hBtRssi8723A(struct rtw_adapter *padapter, u8 *tmpBuf)
9389 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9390 u8 percent = 0, u1tmp = 0;
9393 percent = u1tmp*2+10;
9395 pHalData->bt_coexist.halCoex8723.btRssi = percent;
9396 /*RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", percent)); */
9400 rtl8723a_fw_c2h_BT_info(struct rtw_adapter *padapter, u8 *tmpBuf, u8 length)
9402 struct hal_data_8723a *pHalData;
9403 struct bt_30info *pBTInfo;
9404 struct bt_mgnt *pBtMgnt;
9405 struct bt_coexist_8723a *pBtCoex;
9408 pHalData = GET_HAL_DATA(padapter);
9409 pBTInfo = GET_BT_INFO(padapter);
9410 pBtMgnt = &pBTInfo->BtMgnt;
9411 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9413 pBtCoex->bC2hBtInfoReqSent = false;
9415 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT info[%d]=[", length));
9417 pBtCoex->btRetryCnt = 0;
9418 for (i = 0; i < length; i++) {
9421 pBtCoex->c2hBtInfoOriginal = tmpBuf[i];
9424 pBtCoex->btRetryCnt = tmpBuf[i];
9427 BTDM_FwC2hBtRssi8723A(padapter, &tmpBuf[i]);
9430 pBtCoex->btInfoExt = tmpBuf[i]&BIT(0);
9435 RTPRINT(FBT, BT_TRACE, ("0x%02x]\n", tmpBuf[i]));
9437 RTPRINT(FBT, BT_TRACE, ("0x%02x, ", tmpBuf[i]));
9439 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", pBtCoex->btRssi));
9440 if (pBtCoex->btInfoExt)
9441 RTPRINT(FBT, BT_TRACE, ("[BTC2H], pBtCoex->btInfoExt =%x\n", pBtCoex->btInfoExt));
9443 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9444 BTDM_1AntFwC2hBtInfo8723A(padapter);
9446 BTDM_2AntFwC2hBtInfo8723A(padapter);
9448 if (pBtMgnt->ExtConfig.bManualControl) {
9449 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9453 btdm_BTCoexist8723AHandler(padapter);
9456 static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
9458 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9459 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9460 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9461 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9462 u8 u1Tmp, u1Tmp1, u1Tmp2, i, btInfoExt, psTdmaCase = 0;
9466 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
9467 DCMD_Printf(btCoexDbgBuf);
9469 if (!rtl8723a_BT_coexist(padapter)) {
9470 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");
9471 DCMD_Printf(btCoexDbgBuf);
9475 antNum = btdm_BtWifiAntNum(padapter);
9476 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/%d ", "Ant mechanism PG/Now run :", \
9477 ((pHalData->bt_coexist.BT_Ant_Num == Ant_x2) ? 2 : 1), ((antNum == Ant_x2) ? 2 : 1));
9478 DCMD_Printf(btCoexDbgBuf);
9480 if (pBtMgnt->ExtConfig.bManualControl) {
9481 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
9482 DCMD_Printf(btCoexDbgBuf);
9484 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
9485 ((pBtMgnt->bSupportProfile) ? "Yes" : "No"), pBtMgnt->ExtConfig.HCIExtensionVer);
9486 DCMD_Printf(btCoexDbgBuf);
9489 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = / %d", "Dot11 channel / BT channel", \
9490 pBtMgnt->BTChannel);
9491 DCMD_Printf(btCoexDbgBuf);
9493 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %d / %d / %d", "Wifi/BT/HS rssi", \
9494 BTDM_GetRxSS(padapter),
9495 pHalData->bt_coexist.halCoex8723.btRssi,
9496 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB);
9497 DCMD_Printf(btCoexDbgBuf);
9499 if (!pBtMgnt->ExtConfig.bManualControl) {
9500 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %s / %s ", "WIfi status",
9501 ((BTDM_Legacy(padapter)) ? "Legacy" : (((BTDM_IsHT40(padapter)) ? "HT40" : "HT20"))),
9502 ((!BTDM_IsWifiBusy(padapter)) ? "idle" : ((BTDM_IsWifiUplink(padapter)) ? "uplink" : "downlink")));
9503 DCMD_Printf(btCoexDbgBuf);
9505 if (pBtMgnt->bSupportProfile) {
9506 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
9507 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_SCO)) ? 1 : 0),
9508 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) ? 1 : 0),
9509 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) ? 1 : 0),
9510 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) ? 1 : 0));
9511 DCMD_Printf(btCoexDbgBuf);
9513 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
9514 if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
9515 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role",
9516 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9517 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec],
9518 BtLinkRoleString[pBtMgnt->ExtConfig.linkInfo[i].linkRole]);
9519 DCMD_Printf(btCoexDbgBuf);
9521 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
9522 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "A2DP rate", \
9523 (btInfoExt & BIT(0)) ?
9524 "Basic rate" : "EDR rate");
9525 DCMD_Printf(btCoexDbgBuf);
9527 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
9528 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9529 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec]);
9530 DCMD_Printf(btCoexDbgBuf);
9537 if (!pBtMgnt->ExtConfig.bManualControl) {
9538 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw BT Coex mechanism]============");
9539 DCMD_Printf(btCoexDbgBuf);
9540 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "AGC Table", \
9541 pBtCoex->btdm2Ant.bCurAgcTableEn);
9542 DCMD_Printf(btCoexDbgBuf);
9543 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "ADC Backoff", \
9544 pBtCoex->btdm2Ant.bCurAdcBackOff);
9545 DCMD_Printf(btCoexDbgBuf);
9546 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Low penalty RA", \
9547 pBtCoex->btdm2Ant.bCurLowPenaltyRa);
9548 DCMD_Printf(btCoexDbgBuf);
9549 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "RF Rx LPF Shrink", \
9550 pBtCoex->btdm2Ant.bCurRfRxLpfShrink);
9551 DCMD_Printf(btCoexDbgBuf);
9553 u4Tmp[0] = PHY_QueryRFReg(padapter, PathA, 0x1e, 0xff0);
9554 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "RF-A, 0x1e[11:4]/original val", \
9555 u4Tmp[0], pHalData->bt_coexist.BtRfRegOrigin1E);
9556 DCMD_Printf(btCoexDbgBuf);
9559 if (!pBtMgnt->ExtConfig.bManualControl) {
9560 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw BT Coex mechanism]============");
9561 DCMD_Printf(btCoexDbgBuf);
9563 if (!pBtMgnt->ExtConfig.bManualControl) {
9564 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9565 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm1Ant.curPsTdma;
9567 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm2Ant.curPsTdma;
9568 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA(0x3a)", \
9569 pHalData->bt_coexist.fw3aVal[0], pHalData->bt_coexist.fw3aVal[1],
9570 pHalData->bt_coexist.fw3aVal[2], pHalData->bt_coexist.fw3aVal[3],
9571 pHalData->bt_coexist.fw3aVal[4], psTdmaCase);
9572 DCMD_Printf(btCoexDbgBuf);
9574 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Decrease Bt Power", \
9575 pBtCoex->btdm2Ant.bCurDecBtPwr);
9576 DCMD_Printf(btCoexDbgBuf);
9578 u1Tmp = rtl8723au_read8(padapter, 0x778);
9579 u1Tmp1 = rtl8723au_read8(padapter, 0x783);
9580 u1Tmp2 = rtl8723au_read8(padapter, 0x796);
9581 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
9582 u1Tmp, u1Tmp1, u1Tmp2);
9583 DCMD_Printf(btCoexDbgBuf);
9585 if (!pBtMgnt->ExtConfig.bManualControl) {
9586 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "Sw DacSwing Ctrl/Val", \
9587 pBtCoex->btdm2Ant.bCurDacSwingOn, pBtCoex->btdm2Ant.curDacSwingLvl);
9588 DCMD_Printf(btCoexDbgBuf);
9590 u4Tmp[0] = rtl8723au_read32(padapter, 0x880);
9591 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \
9593 DCMD_Printf(btCoexDbgBuf);
9596 if (!pBtMgnt->ExtConfig.bManualControl) {
9597 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw BT Coex mechanism]============");
9598 DCMD_Printf(btCoexDbgBuf);
9601 u1Tmp = rtl8723au_read8(padapter, 0x40);
9602 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
9604 DCMD_Printf(btCoexDbgBuf);
9606 u4Tmp[0] = rtl8723au_read32(padapter, 0x550);
9607 u1Tmp = rtl8723au_read8(padapter, 0x522);
9608 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x", "0x550(bcn contrl)/0x522", \
9610 DCMD_Printf(btCoexDbgBuf);
9612 u4Tmp[0] = rtl8723au_read32(padapter, 0x484);
9613 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
9615 DCMD_Printf(btCoexDbgBuf);
9617 u4Tmp[0] = rtl8723au_read32(padapter, 0x50);
9618 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
9620 DCMD_Printf(btCoexDbgBuf);
9622 u4Tmp[0] = rtl8723au_read32(padapter, 0xda0);
9623 u4Tmp[1] = rtl8723au_read32(padapter, 0xda4);
9624 u4Tmp[2] = rtl8723au_read32(padapter, 0xda8);
9625 u4Tmp[3] = rtl8723au_read32(padapter, 0xdac);
9626 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
9627 u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);
9628 DCMD_Printf(btCoexDbgBuf);
9630 u4Tmp[0] = rtl8723au_read32(padapter, 0x6c0);
9631 u4Tmp[1] = rtl8723au_read32(padapter, 0x6c4);
9632 u4Tmp[2] = rtl8723au_read32(padapter, 0x6c8);
9633 u1Tmp = rtl8723au_read8(padapter, 0x6cc);
9634 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
9635 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp);
9636 DCMD_Printf(btCoexDbgBuf);
9638 /* u4Tmp = rtl8723au_read32(padapter, 0x770); */
9639 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x770(Hi pri Rx[31:16]/Tx[15:0])", \
9640 pHalData->bt_coexist.halCoex8723.highPriorityRx,
9641 pHalData->bt_coexist.halCoex8723.highPriorityTx);
9642 DCMD_Printf(btCoexDbgBuf);
9643 /* u4Tmp = rtl8723au_read32(padapter, 0x774); */
9644 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x774(Lo pri Rx[31:16]/Tx[15:0])", \
9645 pHalData->bt_coexist.halCoex8723.lowPriorityRx,
9646 pHalData->bt_coexist.halCoex8723.lowPriorityTx);
9647 DCMD_Printf(btCoexDbgBuf);
9649 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang */
9650 u1Tmp = rtl8723au_read8(padapter, 0x41b);
9651 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x41b (hang chk == 0xf)", \
9653 DCMD_Printf(btCoexDbgBuf);
9654 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
9655 pHalData->LastHMEBoxNum);
9656 DCMD_Printf(btCoexDbgBuf);
9660 BTDM_8723ASignalCompensation(struct rtw_adapter *padapter,
9661 u8 *rssi_wifi, u8 *rssi_bt)
9663 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9664 BTDM_1AntSignalCompensation(padapter, rssi_wifi, rssi_bt);
9667 static void BTDM_8723AInit(struct rtw_adapter *padapter)
9669 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9670 BTDM_2AntParaInit(padapter);
9672 BTDM_1AntParaInit(padapter);
9675 static void BTDM_HWCoexAllOff8723A(struct rtw_adapter *padapter)
9677 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9678 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9680 if (pBtMgnt->ExtConfig.bManualControl)
9683 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9684 BTDM_2AntHwCoexAllOff8723A(padapter);
9687 static void BTDM_FWCoexAllOff8723A(struct rtw_adapter *padapter)
9689 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9690 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9692 if (pBtMgnt->ExtConfig.bManualControl)
9695 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9696 BTDM_2AntFwCoexAllOff8723A(padapter);
9699 static void BTDM_SWCoexAllOff8723A(struct rtw_adapter *padapter)
9701 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9702 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9704 if (pBtMgnt->ExtConfig.bManualControl)
9707 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9708 BTDM_2AntSwCoexAllOff8723A(padapter);
9712 BTDM_Set8723ABtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
9714 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9715 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9718 pBtCoex->TotalAntNum = Ant_x1;
9719 else if (antNum == 2)
9720 pBtCoex->TotalAntNum = Ant_x2;
9723 void rtl8723a_BT_lps_leave(struct rtw_adapter *padapter)
9725 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9726 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9728 if (pBtMgnt->ExtConfig.bManualControl)
9731 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9732 BTDM_1AntLpsLeave(padapter);
9735 static void BTDM_ForHalt8723A(struct rtw_adapter *padapter)
9737 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9738 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9740 if (pBtMgnt->ExtConfig.bManualControl)
9743 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9744 BTDM_1AntForHalt(padapter);
9747 static void BTDM_WifiScanNotify8723A(struct rtw_adapter *padapter, u8 scanType)
9749 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9750 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9752 if (pBtMgnt->ExtConfig.bManualControl)
9755 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9756 BTDM_1AntWifiScanNotify(padapter, scanType);
9760 BTDM_WifiAssociateNotify8723A(struct rtw_adapter *padapter, u8 action)
9762 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9763 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9765 if (pBtMgnt->ExtConfig.bManualControl)
9768 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9769 BTDM_1AntWifiAssociateNotify(padapter, action);
9773 BTDM_MediaStatusNotify8723A(struct rtw_adapter *padapter,
9774 enum rt_media_status mstatus)
9776 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9777 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9779 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatusNotify, %s\n",
9780 mstatus?"connect":"disconnect"));
9782 BTDM_SetFwChnlInfo(padapter, mstatus);
9784 if (pBtMgnt->ExtConfig.bManualControl)
9787 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9788 BTDM_1AntMediaStatusNotify(padapter, mstatus);
9791 static void BTDM_ForDhcp8723A(struct rtw_adapter *padapter)
9793 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9794 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9796 if (pBtMgnt->ExtConfig.bManualControl)
9799 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9800 BTDM_1AntForDhcp(padapter);
9803 bool rtl8723a_BT_using_antenna_1(struct rtw_adapter *padapter)
9805 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9811 static void BTDM_BTCoexist8723A(struct rtw_adapter *padapter)
9813 struct hal_data_8723a *pHalData;
9814 struct bt_30info *pBTInfo;
9815 struct bt_mgnt *pBtMgnt;
9816 struct bt_coexist_8723a *pBtCoex;
9818 pHalData = GET_HAL_DATA(padapter);
9819 pBTInfo = GET_BT_INFO(padapter);
9820 pBtMgnt = &pBTInfo->BtMgnt;
9821 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9823 RTPRINT(FBT, BT_TRACE, ("[BTCoex], beacon RSSI = 0x%x(%d)\n",
9824 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB,
9825 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB));
9827 btdm_BtHwCountersMonitor(padapter);
9828 btdm_BtEnableDisableCheck8723A(padapter);
9830 if (pBtMgnt->ExtConfig.bManualControl) {
9831 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9835 if (pBtCoex->bC2hBtInfoReqSent) {
9836 if (!rtl8723a_BT_enabled(padapter)) {
9837 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9839 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9840 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9843 btdm_BTCoexist8723AHandler(padapter);
9844 } else if (!rtl8723a_BT_enabled(padapter)) {
9845 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9846 btdm_BTCoexist8723AHandler(padapter);
9849 BTDM_QueryBtInformation(padapter);
9852 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
9854 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
9856 /* local function start with btdm_ */
9857 /* extern function start with BTDM_ */
9859 static void BTDM_SetAntenna(struct rtw_adapter *padapter, u8 who)
9865 struct rtw_adapter *padapter,
9871 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9872 u8 H2C_Parameter[3] = {0};
9874 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9877 H2C_Parameter[2] = 0;
9878 H2C_Parameter[1] = 0;
9879 H2C_Parameter[0] = 0;
9882 H2C_Parameter[2] |= 0x02; /* BIT1 */
9883 pHalData->bt_coexist.bFWCoexistAllOff = false;
9885 pHalData->bt_coexist.bInterruptOn = bInterruptOn;
9888 H2C_Parameter[2] |= 0x10; /* BIT4 */
9889 pHalData->bt_coexist.bFWCoexistAllOff = false;
9891 pHalData->bt_coexist.bSingleAntOn = bSingleAntOn;
9894 H2C_Parameter[2] |= 0x20; /* BIT5 */
9895 pHalData->bt_coexist.bFWCoexistAllOff = false;
9897 pHalData->bt_coexist.bMultiNAVOn = bMultiNAVOn;
9899 RTPRINT(FBT, BT_TRACE, ("[DM][BT], SingleAntenna =[%s:%s:%s], write 0xe = 0x%x\n",
9900 bSingleAntOn?"ON":"OFF", bInterruptOn?"ON":"OFF", bMultiNAVOn?"ON":"OFF",
9901 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
9904 void BTDM_CheckBTIdleChange1Ant(struct rtw_adapter *padapter)
9906 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9907 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9908 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9909 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
9910 u8 stateChange = false;
9911 u32 BT_Polling, Ratio_Act, Ratio_STA;
9912 u32 BT_Active, BT_State;
9913 u32 regBTActive = 0, regBTState = 0, regBTPolling = 0;
9915 if (!rtl8723a_BT_coexist(padapter))
9917 if (pBtMgnt->ExtConfig.bManualControl)
9919 if (pHalData->bt_coexist.BT_CoexistType != BT_CSR_BC8)
9921 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9924 /* The following we only consider CSR BC8 and fw version should be >= 62 */
9925 RTPRINT(FBT, BT_TRACE, ("[DM][BT], FirmwareVersion = 0x%x(%d)\n",
9926 pHalData->FirmwareVersion, pHalData->FirmwareVersion));
9927 regBTActive = REG_BT_ACTIVE;
9928 regBTState = REG_BT_STATE;
9929 if (pHalData->FirmwareVersion >= FW_VER_BT_REG1)
9930 regBTPolling = REG_BT_POLLING1;
9932 regBTPolling = REG_BT_POLLING;
9934 BT_Active = rtl8723au_read32(padapter, regBTActive);
9935 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Active(0x%x) =%x\n", regBTActive, BT_Active));
9936 BT_Active = BT_Active & 0x00ffffff;
9938 BT_State = rtl8723au_read32(padapter, regBTState);
9939 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_State(0x%x) =%x\n", regBTState, BT_State));
9940 BT_State = BT_State & 0x00ffffff;
9942 BT_Polling = rtl8723au_read32(padapter, regBTPolling);
9943 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Polling(0x%x) =%x\n", regBTPolling, BT_Polling));
9945 if (BT_Active == 0xffffffff && BT_State == 0xffffffff && BT_Polling == 0xffffffff)
9947 if (BT_Polling == 0)
9950 Ratio_Act = BT_Active*1000/BT_Polling;
9951 Ratio_STA = BT_State*1000/BT_Polling;
9953 pHalData->bt_coexist.Ratio_Tx = Ratio_Act;
9954 pHalData->bt_coexist.Ratio_PRI = Ratio_STA;
9956 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_Act =%d\n", Ratio_Act));
9957 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_STA =%d\n", Ratio_STA));
9959 if (Ratio_STA < 60 && Ratio_Act < 500) { /* BT PAN idle */
9960 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_IDLE;
9961 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9962 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9964 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_IDLE;
9967 /* Check if BT PAN (under BT 2.1) is uplink or downlink */
9968 if ((Ratio_Act/Ratio_STA) < 2) {
9970 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = true;
9971 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_UPLINK;
9972 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = false;
9973 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9975 /* BT PAN downlink */
9976 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9977 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9978 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9979 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9982 /* BT PAN downlink */
9983 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9984 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9985 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9986 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9990 /* Check BT is idle or not */
9991 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9992 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9993 pBtMgnt->ExtConfig.bBTBusy = false;
9994 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9996 if (Ratio_STA < 60) {
9997 pBtMgnt->ExtConfig.bBTBusy = false;
9998 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
10000 pBtMgnt->ExtConfig.bBTBusy = true;
10001 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_IDLE;
10005 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
10006 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
10007 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
10008 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
10009 BTDM_SetAntenna(padapter, BTDM_ANT_BT_IDLE);
10011 if (pBtMgnt->ExtConfig.MIN_BT_RSSI <= -5) {
10012 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_RSSI_LOW;
10013 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Low\n"));
10015 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
10016 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Normal\n"));
10020 if (pHalData->bt_coexist.bBTBusyTraffic != pBtMgnt->ExtConfig.bBTBusy) {
10021 /* BT idle or BT non-idle */
10022 pHalData->bt_coexist.bBTBusyTraffic = pBtMgnt->ExtConfig.bBTBusy;
10023 stateChange = true;
10027 if (!pBtMgnt->ExtConfig.bBTBusy)
10028 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
10030 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is non-idle\n"));
10032 if (!pBtMgnt->ExtConfig.bBTBusy) {
10033 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
10034 if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING|WIFI_SITE_MONITOR) == true)
10035 BTDM_SetAntenna(padapter, BTDM_ANT_WIFI);
10039 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
10041 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
10043 /* local function start with btdm_ */
10046 /* In the following, FW should be done before SW mechanism. */
10047 /* BTDM_Balance(), BTDM_DiminishWiFi(), BT_NAV() should be done */
10048 /* before BTDM_AGCTable(), BTDM_BBBackOffLevel(), btdm_DacSwing(). */
10050 /* extern function start with BTDM_ */
10054 struct rtw_adapter *padapter,
10061 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10062 u8 H2C_Parameter[3] = {0};
10064 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x2)
10067 if ((pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_RSSI_LOW) &&
10068 (DACSwingLevel == 0x20)) {
10069 RTPRINT(FBT, BT_TRACE, ("[BT]DiminishWiFi 0x20 original, but set 0x18 for Low RSSI!\n"));
10070 DACSwingLevel = 0x18;
10073 H2C_Parameter[2] = 0;
10074 H2C_Parameter[1] = DACSwingLevel;
10075 H2C_Parameter[0] = 0;
10077 H2C_Parameter[2] |= 0x01; /* BIT0 */
10079 H2C_Parameter[2] |= 0x02; /* BIT1 */
10080 pHalData->bt_coexist.bFWCoexistAllOff = false;
10083 H2C_Parameter[2] |= 0x08; /* BIT3 */
10084 pHalData->bt_coexist.bFWCoexistAllOff = false;
10087 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bDACOn = %s, bInterruptOn = %s, write 0xe = 0x%x\n",
10088 bDACOn?"ON":"OFF", bInterruptOn?"ON":"OFF",
10089 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10090 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bNAVOn = %s\n",
10091 bNAVOn?"ON":"OFF"));
10094 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
10096 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
10098 /* local function */
10099 static void btdm_ResetFWCoexState(struct rtw_adapter *padapter)
10101 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10103 pHalData->bt_coexist.CurrentState = 0;
10104 pHalData->bt_coexist.PreviousState = 0;
10107 static void btdm_InitBtCoexistDM(struct rtw_adapter *padapter)
10109 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10111 /* 20100415 Joseph: Restore RF register 0x1E and 0x1F value for further usage. */
10112 pHalData->bt_coexist.BtRfRegOrigin1E = PHY_QueryRFReg(padapter, PathA, RF_RCK1, bRFRegOffsetMask);
10113 pHalData->bt_coexist.BtRfRegOrigin1F = PHY_QueryRFReg(padapter, PathA, RF_RCK2, 0xf0);
10115 pHalData->bt_coexist.CurrentState = 0;
10116 pHalData->bt_coexist.PreviousState = 0;
10118 BTDM_8723AInit(padapter);
10119 pHalData->bt_coexist.bInitlized = true;
10123 /* extern function */
10125 void BTDM_CheckAntSelMode(struct rtw_adapter *padapter)
10129 void BTDM_FwC2hBtRssi(struct rtw_adapter *padapter, u8 *tmpBuf)
10131 BTDM_FwC2hBtRssi8723A(padapter, tmpBuf);
10134 void BTDM_DisplayBtCoexInfo(struct rtw_adapter *padapter)
10136 BTDM_Display8723ABtCoexInfo(padapter);
10139 void BTDM_RejectAPAggregatedPacket(struct rtw_adapter *padapter, u8 bReject)
10143 u8 BTDM_IsHT40(struct rtw_adapter *padapter)
10146 enum ht_channel_width bw;
10148 bw = padapter->mlmeextpriv.cur_bwmode;
10150 if (bw == HT_CHANNEL_WIDTH_20)
10152 else if (bw == HT_CHANNEL_WIDTH_40)
10158 u8 BTDM_Legacy(struct rtw_adapter *padapter)
10160 struct mlme_ext_priv *pmlmeext;
10161 u8 isLegacy = false;
10163 pmlmeext = &padapter->mlmeextpriv;
10164 if ((pmlmeext->cur_wireless_mode == WIRELESS_11B) ||
10165 (pmlmeext->cur_wireless_mode == WIRELESS_11G) ||
10166 (pmlmeext->cur_wireless_mode == WIRELESS_11BG))
10172 void BTDM_CheckWiFiState(struct rtw_adapter *padapter)
10174 struct hal_data_8723a *pHalData;
10175 struct mlme_priv *pmlmepriv;
10176 struct bt_30info *pBTInfo;
10177 struct bt_mgnt *pBtMgnt;
10179 pHalData = GET_HAL_DATA(padapter);
10180 pmlmepriv = &padapter->mlmepriv;
10181 pBTInfo = GET_BT_INFO(padapter);
10182 pBtMgnt = &pBTInfo->BtMgnt;
10184 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
10185 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_IDLE;
10187 if (pmlmepriv->LinkDetectInfo.bTxBusyTraffic)
10188 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_UPLINK;
10190 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10192 if (pmlmepriv->LinkDetectInfo.bRxBusyTraffic)
10193 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_DOWNLINK;
10195 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10197 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_IDLE;
10198 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10199 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10202 if (BTDM_Legacy(padapter)) {
10203 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_LEGACY;
10204 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10205 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10207 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_LEGACY;
10208 if (BTDM_IsHT40(padapter)) {
10209 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT40;
10210 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10212 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT20;
10213 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10217 if (pBtMgnt->BtOperationOn)
10218 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT30;
10220 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT30;
10223 s32 BTDM_GetRxSS(struct rtw_adapter *padapter)
10225 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10226 struct mlme_priv *pmlmepriv;
10227 struct hal_data_8723a *pHalData;
10228 s32 UndecoratedSmoothedPWDB = 0;
10230 pmlmepriv = &padapter->mlmepriv;
10231 pHalData = GET_HAL_DATA(padapter);
10233 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10234 UndecoratedSmoothedPWDB = GET_UNDECORATED_AVERAGE_RSSI(padapter);
10235 } else { /* associated entry pwdb */
10236 UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10237 /* pHalData->BT_EntryMinUndecoratedSmoothedPWDB */
10239 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxSS() = %d\n", UndecoratedSmoothedPWDB));
10240 return UndecoratedSmoothedPWDB;
10243 static s32 BTDM_GetRxBeaconSS(struct rtw_adapter *padapter)
10245 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10246 struct mlme_priv *pmlmepriv;
10247 struct hal_data_8723a *pHalData;
10248 s32 pwdbBeacon = 0;
10250 pmlmepriv = &padapter->mlmepriv;
10251 pHalData = GET_HAL_DATA(padapter);
10253 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10254 /* pwdbBeacon = pHalData->dmpriv.UndecoratedSmoothedBeacon; */
10255 pwdbBeacon = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10257 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxBeaconSS() = %d\n", pwdbBeacon));
10261 /* Get beacon rssi state */
10262 u8 BTDM_CheckCoexBcnRssiState(struct rtw_adapter *padapter, u8 levelNum,
10263 u8 RssiThresh, u8 RssiThresh1)
10265 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10266 s32 pwdbBeacon = 0;
10267 u8 bcnRssiState = 0;
10269 pwdbBeacon = BTDM_GetRxBeaconSS(padapter);
10271 if (levelNum == 2) {
10272 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10274 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10275 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10276 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10277 bcnRssiState = BT_RSSI_STATE_HIGH;
10278 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10279 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10280 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10282 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10283 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10286 if (pwdbBeacon < RssiThresh) {
10287 bcnRssiState = BT_RSSI_STATE_LOW;
10288 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10289 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10290 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10292 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10293 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10296 } else if (levelNum == 3) {
10297 if (RssiThresh > RssiThresh1) {
10298 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON thresh error!!\n"));
10299 return pHalData->bt_coexist.preRssiStateBeacon;
10302 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10303 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10304 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10305 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10306 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10307 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10308 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10309 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10311 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10312 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10314 } else if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_MEDIUM) ||
10315 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_MEDIUM)) {
10316 if (pwdbBeacon >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10317 bcnRssiState = BT_RSSI_STATE_HIGH;
10318 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10319 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10320 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10321 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10322 } else if (pwdbBeacon < RssiThresh) {
10323 bcnRssiState = BT_RSSI_STATE_LOW;
10324 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10325 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10326 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10327 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10329 bcnRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10330 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Medium\n"));
10333 if (pwdbBeacon < RssiThresh1) {
10334 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10335 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10336 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10337 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10338 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10340 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10341 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10346 pHalData->bt_coexist.preRssiStateBeacon = bcnRssiState;
10348 return bcnRssiState;
10351 u8 BTDM_CheckCoexRSSIState1(struct rtw_adapter *padapter, u8 levelNum,
10352 u8 RssiThresh, u8 RssiThresh1)
10354 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10355 s32 UndecoratedSmoothedPWDB = 0;
10356 u8 btRssiState = 0;
10358 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10360 if (levelNum == 2) {
10361 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10363 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10364 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10365 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10366 btRssiState = BT_RSSI_STATE_HIGH;
10367 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10368 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10369 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10371 btRssiState = BT_RSSI_STATE_STAY_LOW;
10372 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10375 if (UndecoratedSmoothedPWDB < RssiThresh) {
10376 btRssiState = BT_RSSI_STATE_LOW;
10377 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10378 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10379 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10381 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10382 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10385 } else if (levelNum == 3) {
10386 if (RssiThresh > RssiThresh1) {
10387 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 thresh error!!\n"));
10388 return pHalData->bt_coexist.preRssiState1;
10391 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10392 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10393 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10394 btRssiState = BT_RSSI_STATE_MEDIUM;
10395 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10396 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10397 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10398 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10400 btRssiState = BT_RSSI_STATE_STAY_LOW;
10401 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10403 } else if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_MEDIUM) ||
10404 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_MEDIUM)) {
10405 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10406 btRssiState = BT_RSSI_STATE_HIGH;
10407 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10408 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10409 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10410 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10411 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10412 btRssiState = BT_RSSI_STATE_LOW;
10413 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10414 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10415 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10416 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10418 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10419 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Medium\n"));
10422 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10423 btRssiState = BT_RSSI_STATE_MEDIUM;
10424 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10425 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10426 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10427 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10429 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10430 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10435 pHalData->bt_coexist.preRssiState1 = btRssiState;
10437 return btRssiState;
10440 u8 BTDM_CheckCoexRSSIState(struct rtw_adapter *padapter, u8 levelNum,
10441 u8 RssiThresh, u8 RssiThresh1)
10443 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10444 s32 UndecoratedSmoothedPWDB = 0;
10445 u8 btRssiState = 0;
10447 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10449 if (levelNum == 2) {
10450 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10452 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10453 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10454 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10455 btRssiState = BT_RSSI_STATE_HIGH;
10456 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10457 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10458 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10460 btRssiState = BT_RSSI_STATE_STAY_LOW;
10461 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10464 if (UndecoratedSmoothedPWDB < RssiThresh) {
10465 btRssiState = BT_RSSI_STATE_LOW;
10466 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10467 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10468 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10470 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10471 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10474 } else if (levelNum == 3) {
10475 if (RssiThresh > RssiThresh1) {
10476 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI thresh error!!\n"));
10477 return pHalData->bt_coexist.preRssiState;
10480 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10481 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10482 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10483 btRssiState = BT_RSSI_STATE_MEDIUM;
10484 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10485 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10486 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10487 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10489 btRssiState = BT_RSSI_STATE_STAY_LOW;
10490 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10492 } else if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_MEDIUM) ||
10493 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_MEDIUM)) {
10494 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10495 btRssiState = BT_RSSI_STATE_HIGH;
10496 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10497 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10498 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10499 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10500 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10501 btRssiState = BT_RSSI_STATE_LOW;
10502 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10503 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10504 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10505 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10507 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10508 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Medium\n"));
10511 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10512 btRssiState = BT_RSSI_STATE_MEDIUM;
10513 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10514 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10515 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10516 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10518 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10519 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10524 pHalData->bt_coexist.preRssiState = btRssiState;
10526 return btRssiState;
10529 bool rtl8723a_BT_disable_EDCA_turbo(struct rtw_adapter *padapter)
10531 struct bt_mgnt *pBtMgnt;
10532 struct hal_data_8723a *pHalData;
10533 u8 bBtChangeEDCA = false;
10534 u32 EDCA_BT_BE = 0x5ea42b, cur_EDCA_reg;
10537 pHalData = GET_HAL_DATA(padapter);
10538 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10540 if (!rtl8723a_BT_coexist(padapter)) {
10542 pHalData->bt_coexist.lastBtEdca = 0;
10545 if (!((pBtMgnt->bSupportProfile) ||
10546 (pHalData->bt_coexist.BT_CoexistType == BT_CSR_BC8))) {
10548 pHalData->bt_coexist.lastBtEdca = 0;
10552 if (rtl8723a_BT_using_antenna_1(padapter)) {
10554 pHalData->bt_coexist.lastBtEdca = 0;
10558 if (pHalData->bt_coexist.exec_cnt < 3)
10559 pHalData->bt_coexist.exec_cnt++;
10561 pHalData->bt_coexist.bEDCAInitialized = true;
10563 /* When BT is non idle */
10564 if (!(pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)) {
10565 RTPRINT(FBT, BT_TRACE, ("BT state non idle, set bt EDCA\n"));
10567 /* aggr_num = 0x0909; */
10568 if (pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA) {
10569 bBtChangeEDCA = true;
10570 pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA = false;
10571 pHalData->dmpriv.prv_traffic_idx = 3;
10573 cur_EDCA_reg = rtl8723au_read32(padapter, REG_EDCA_BE_PARAM);
10575 if (cur_EDCA_reg != EDCA_BT_BE)
10576 bBtChangeEDCA = true;
10577 if (bBtChangeEDCA || !pHalData->bt_coexist.bEDCAInitialized) {
10578 rtl8723au_write32(padapter, REG_EDCA_BE_PARAM,
10580 pHalData->bt_coexist.lastBtEdca = EDCA_BT_BE;
10584 RTPRINT(FBT, BT_TRACE, ("BT state idle, set original EDCA\n"));
10585 pHalData->bt_coexist.lastBtEdca = 0;
10593 struct rtw_adapter *padapter,
10599 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10600 u8 H2C_Parameter[3] = {0};
10603 H2C_Parameter[2] = 1;
10604 H2C_Parameter[1] = ms1;
10605 H2C_Parameter[0] = ms0;
10606 pHalData->bt_coexist.bFWCoexistAllOff = false;
10608 H2C_Parameter[2] = 0;
10609 H2C_Parameter[1] = 0;
10610 H2C_Parameter[0] = 0;
10612 pHalData->bt_coexist.bBalanceOn = bBalanceOn;
10614 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Balance =[%s:%dms:%dms], write 0xc = 0x%x\n",
10615 bBalanceOn?"ON":"OFF", ms0, ms1,
10616 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10618 FillH2CCmd(padapter, 0xc, 3, H2C_Parameter);
10621 void BTDM_AGCTable(struct rtw_adapter *padapter, u8 type)
10623 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10624 if (type == BT_AGCTABLE_OFF) {
10625 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable Off!\n"));
10626 rtl8723au_write32(padapter, 0xc78, 0x641c0001);
10627 rtl8723au_write32(padapter, 0xc78, 0x631d0001);
10628 rtl8723au_write32(padapter, 0xc78, 0x621e0001);
10629 rtl8723au_write32(padapter, 0xc78, 0x611f0001);
10630 rtl8723au_write32(padapter, 0xc78, 0x60200001);
10632 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x32000);
10633 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x71000);
10634 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xb0000);
10635 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xfc000);
10636 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x30355);
10638 pHalData->bt_coexist.b8723aAgcTableOn = false;
10639 } else if (type == BT_AGCTABLE_ON) {
10640 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable On!\n"));
10641 rtl8723au_write32(padapter, 0xc78, 0x4e1c0001);
10642 rtl8723au_write32(padapter, 0xc78, 0x4d1d0001);
10643 rtl8723au_write32(padapter, 0xc78, 0x4c1e0001);
10644 rtl8723au_write32(padapter, 0xc78, 0x4b1f0001);
10645 rtl8723au_write32(padapter, 0xc78, 0x4a200001);
10647 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xdc000);
10648 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x90000);
10649 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x51000);
10650 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x12000);
10651 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x00355);
10653 pHalData->bt_coexist.b8723aAgcTableOn = true;
10655 pHalData->bt_coexist.bSWCoexistAllOff = false;
10659 void BTDM_BBBackOffLevel(struct rtw_adapter *padapter, u8 type)
10661 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10663 if (type == BT_BB_BACKOFF_OFF) {
10664 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel Off!\n"));
10665 rtl8723au_write32(padapter, 0xc04, 0x3a05611);
10666 } else if (type == BT_BB_BACKOFF_ON) {
10667 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel On!\n"));
10668 rtl8723au_write32(padapter, 0xc04, 0x3a07611);
10669 pHalData->bt_coexist.bSWCoexistAllOff = false;
10673 void BTDM_FWCoexAllOff(struct rtw_adapter *padapter)
10675 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10677 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff()\n"));
10678 if (pHalData->bt_coexist.bFWCoexistAllOff)
10680 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff(), real Do\n"));
10682 BTDM_FWCoexAllOff8723A(padapter);
10684 pHalData->bt_coexist.bFWCoexistAllOff = true;
10687 void BTDM_SWCoexAllOff(struct rtw_adapter *padapter)
10689 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10691 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff()\n"));
10692 if (pHalData->bt_coexist.bSWCoexistAllOff)
10694 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff(), real Do\n"));
10695 BTDM_SWCoexAllOff8723A(padapter);
10697 pHalData->bt_coexist.bSWCoexistAllOff = true;
10700 void BTDM_HWCoexAllOff(struct rtw_adapter *padapter)
10702 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10704 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff()\n"));
10705 if (pHalData->bt_coexist.bHWCoexistAllOff)
10707 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff(), real Do\n"));
10709 BTDM_HWCoexAllOff8723A(padapter);
10711 pHalData->bt_coexist.bHWCoexistAllOff = true;
10714 void BTDM_CoexAllOff(struct rtw_adapter *padapter)
10716 BTDM_FWCoexAllOff(padapter);
10717 BTDM_SWCoexAllOff(padapter);
10718 BTDM_HWCoexAllOff(padapter);
10721 void rtl8723a_BT_disable_coexist(struct rtw_adapter *padapter)
10723 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
10725 if (!rtl8723a_BT_coexist(padapter))
10728 /* 8723 1Ant doesn't need to turn off bt coexist mechanism. */
10729 if (rtl8723a_BT_using_antenna_1(padapter))
10732 /* Before enter IPS, turn off FW BT Co-exist mechanism */
10733 if (ppwrctrl->reg_rfoff == rf_on) {
10734 RTPRINT(FBT, BT_TRACE, ("[BT][DM], Before enter IPS, turn off all Coexist DM\n"));
10735 btdm_ResetFWCoexState(padapter);
10736 BTDM_CoexAllOff(padapter);
10737 BTDM_SetAntenna(padapter, BTDM_ANT_BT);
10741 void BTDM_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
10743 BTDM_8723ASignalCompensation(padapter, rssi_wifi, rssi_bt);
10746 void rtl8723a_BT_do_coexist(struct rtw_adapter *padapter)
10748 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10750 if (!rtl8723a_BT_coexist(padapter)) {
10751 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT not exists!!\n"));
10755 if (!pHalData->bt_coexist.bInitlized) {
10756 RTPRINT(FBT, BT_TRACE, ("[DM][BT], btdm_InitBtCoexistDM()\n"));
10757 btdm_InitBtCoexistDM(padapter);
10760 RTPRINT(FBT, BT_TRACE, ("\n\n[DM][BT], BTDM start!!\n"));
10762 BTDM_PWDBMonitor(padapter);
10764 RTPRINT(FBT, BT_TRACE, ("[DM][BT], HW type is 8723\n"));
10765 BTDM_BTCoexist8723A(padapter);
10766 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BTDM end!!\n\n"));
10769 void BTDM_UpdateCoexState(struct rtw_adapter *padapter)
10771 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10773 if (!BTDM_IsSameCoexistState(padapter)) {
10774 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x, changeBits = 0x%"i64fmt"x\n",
10775 pHalData->bt_coexist.PreviousState,
10776 pHalData->bt_coexist.CurrentState,
10777 (pHalData->bt_coexist.PreviousState^pHalData->bt_coexist.CurrentState)));
10778 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
10782 u8 BTDM_IsSameCoexistState(struct rtw_adapter *padapter)
10784 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10786 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState) {
10789 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Coexist state changed!!\n"));
10794 void BTDM_PWDBMonitor(struct rtw_adapter *padapter)
10796 struct bt_30info *pBTInfo = GET_BT_INFO(GetDefaultAdapter(padapter));
10797 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10798 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10799 u8 H2C_Parameter[3] = {0};
10800 s32 tmpBTEntryMaxPWDB = 0, tmpBTEntryMinPWDB = 0xff;
10803 if (pBtMgnt->BtOperationOn) {
10804 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
10805 if (pBTInfo->BtAsocEntry[i].bUsed) {
10806 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB < tmpBTEntryMinPWDB)
10807 tmpBTEntryMinPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10808 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB > tmpBTEntryMaxPWDB)
10809 tmpBTEntryMaxPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10810 /* Report every BT connection (HS mode) RSSI to FW */
10811 H2C_Parameter[2] = (u8)(pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB & 0xFF);
10812 H2C_Parameter[0] = (MAX_FW_SUPPORT_MACID_NUM-1-i);
10813 RTPRINT(FDM, DM_BT30, ("RSSI report for BT[%d], H2C_Par = 0x%x\n", i, H2C_Parameter[0]));
10814 FillH2CCmd(padapter, RSSI_SETTING_EID, 3, H2C_Parameter);
10815 RTPRINT_ADDR(FDM, (DM_PWDB|DM_BT30), ("BT_Entry Mac :"),
10816 pBTInfo->BtAsocEntry[i].BTRemoteMACAddr)
10817 RTPRINT(FDM, (DM_PWDB|DM_BT30),
10818 ("BT rx pwdb[%d] = 0x%x(%d)\n", i,
10819 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB,
10820 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB));
10823 if (tmpBTEntryMaxPWDB != 0) { /* If associated entry is found */
10824 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = tmpBTEntryMaxPWDB;
10825 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMaxPWDB = 0x%x(%d)\n",
10826 tmpBTEntryMaxPWDB, tmpBTEntryMaxPWDB));
10828 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = 0;
10830 if (tmpBTEntryMinPWDB != 0xff) { /* If associated entry is found */
10831 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = tmpBTEntryMinPWDB;
10832 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMinPWDB = 0x%x(%d)\n",
10833 tmpBTEntryMinPWDB, tmpBTEntryMinPWDB));
10835 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = 0;
10840 u8 BTDM_IsBTBusy(struct rtw_adapter *padapter)
10842 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10843 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10845 if (pBtMgnt->ExtConfig.bBTBusy)
10851 u8 BTDM_IsWifiBusy(struct rtw_adapter *padapter)
10853 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10854 struct mlme_priv *pmlmepriv = &GetDefaultAdapter(padapter)->mlmepriv;
10855 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10856 struct bt_traffic *pBtTraffic = &pBTInfo->BtTraffic;
10858 if (pmlmepriv->LinkDetectInfo.bBusyTraffic ||
10859 pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic ||
10860 pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic)
10866 u8 BTDM_IsCoexistStateChanged(struct rtw_adapter *padapter)
10868 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10870 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState)
10876 u8 BTDM_IsWifiUplink(struct rtw_adapter *padapter)
10878 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10879 struct mlme_priv *pmlmepriv;
10880 struct bt_30info *pBTInfo;
10881 struct bt_traffic *pBtTraffic;
10883 pmlmepriv = &padapter->mlmepriv;
10884 pBTInfo = GET_BT_INFO(padapter);
10885 pBtTraffic = &pBTInfo->BtTraffic;
10887 if ((pmlmepriv->LinkDetectInfo.bTxBusyTraffic) ||
10888 (pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic))
10894 u8 BTDM_IsWifiDownlink(struct rtw_adapter *padapter)
10896 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10897 struct mlme_priv *pmlmepriv;
10898 struct bt_30info *pBTInfo;
10899 struct bt_traffic *pBtTraffic;
10901 pmlmepriv = &padapter->mlmepriv;
10902 pBTInfo = GET_BT_INFO(padapter);
10903 pBtTraffic = &pBTInfo->BtTraffic;
10905 if ((pmlmepriv->LinkDetectInfo.bRxBusyTraffic) ||
10906 (pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic))
10912 u8 BTDM_IsBTHSMode(struct rtw_adapter *padapter)
10914 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10915 struct hal_data_8723a *pHalData;
10916 struct bt_mgnt *pBtMgnt;
10918 pHalData = GET_HAL_DATA(padapter);
10919 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10921 if (pBtMgnt->BtOperationOn)
10927 u8 BTDM_IsBTUplink(struct rtw_adapter *padapter)
10929 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10931 if (pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic)
10937 u8 BTDM_IsBTDownlink(struct rtw_adapter *padapter)
10939 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10941 if (pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic)
10947 void BTDM_AdjustForBtOperation(struct rtw_adapter *padapter)
10949 RTPRINT(FBT, BT_TRACE, ("[BT][DM], BTDM_AdjustForBtOperation()\n"));
10950 BTDM_AdjustForBtOperation8723A(padapter);
10953 void BTDM_SetBtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
10955 BTDM_Set8723ABtCoexCurrAntNum(padapter, antNum);
10958 void BTDM_ForHalt(struct rtw_adapter *padapter)
10960 if (!rtl8723a_BT_coexist(padapter))
10963 BTDM_ForHalt8723A(padapter);
10964 GET_HAL_DATA(padapter)->bt_coexist.bInitlized = false;
10967 void BTDM_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
10969 if (!rtl8723a_BT_coexist(padapter))
10972 BTDM_WifiScanNotify8723A(padapter, scanType);
10975 void BTDM_WifiAssociateNotify(struct rtw_adapter *padapter, u8 action)
10977 if (!rtl8723a_BT_coexist(padapter))
10980 BTDM_WifiAssociateNotify8723A(padapter, action);
10983 void rtl8723a_BT_mediastatus_notify(struct rtw_adapter *padapter,
10984 enum rt_media_status mstatus)
10986 if (!rtl8723a_BT_coexist(padapter))
10989 BTDM_MediaStatusNotify8723A(padapter, mstatus);
10992 void rtl8723a_BT_specialpacket_notify(struct rtw_adapter *padapter)
10994 if (!rtl8723a_BT_coexist(padapter))
10997 BTDM_ForDhcp8723A(padapter);
11000 void BTDM_ResetActionProfileState(struct rtw_adapter *padapter)
11002 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11004 pHalData->bt_coexist.CurrentState &= ~\
11005 (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP|
11006 BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_SCO);
11009 u8 BTDM_IsActionSCO(struct rtw_adapter *padapter)
11011 struct hal_data_8723a *pHalData;
11012 struct bt_30info *pBTInfo;
11013 struct bt_mgnt *pBtMgnt;
11014 struct bt_dgb *pBtDbg;
11017 pHalData = GET_HAL_DATA(padapter);
11018 pBTInfo = GET_BT_INFO(padapter);
11019 pBtMgnt = &pBTInfo->BtMgnt;
11020 pBtDbg = &pBTInfo->BtDbg;
11023 if (pBtDbg->dbgCtrl) {
11024 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_SCO) {
11025 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
11029 if (pBtMgnt->ExtConfig.NumberOfSCO > 0) {
11030 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
11037 u8 BTDM_IsActionHID(struct rtw_adapter *padapter)
11039 struct bt_30info *pBTInfo;
11040 struct hal_data_8723a *pHalData;
11041 struct bt_mgnt *pBtMgnt;
11042 struct bt_dgb *pBtDbg;
11045 pHalData = GET_HAL_DATA(padapter);
11046 pBTInfo = GET_BT_INFO(padapter);
11047 pBtMgnt = &pBTInfo->BtMgnt;
11048 pBtDbg = &pBTInfo->BtDbg;
11051 if (pBtDbg->dbgCtrl) {
11052 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID) {
11053 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11057 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11058 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11059 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11066 u8 BTDM_IsActionA2DP(struct rtw_adapter *padapter)
11068 struct hal_data_8723a *pHalData;
11069 struct bt_30info *pBTInfo;
11070 struct bt_mgnt *pBtMgnt;
11071 struct bt_dgb *pBtDbg;
11074 pHalData = GET_HAL_DATA(padapter);
11075 pBTInfo = GET_BT_INFO(padapter);
11076 pBtMgnt = &pBTInfo->BtMgnt;
11077 pBtDbg = &pBTInfo->BtDbg;
11080 if (pBtDbg->dbgCtrl) {
11081 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_A2DP) {
11082 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11086 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP) &&
11087 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11088 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11095 u8 BTDM_IsActionPAN(struct rtw_adapter *padapter)
11097 struct hal_data_8723a *pHalData;
11098 struct bt_30info *pBTInfo;
11099 struct bt_mgnt *pBtMgnt;
11100 struct bt_dgb *pBtDbg;
11103 pHalData = GET_HAL_DATA(padapter);
11104 pBTInfo = GET_BT_INFO(padapter);
11105 pBtMgnt = &pBTInfo->BtMgnt;
11106 pBtDbg = &pBTInfo->BtDbg;
11109 if (pBtDbg->dbgCtrl) {
11110 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN) {
11111 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11115 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
11116 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11117 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11124 u8 BTDM_IsActionHIDA2DP(struct rtw_adapter *padapter)
11126 struct hal_data_8723a *pHalData;
11127 struct bt_30info *pBTInfo;
11128 struct bt_mgnt *pBtMgnt;
11129 struct bt_dgb *pBtDbg;
11132 pHalData = GET_HAL_DATA(padapter);
11133 pBTInfo = GET_BT_INFO(padapter);
11134 pBtMgnt = &pBTInfo->BtMgnt;
11135 pBtDbg = &pBTInfo->BtDbg;
11138 if (pBtDbg->dbgCtrl) {
11139 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_A2DP) {
11140 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11144 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11145 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11146 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11153 u8 BTDM_IsActionHIDPAN(struct rtw_adapter *padapter)
11155 struct hal_data_8723a *pHalData;
11156 struct bt_30info *pBTInfo;
11157 struct bt_dgb *pBtDbg;
11160 pHalData = GET_HAL_DATA(padapter);
11161 pBTInfo = GET_BT_INFO(padapter);
11162 pBtDbg = &pBTInfo->BtDbg;
11165 if (pBtDbg->dbgCtrl) {
11166 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_PAN) {
11167 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11171 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11172 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
11173 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11180 u8 BTDM_IsActionPANA2DP(struct rtw_adapter *padapter)
11182 struct hal_data_8723a *pHalData;
11183 struct bt_30info *pBTInfo;
11184 struct bt_dgb *pBtDbg;
11187 pHalData = GET_HAL_DATA(padapter);
11188 pBTInfo = GET_BT_INFO(padapter);
11189 pBtDbg = &pBTInfo->BtDbg;
11192 if (pBtDbg->dbgCtrl) {
11193 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN_A2DP) {
11194 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11198 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) && BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11199 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11206 bool rtl8723a_BT_enabled(struct rtw_adapter *padapter)
11208 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11210 if (pHalData->bt_coexist.bCurBtDisabled)
11216 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
11218 /* ===== Below this line is sync from SD7 driver HAL/HalBT.c ===== */
11221 /*local function */
11224 static void halbt_InitHwConfig8723A(struct rtw_adapter *padapter)
11229 /*extern function */
11231 u8 HALBT_GetPGAntNum(struct rtw_adapter *padapter)
11233 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11235 return pHalData->bt_coexist.BT_Ant_Num;
11238 void HALBT_SetKey(struct rtw_adapter *padapter, u8 EntryNum)
11240 struct bt_30info *pBTinfo;
11241 struct bt_asoc_entry *pBtAssocEntry;
11244 pBTinfo = GET_BT_INFO(padapter);
11245 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11247 pBtAssocEntry->HwCAMIndex = BT_HWCAM_STAR + EntryNum;
11249 usConfig = CAM_VALID | (CAM_AES << 2);
11250 rtl8723a_cam_write(padapter, pBtAssocEntry->HwCAMIndex, usConfig,
11251 pBtAssocEntry->BTRemoteMACAddr,
11252 pBtAssocEntry->PTK + TKIP_ENC_KEY_POS);
11255 void HALBT_RemoveKey(struct rtw_adapter *padapter, u8 EntryNum)
11257 struct bt_30info *pBTinfo;
11258 struct bt_asoc_entry *pBtAssocEntry;
11260 pBTinfo = GET_BT_INFO(padapter);
11261 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11263 if (pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex != 0) {
11264 /* ToDo : add New HALBT_RemoveKey function !! */
11265 if (pBtAssocEntry->HwCAMIndex >= BT_HWCAM_STAR &&
11266 pBtAssocEntry->HwCAMIndex < HALF_CAM_ENTRY)
11267 rtl8723a_cam_empty_entry(padapter,
11268 pBtAssocEntry->HwCAMIndex);
11269 pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex = 0;
11273 void rtl8723a_BT_init_hal_vars(struct rtw_adapter *padapter)
11275 struct hal_data_8723a *pHalData;
11277 pHalData = GET_HAL_DATA(padapter);
11279 pHalData->bt_coexist.BluetoothCoexist = pHalData->EEPROMBluetoothCoexist;
11280 pHalData->bt_coexist.BT_Ant_Num = pHalData->EEPROMBluetoothAntNum;
11281 pHalData->bt_coexist.BT_CoexistType = pHalData->EEPROMBluetoothType;
11282 pHalData->bt_coexist.BT_Ant_isolation = pHalData->EEPROMBluetoothAntIsolation;
11283 pHalData->bt_coexist.bt_radiosharedtype = pHalData->EEPROMBluetoothRadioShared;
11285 RT_TRACE(_module_hal_init_c_, _drv_info_,
11286 ("BT Coexistance = 0x%x\n", rtl8723a_BT_coexist(padapter)));
11288 if (rtl8723a_BT_coexist(padapter)) {
11289 if (pHalData->bt_coexist.BT_Ant_Num == Ant_x2) {
11290 BTDM_SetBtCoexCurrAntNum(padapter, 2);
11291 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx2\n"));
11292 } else if (pHalData->bt_coexist.BT_Ant_Num == Ant_x1) {
11293 BTDM_SetBtCoexCurrAntNum(padapter, 1);
11294 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx1\n"));
11296 pHalData->bt_coexist.bBTBusyTraffic = false;
11297 pHalData->bt_coexist.bBTTrafficModeSet = false;
11298 pHalData->bt_coexist.bBTNonTrafficModeSet = false;
11299 pHalData->bt_coexist.CurrentState = 0;
11300 pHalData->bt_coexist.PreviousState = 0;
11302 RT_TRACE(_module_hal_init_c_, _drv_info_,
11303 ("bt_radiosharedType = 0x%x\n",
11304 pHalData->bt_coexist.bt_radiosharedtype));
11308 bool rtl8723a_BT_coexist(struct rtw_adapter *padapter)
11310 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11312 if (pHalData->bt_coexist.BluetoothCoexist)
11318 u8 HALBT_BTChipType(struct rtw_adapter *padapter)
11320 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11322 return pHalData->bt_coexist.BT_CoexistType;
11325 void rtl8723a_BT_init_hwconfig(struct rtw_adapter *padapter)
11327 halbt_InitHwConfig8723A(padapter);
11328 rtl8723a_BT_do_coexist(padapter);
11331 void HALBT_SetRtsCtsNoLenLimit(struct rtw_adapter *padapter)
11335 /* ===== End of sync from SD7 driver HAL/HalBT.c ===== */
11337 void rtl8723a_dual_antenna_detection(struct rtw_adapter *padapter)
11339 struct hal_data_8723a *pHalData;
11340 struct dm_odm_t *pDM_Odm;
11341 struct sw_ant_sw *pDM_SWAT_Table;
11344 pHalData = GET_HAL_DATA(padapter);
11345 pDM_Odm = &pHalData->odmpriv;
11346 pDM_SWAT_Table = &pDM_Odm->DM_SWAT_Table;
11349 /* <Roger_Notes> RTL8723A Single and Dual antenna dynamic detection
11350 mechanism when RF power state is on. */
11351 /* We should take power tracking, IQK, LCK, RCK RF read/write
11352 operation into consideration. */
11355 if (!pHalData->bAntennaDetected) {
11356 u8 btAntNum = BT_GetPGAntNum(padapter);
11358 /* Set default antenna B status */
11359 if (btAntNum == Ant_x2)
11360 pDM_SWAT_Table->ANTB_ON = true;
11361 else if (btAntNum == Ant_x1)
11362 pDM_SWAT_Table->ANTB_ON = false;
11364 pDM_SWAT_Table->ANTB_ON = true;
11366 if (pHalData->CustomerID != RT_CID_TOSHIBA) {
11367 for (i = 0; i < MAX_ANTENNA_DETECTION_CNT; i++) {
11368 if (ODM_SingleDualAntennaDetection
11369 (&pHalData->odmpriv, ANTTESTALL) == true)
11373 /* Set default antenna number for BT coexistence */
11374 if (btAntNum == Ant_x2)
11375 BT_SetBtCoexCurrAntNum(padapter,
11379 pHalData->bAntennaDetected = true;