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>
21 #ifdef CONFIG_8723AU_BT_COEXIST
23 u32 BTCoexDbgLevel = _bt_dbg_off_;
25 #define RTPRINT(_Comp, _Level, Fmt)\
27 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
32 #define RTPRINT_ADDR(dbgtype, dbgflag, printstr, _Ptr)\
33 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
35 u8 *ptr = (u8 *)_Ptr; \
38 for (__i = 0; __i < 6; __i++) \
39 printk("%02X%s", ptr[__i], (__i == 5)?"":"-"); \
42 #define RTPRINT_DATA(dbgtype, dbgflag, _TitleString, _HexData, _HexDataLen)\
43 if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
45 u8 *ptr = (u8 *)_HexData; \
46 printk(_TitleString); \
47 for (__i = 0; __i < (u32)_HexDataLen; __i++) { \
48 printk("%02X%s", ptr[__i], (((__i + 1) % 4) == 0)?" ":" ");\
49 if (((__i + 1) % 16) == 0) \
54 /* Added by Annie, 2005-11-22. */
55 #define MAX_STR_LEN 64
56 /* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. */
57 #define PRINTABLE(_ch) (_ch >= ' ' && _ch <= '~')
58 #define RT_PRINT_STR(_Comp, _Level, _TitleString, _Ptr, _Len) \
61 u8 buffer[MAX_STR_LEN]; \
62 u32 length = (_Len < MAX_STR_LEN) ? _Len : (MAX_STR_LEN-1);\
63 memset(buffer, 0, MAX_STR_LEN); \
64 memcpy(buffer, (u8 *)_Ptr, length); \
65 for (__i = 0; __i < length; __i++) { \
66 if (!PRINTABLE(buffer[__i])) \
69 buffer[length] = '\0'; \
70 printk(_TitleString); \
71 printk(": %d, <%s>\n", _Len, buffer); \
75 #define DCMD_Printf(...)
76 #define RT_ASSERT(...)
78 #define rsprintf snprintf
80 #define GetDefaultAdapter(padapter) padapter
82 #define PlatformZeroMemory(ptr, sz) memset(ptr, 0, sz)
84 #define PlatformProcessHCICommands(...)
85 #define PlatformTxBTQueuedPackets(...)
86 #define PlatformIndicateBTACLData(...) (RT_STATUS_SUCCESS)
87 #define PlatformAcquireSpinLock(padapter, type)
88 #define PlatformReleaseSpinLock(padapter, type)
90 #define GET_UNDECORATED_AVERAGE_RSSI(padapter) \
91 (GET_HAL_DATA(padapter)->dmpriv.EntryMinUndecoratedSmoothedPWDB)
92 #define RT_RF_CHANGE_SOURCE u32
103 #ifdef __BT_C__ /* COMMOM/BT.c */
104 /* ===== Below this line is sync from SD7 driver COMMOM/BT.c ===== */
106 static u8 BT_Operation(struct rtw_adapter *padapter)
108 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
109 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
111 if (pBtMgnt->BtOperationOn)
117 static u8 BT_IsLegalChannel(struct rtw_adapter *padapter, u8 channel)
119 struct rt_channel_info *pChanneList = NULL;
122 pChanneList = padapter->mlmeextpriv.channel_set;
123 channelLen = padapter->mlmeextpriv.max_chan_nums;
125 for (i = 0; i < channelLen; i++) {
126 RTPRINT(FIOCTL, IOCTL_STATE,
127 ("Check if chnl(%d) in channel plan contains bt target chnl(%d) for BT connection\n",
128 pChanneList[i].ChannelNum, channel));
129 if ((channel == pChanneList[i].ChannelNum) ||
130 (channel == pChanneList[i].ChannelNum + 2))
136 void BT_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
138 BTDM_SignalCompensation(padapter, rssi_wifi, rssi_bt);
141 void BT_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
143 BTHCI_WifiScanNotify(padapter, scanType);
144 BTDM_CheckAntSelMode(padapter);
145 BTDM_WifiScanNotify(padapter, scanType);
148 void BT_WifiAssociateNotify(struct rtw_adapter *padapter, u8 action)
151 /* true = associate start */
152 /* false = associate finished */
154 BTDM_CheckAntSelMode(padapter);
156 BTDM_WifiAssociateNotify(padapter, action);
159 void BT_WifiMediaStatusNotify(struct rtw_adapter *padapter, enum rt_media_status mstatus)
161 BTDM_MediaStatusNotify(padapter, mstatus);
164 void BT_SpecialPacketNotify(struct rtw_adapter *padapter)
166 BTDM_ForDhcp(padapter);
169 void BT_HaltProcess(struct rtw_adapter *padapter)
171 BTDM_ForHalt(padapter);
174 void BT_LpsLeave(struct rtw_adapter *padapter)
176 BTDM_LpsLeave(padapter);
179 /* ===== End of sync from SD7 driver COMMOM/BT.c ===== */
182 #ifdef __BT_HANDLEPACKET_C__ /* COMMOM/bt_handlepacket.c */
183 /* ===== Below this line is sync from SD7 driver COMMOM/bt_handlepacket.c ===== */
185 /* ===== End of sync from SD7 driver COMMOM/bt_handlepacket.c ===== */
188 #ifdef __BT_HCI_C__ /* COMMOM/bt_hci.c */
191 #define UINT64_C(v) (v)
193 #define FillOctetString(_os, _octet, _len) \
194 (_os).Octet = (u8 *)(_octet); \
195 (_os).Length = (_len);
197 static enum rt_status PlatformIndicateBTEvent(
198 struct rtw_adapter *padapter,
203 enum rt_status rt_status = RT_STATUS_FAILURE;
205 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event start, %d bytes data to Transferred!!\n", dataLen));
206 RTPRINT_DATA(FIOCTL, IOCTL_BT_EVENT_DETAIL, "To transfer Hex Data :\n",
209 BT_EventParse(padapter, pEvntData, dataLen);
211 printk(KERN_WARNING "%s: Linux has no way to report BT event!!\n", __func__);
213 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL, ("BT event end, %s\n",
214 (rt_status == RT_STATUS_SUCCESS) ? "SUCCESS" : "FAIL"));
219 /* ===== Below this line is sync from SD7 driver COMMOM/bt_hci.c ===== */
221 static u8 bthci_GetLocalChannel(struct rtw_adapter *padapter)
223 return padapter->mlmeextpriv.cur_channel;
226 static u8 bthci_GetCurrentEntryNum(struct rtw_adapter *padapter, u8 PhyHandle)
228 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
231 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
232 if ((pBTInfo->BtAsocEntry[i].bUsed) &&
233 (pBTInfo->BtAsocEntry[i].PhyLinkCmdData.BtPhyLinkhandle == PhyHandle))
240 static void bthci_DecideBTChannel(struct rtw_adapter *padapter, u8 EntryNum)
242 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
243 struct mlme_priv *pmlmepriv;
244 struct bt_30info *pBTInfo;
245 struct bt_mgnt *pBtMgnt;
246 struct bt_hci_info *pBtHciInfo;
247 struct chnl_txpower_triple *pTriple_subband = NULL;
248 struct common_triple *pTriple;
249 u8 i, j, localchnl, firstRemoteLegalChnlInTriplet = 0;
250 u8 regulatory_skipLen = 0;
251 u8 subbandTripletCnt = 0;
253 pmlmepriv = &padapter->mlmepriv;
254 pBTInfo = GET_BT_INFO(padapter);
255 pBtMgnt = &pBTInfo->BtMgnt;
256 pBtHciInfo = &pBTInfo->BtHciInfo;
258 pBtMgnt->CheckChnlIsSuit = true;
259 localchnl = bthci_GetLocalChannel(padapter);
261 pTriple = (struct common_triple *)
262 &pBtHciInfo->BTPreChnllist[COUNTRY_STR_LEN];
264 /* contains country string, len is 3 */
265 for (i = 0; i < (pBtHciInfo->BtPreChnlListLen-COUNTRY_STR_LEN); i += 3, pTriple++) {
267 /* check every triplet, an triplet may be */
268 /* regulatory extension identifier or sub-band triplet */
270 if (pTriple->byte_1st == 0xc9) {
271 /* Regulatory Extension Identifier, skip it */
272 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
273 ("Find Regulatory ID, regulatory class = %d\n", pTriple->byte_2nd));
274 regulatory_skipLen += 3;
275 pTriple_subband = NULL;
277 } else { /* Sub-band triplet */
278 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Find Sub-band triplet \n"));
280 pTriple_subband = (struct chnl_txpower_triple *)pTriple;
281 /* if remote first legal channel not found, then find first remote channel */
282 /* and it's legal for our channel plan. */
284 /* search the sub-band triplet and find if remote channel is legal to our channel plan. */
285 for (j = pTriple_subband->FirstChnl; j < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls); j++) {
286 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), (" Check if chnl(%d) is legal\n", j));
287 if (BT_IsLegalChannel(padapter, j)) {
288 /* remote channel is legal for our channel plan. */
289 firstRemoteLegalChnlInTriplet = j;
290 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
291 ("Find first remote legal channel : %d\n",
292 firstRemoteLegalChnlInTriplet));
294 /* If we find a remote legal channel in the sub-band triplet */
295 /* and only BT connection is established(local not connect to any AP or IBSS), */
296 /* then we just switch channel to remote channel. */
297 if (!(check_fwstate(pmlmepriv, WIFI_ASOC_STATE|WIFI_ADHOC_STATE|WIFI_AP_STATE) ||
298 BTHCI_HsConnectionEstablished(padapter))) {
299 pBtMgnt->BTChannel = firstRemoteLegalChnlInTriplet;
300 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Remote legal channel (%d) is selected, Local not connect to any!!\n", pBtMgnt->BTChannel));
303 if ((localchnl >= firstRemoteLegalChnlInTriplet) &&
304 (localchnl < (pTriple_subband->FirstChnl+pTriple_subband->NumChnls))) {
305 pBtMgnt->BTChannel = localchnl;
306 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected, wifi or BT connection exists\n", pBtMgnt->BTChannel));
316 if (subbandTripletCnt) {
317 /* if any preferred channel triplet exists */
318 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("There are %d sub band triplet exists, ", subbandTripletCnt));
319 if (firstRemoteLegalChnlInTriplet == 0) {
320 /* no legal channel is found, reject the connection. */
321 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("no legal channel is found!!\n"));
323 /* Remote Legal channel is found but not match to local */
324 /* wifi connection exists), so reject the connection. */
325 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
326 ("Remote Legal channel is found but not match to local(wifi connection exists)!!\n"));
328 pBtMgnt->CheckChnlIsSuit = false;
330 /* There are not any preferred channel triplet exists */
331 /* Use current legal channel as the bt channel. */
332 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("No sub band triplet exists!!\n"));
334 pBtMgnt->BTChannel = localchnl;
335 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Local channel (%d) is selected!!\n", pBtMgnt->BTChannel));
338 /* Success:return true */
339 /* Fail:return false */
340 static u8 bthci_GetAssocInfo(struct rtw_adapter *padapter, u8 EntryNum)
342 struct bt_30info *pBTInfo;
343 struct bt_hci_info *pBtHciInfo;
346 u8 BaseMemoryShift = 0;
348 struct amp_assoc_structure *pAmpAsoc;
350 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo start\n"));
351 pBTInfo = GET_BT_INFO(padapter);
352 pBtHciInfo = &pBTInfo->BtHciInfo;
354 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar == 0) {
355 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen < (MAX_AMP_ASSOC_FRAG_LEN))
356 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen;
357 else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen == (MAX_AMP_ASSOC_FRAG_LEN))
358 TotalLen = MAX_AMP_ASSOC_FRAG_LEN;
359 } else if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar > 0)
360 TotalLen = pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar;
362 while ((pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar >= BaseMemoryShift) || TotalLen > BaseMemoryShift) {
363 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("GetAssocInfo, TotalLen =%d, BaseMemoryShift =%d\n", TotalLen, BaseMemoryShift));
365 (u8 *)pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment+BaseMemoryShift,
366 TotalLen-BaseMemoryShift);
367 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, "GetAssocInfo :\n",
368 tempBuf, TotalLen-BaseMemoryShift);
370 pAmpAsoc = (struct amp_assoc_structure *)tempBuf;
371 pAmpAsoc->Length = le16_to_cpu(pAmpAsoc->Length);
372 BaseMemoryShift += 3 + pAmpAsoc->Length;
374 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TypeID = 0x%x, ", pAmpAsoc->TypeID));
375 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Hex Data: \n", pAmpAsoc->Data, pAmpAsoc->Length);
376 switch (pAmpAsoc->TypeID) {
378 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_MAC_ADDR\n"));
379 if (pAmpAsoc->Length > 6)
381 memcpy(pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, pAmpAsoc->Data, 6);
382 RTPRINT_ADDR(FIOCTL, IOCTL_BT_HCICMD, ("Remote Mac address \n"), pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr);
384 case AMP_PREFERRED_CHANNEL_LIST:
385 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_PREFERRED_CHANNEL_LIST\n"));
386 pBtHciInfo->BtPreChnlListLen = pAmpAsoc->Length;
387 memcpy(pBtHciInfo->BTPreChnllist,
389 pBtHciInfo->BtPreChnlListLen);
390 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, "Preferred channel list : \n", pBtHciInfo->BTPreChnllist, pBtHciInfo->BtPreChnlListLen);
391 bthci_DecideBTChannel(padapter, EntryNum);
393 case AMP_CONNECTED_CHANNEL:
394 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_CONNECTED_CHANNEL\n"));
395 pBtHciInfo->BTConnectChnlListLen = pAmpAsoc->Length;
396 memcpy(pBtHciInfo->BTConnectChnllist,
398 pBtHciInfo->BTConnectChnlListLen);
400 case AMP_80211_PAL_CAP_LIST:
401 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> AMP_80211_PAL_CAP_LIST\n"));
402 pBTInfo->BtAsocEntry[EntryNum].BTCapability = *(u32 *)(pAmpAsoc->Data);
403 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000001) {
406 /* Signifies PAL capable of utilizing received activity reports. */
408 if (pBTInfo->BtAsocEntry[EntryNum].BTCapability & 0x00000002) {
410 /* Signifies PAL is capable of utilizing scheduling information received in an activity reports. */
413 case AMP_80211_PAL_VISION:
414 pBtHciInfo->BTPalVersion = *(u8 *)(pAmpAsoc->Data);
415 pBtHciInfo->BTPalCompanyID = *(u16 *)(((u8 *)(pAmpAsoc->Data))+1);
416 pBtHciInfo->BTPalsubversion = *(u16 *)(((u8 *)(pAmpAsoc->Data))+3);
417 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("==> AMP_80211_PAL_VISION PalVersion 0x%x, PalCompanyID 0x%x, Palsubversion 0x%x\n",
418 pBtHciInfo->BTPalVersion,
419 pBtHciInfo->BTPalCompanyID,
420 pBtHciInfo->BTPalsubversion));
423 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("==> Unsupport TypeID !!\n"));
428 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("GetAssocInfo end\n"));
433 static u8 bthci_AddEntry(struct rtw_adapter *padapter)
435 struct bt_30info *pBTInfo;
436 struct bt_mgnt *pBtMgnt;
439 pBTInfo = GET_BT_INFO(padapter);
440 pBtMgnt = &pBTInfo->BtMgnt;
442 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
443 if (pBTInfo->BtAsocEntry[i].bUsed == false) {
444 pBTInfo->BtAsocEntry[i].bUsed = true;
445 pBtMgnt->CurrentConnectEntryNum = i;
450 if (i == MAX_BT_ASOC_ENTRY_NUM) {
451 RTPRINT(FIOCTL, IOCTL_STATE, ("bthci_AddEntry(), Add entry fail!!\n"));
457 static u8 bthci_DiscardTxPackets(struct rtw_adapter *padapter, u16 LLH)
463 bthci_CheckLogLinkBehavior(
464 struct rtw_adapter *padapter,
465 struct hci_flow_spec TxFlowSpec
468 u8 ID = TxFlowSpec.Identifier;
469 u8 ServiceType = TxFlowSpec.ServiceType;
470 u16 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
471 u32 SDUInterArrivatime = TxFlowSpec.SDUInterArrivalTime;
476 if (ServiceType == BT_LL_BE) {
478 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX best effort flowspec\n"));
479 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 0xffff)) {
481 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed latency flowspec\n"));
482 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
483 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX guaranteed Large latency flowspec\n"));
487 if (ServiceType == BT_LL_BE) {
489 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = RX best effort flowspec\n"));
494 if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 1492)) {
496 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed latency flowspec\n"));
497 } else if ((ServiceType == BT_LL_GU) && (MaxSDUSize == 2500)) {
498 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX guaranteed Large latency flowspec\n"));
502 if (ServiceType == BT_LL_BE) {
503 if ((SDUInterArrivatime == 0xffffffff) && (ServiceType == BT_LL_BE) && (MaxSDUSize == 1492)) {
505 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX aggregated best effort flowspec\n"));
507 } else if (ServiceType == BT_LL_GU) {
508 if (SDUInterArrivatime == 100) {
510 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = TX/RX guaranteed bandwidth flowspec\n"));
515 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Logical Link Type = Unknow Type !!!!!!!!\n"));
519 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO),
520 ("ID = 0x%x, ServiceType = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, AccessLatency = 0x%x, FlushTimeout = 0x%x\n",
521 TxFlowSpec.Identifier, TxFlowSpec.ServiceType, MaxSDUSize,
522 SDUInterArrivatime, TxFlowSpec.AccessLatency, TxFlowSpec.FlushTimeout));
526 static u16 bthci_AssocMACAddr(struct rtw_adapter *padapter, void *pbuf)
528 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
529 pAssoStrc->TypeID = AMP_MAC_ADDR;
530 pAssoStrc->Length = 0x06;
531 memcpy(&pAssoStrc->Data[0], padapter->eeprompriv.mac_addr, 6);
532 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
533 ("AssocMACAddr : \n"), pAssoStrc, pAssoStrc->Length+3);
535 return pAssoStrc->Length + 3;
539 bthci_PALCapabilities(
540 struct rtw_adapter *padapter,
544 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
546 pAssoStrc->TypeID = AMP_80211_PAL_CAP_LIST;
547 pAssoStrc->Length = 0x04;
549 pAssoStrc->Data[0] = 0x00;
550 pAssoStrc->Data[1] = 0x00;
552 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("PALCapabilities:\n"), pAssoStrc, pAssoStrc->Length+3);
553 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("PALCapabilities \n"));
555 RTPRINT(FIOCTL, IOCTL_BT_LOGO, (" TypeID = 0x%x,\n Length = 0x%x,\n Content = 0x0000\n",
559 return pAssoStrc->Length + 3;
562 static u16 bthci_AssocPreferredChannelList(struct rtw_adapter *padapter,
563 void *pbuf, u8 EntryNum)
565 struct bt_30info *pBTInfo;
566 struct amp_assoc_structure *pAssoStrc;
567 struct amp_pref_chnl_regulatory *pReg;
568 struct chnl_txpower_triple *pTriple;
569 char ctrString[3] = {'X', 'X', 'X'};
573 pBTInfo = GET_BT_INFO(padapter);
574 pAssoStrc = (struct amp_assoc_structure *)pbuf;
575 pReg = (struct amp_pref_chnl_regulatory *)&pAssoStrc->Data[3];
577 preferredChnl = bthci_GetLocalChannel(padapter);
578 pAssoStrc->TypeID = AMP_PREFERRED_CHANNEL_LIST;
581 memcpy(&pAssoStrc->Data[0], &ctrString[0], 3);
583 pReg->regulatoryClass = 254;
584 pReg->coverageClass = 0;
586 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("PREFERRED_CHNL_LIST\n"));
587 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("XXX, 201, 254, 0\n"));
588 /* at the following, chnl 1~11 should be contained */
589 pTriple = (struct chnl_txpower_triple *)&pAssoStrc->Data[len];
591 /* (1) if any wifi or bt HS connection exists */
592 if ((pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR) ||
593 (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE |
594 WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE |
596 BTHCI_HsConnectionEstablished(padapter)) {
597 pTriple->FirstChnl = preferredChnl;
598 pTriple->NumChnls = 1;
599 pTriple->MaxTxPowerInDbm = 20;
601 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD | IOCTL_BT_LOGO), ("First Channel = %d, Channel Num = %d, MaxDbm = %d\n",
604 pTriple->MaxTxPowerInDbm));
607 pAssoStrc->Length = (u16)len;
608 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD, ("AssocPreferredChannelList : \n"), pAssoStrc, pAssoStrc->Length+3);
610 return pAssoStrc->Length + 3;
613 static u16 bthci_AssocPALVer(struct rtw_adapter *padapter, void *pbuf)
615 struct amp_assoc_structure *pAssoStrc = (struct amp_assoc_structure *)pbuf;
619 pAssoStrc->TypeID = AMP_80211_PAL_VISION;
620 pAssoStrc->Length = 0x5;
621 pu1Tmp = &pAssoStrc->Data[0];
622 *pu1Tmp = 0x1; /* PAL Version */
623 pu2Tmp = (u16 *)&pAssoStrc->Data[1];
624 *pu2Tmp = 0x5D; /* SIG Company identifier of 802.11 PAL vendor */
625 pu2Tmp = (u16 *)&pAssoStrc->Data[3];
626 *pu2Tmp = 0x1; /* PAL Sub-version specifier */
628 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("AssocPALVer : \n"), pAssoStrc, pAssoStrc->Length+3);
629 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("AssocPALVer \n"));
631 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",
634 return pAssoStrc->Length + 3;
637 static u8 bthci_CheckRfStateBeforeConnect(struct rtw_adapter *padapter)
639 struct bt_30info *pBTInfo;
640 enum rt_rf_power_state RfState;
642 pBTInfo = GET_BT_INFO(padapter);
644 RfState = padapter->pwrctrlpriv.rf_pwrstate;
646 if (RfState != rf_on) {
647 mod_timer(&pBTInfo->BTPsDisableTimer,
648 jiffies + msecs_to_jiffies(50));
654 static void bthci_ResponderStartToScan(struct rtw_adapter *padapter)
658 static u8 bthci_PhyLinkConnectionInProgress(struct rtw_adapter *padapter, u8 PhyLinkHandle)
660 struct bt_30info *pBTInfo;
661 struct bt_mgnt *pBtMgnt;
663 pBTInfo = GET_BT_INFO(padapter);
664 pBtMgnt = &pBTInfo->BtMgnt;
666 if (pBtMgnt->bPhyLinkInProgress &&
667 (pBtMgnt->BtCurrentPhyLinkhandle == PhyLinkHandle))
672 static void bthci_ResetFlowSpec(struct rtw_adapter *padapter, u8 EntryNum, u8 index)
674 struct bt_30info *pBTinfo;
676 pBTinfo = GET_BT_INFO(padapter);
678 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtLogLinkhandle = 0;
679 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtPhyLinkhandle = 0;
680 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCompleteEventIsSet = false;
681 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].bLLCancelCMDIsSetandComplete = false;
682 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].BtTxFlowSpecID = 0;
683 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].TxPacketCount = 0;
685 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.Identifier = 0x01;
686 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
687 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.MaximumSDUSize = 0xffff;
688 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
689 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.AccessLatency = 0xffffffff;
690 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Tx_Flow_Spec.FlushTimeout = 0xffffffff;
692 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.Identifier = 0x01;
693 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.ServiceType = SERVICE_BEST_EFFORT;
694 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.MaximumSDUSize = 0xffff;
695 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.SDUInterArrivalTime = 0xffffffff;
696 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.AccessLatency = 0xffffffff;
697 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[index].Rx_Flow_Spec.FlushTimeout = 0xffffffff;
700 static void bthci_ResetEntry(struct rtw_adapter *padapter, u8 EntryNum)
702 struct bt_30info *pBTinfo;
703 struct bt_mgnt *pBtMgnt;
706 pBTinfo = GET_BT_INFO(padapter);
707 pBtMgnt = &pBTinfo->BtMgnt;
709 pBTinfo->BtAsocEntry[EntryNum].bUsed = false;
710 pBTinfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_DISCONNECTED;
711 pBTinfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED;
713 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocRemLen = 0;
714 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = 0;
715 if (pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment != NULL)
716 memset(pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment, 0, TOTAL_ALLOCIATE_ASSOC_LEN);
717 pBTinfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = 0;
719 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = 0;
720 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = 0;
721 memset(pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, 0,
722 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
723 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = 0;
725 /* 0x640; 0.625ms*1600 = 1000ms, 0.625ms*16000 = 10000ms */
726 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = 0x3e80;
728 pBTinfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_NONE;
730 pBTinfo->BtAsocEntry[EntryNum].mAssoc = false;
731 pBTinfo->BtAsocEntry[EntryNum].b4waySuccess = false;
734 pBTinfo->BtAsocEntry[EntryNum].KeyReplayCounter = 0;
735 pBTinfo->BtAsocEntry[EntryNum].BTWPAAuthState = STATE_WPA_AUTH_UNINITIALIZED;
737 pBTinfo->BtAsocEntry[EntryNum].bSendSupervisionPacket = false;
738 pBTinfo->BtAsocEntry[EntryNum].NoRxPktCnt = 0;
739 pBTinfo->BtAsocEntry[EntryNum].ShortRangeMode = 0;
740 pBTinfo->BtAsocEntry[EntryNum].rxSuvpPktCnt = 0;
742 for (j = 0; j < MAX_LOGICAL_LINK_NUM; j++)
743 bthci_ResetFlowSpec(padapter, EntryNum, j);
745 pBtMgnt->BTAuthCount = 0;
746 pBtMgnt->BTAsocCount = 0;
747 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
748 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
750 HALBT_RemoveKey(padapter, EntryNum);
753 static void bthci_RemoveEntryByEntryNum(struct rtw_adapter *padapter, u8 EntryNum)
755 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
756 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
758 bthci_ResetEntry(padapter, EntryNum);
760 if (pBtMgnt->CurrentBTConnectionCnt > 0)
761 pBtMgnt->CurrentBTConnectionCnt--;
763 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d!!\n",
764 pBtMgnt->CurrentBTConnectionCnt));
766 if (pBtMgnt->CurrentBTConnectionCnt > 0) {
767 pBtMgnt->BtOperationOn = true;
769 pBtMgnt->BtOperationOn = false;
770 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation OFF!!\n"));
773 if (!pBtMgnt->BtOperationOn) {
774 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
775 del_timer_sync(&pBTInfo->BTBeaconTimer);
776 pBtMgnt->bStartSendSupervisionPkt = false;
781 bthci_CommandCompleteHeader(
785 enum hci_status status
788 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
789 u8 NumHCI_Comm = 0x1;
791 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_COMPLETE;
792 PPacketIrpEvent->Data[0] = NumHCI_Comm; /* packet # */
793 PPacketIrpEvent->Data[1] = HCIOPCODELOW(OCF, OGF);
794 PPacketIrpEvent->Data[2] = HCIOPCODEHIGHT(OCF, OGF);
796 if (OGF == OGF_EXTENSION) {
797 if (OCF == HCI_SET_RSSI_VALUE) {
798 RTPRINT(FIOCTL, (IOCTL_BT_EVENT_PERIODICAL),
799 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
800 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
802 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_EXT),
803 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
804 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
807 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
808 ("[BT event], CommandComplete, Num_HCI_Comm = 0x%x, Opcode = 0x%02x%02x, status = 0x%x, OGF = 0x%x, OCF = 0x%x\n",
809 NumHCI_Comm, (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), status, OGF, OCF));
814 static u8 bthci_ExtensionEventHeaderRtk(u8 *pbuf, u8 extensionEvent)
816 struct packet_irp_hcievent_data *PPacketIrpEvent = (struct packet_irp_hcievent_data *)pbuf;
817 PPacketIrpEvent->EventCode = HCI_EVENT_EXTENSION_RTK;
818 PPacketIrpEvent->Data[0] = extensionEvent; /* extension event code */
823 static enum rt_status
825 struct rtw_adapter *padapter,
830 enum rt_status rt_status;
832 rt_status = PlatformIndicateBTEvent(padapter, pEvntData, dataLen);
838 bthci_EventWriteRemoteAmpAssoc(
839 struct rtw_adapter *padapter,
840 enum hci_status status,
844 u8 localBuf[TmpLocalBufSize] = "";
847 struct packet_irp_hcievent_data *PPacketIrpEvent;
849 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
850 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
852 len += bthci_CommandCompleteHeader(&localBuf[0],
853 OGF_STATUS_PARAMETERS,
854 HCI_WRITE_REMOTE_AMP_ASSOC,
856 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("PhyLinkHandle = 0x%x, status = %d\n", PLHandle, status));
857 /* Return parameters starts from here */
858 pRetPar = &PPacketIrpEvent->Data[len];
859 pRetPar[0] = status; /* status */
860 pRetPar[1] = PLHandle;
862 PPacketIrpEvent->Length = len;
864 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
868 bthci_EventEnhancedFlushComplete(
869 struct rtw_adapter *padapter,
874 struct packet_irp_hcievent_data *PPacketIrpEvent;
876 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("EventEnhancedFlushComplete, LLH = 0x%x\n", LLH));
878 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
879 PPacketIrpEvent->EventCode = HCI_EVENT_ENHANCED_FLUSH_COMPLETE;
880 PPacketIrpEvent->Length = 2;
881 /* Logical link handle */
882 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LLH);
883 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LLH);
885 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
889 bthci_EventShortRangeModeChangeComplete(
890 struct rtw_adapter *padapter,
891 enum hci_status HciStatus,
896 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
897 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
899 struct packet_irp_hcievent_data *PPacketIrpEvent;
901 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE)) {
902 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
903 ("[BT event], Short Range Mode Change Complete, Ignore to send this event due to event mask page 2\n"));
906 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",
907 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, ShortRangeState));
909 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
910 PPacketIrpEvent->EventCode = HCI_EVENT_SHORT_RANGE_MODE_CHANGE_COMPLETE;
911 PPacketIrpEvent->Length = 3;
912 PPacketIrpEvent->Data[0] = HciStatus;
913 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
914 PPacketIrpEvent->Data[2] = ShortRangeState;
915 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
918 static void bthci_EventSendFlowSpecModifyComplete(struct rtw_adapter *padapter,
919 enum hci_status HciStatus,
923 struct packet_irp_hcievent_data *PPacketIrpEvent;
924 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
925 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
927 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE)) {
928 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
929 ("[BT event], Flow Spec Modify Complete, Ignore to send this event due to event mask page 2\n"));
932 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO),
933 ("[BT event], Flow Spec Modify Complete, status = 0x%x, LLH = 0x%x\n", HciStatus, logicHandle));
934 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
935 PPacketIrpEvent->EventCode = HCI_EVENT_FLOW_SPEC_MODIFY_COMPLETE;
936 PPacketIrpEvent->Length = 3;
938 PPacketIrpEvent->Data[0] = HciStatus;
939 /* Logical link handle */
940 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(logicHandle);
941 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(logicHandle);
943 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
947 bthci_EventExtWifiScanNotify(
948 struct rtw_adapter *padapter,
952 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
953 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
958 struct packet_irp_hcievent_data *PPacketIrpEvent;
960 if (!pBtMgnt->BtOperationOn)
963 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
965 len += bthci_ExtensionEventHeaderRtk(&localBuf[0], HCI_EVENT_EXT_WIFI_SCAN_NOTIFY);
967 /* Return parameters starts from here */
968 pRetPar = &PPacketIrpEvent->Data[len];
969 pu1Temp = (u8 *)&pRetPar[0];
973 PPacketIrpEvent->Length = len;
975 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS) {
976 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Wifi scan notify, scan type = %d\n",
982 bthci_EventAMPReceiverReport(
983 struct rtw_adapter *padapter,
987 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
988 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
990 if (pBtHciInfo->bTestNeedReport) {
991 u8 localBuf[20] = "";
994 struct packet_irp_hcievent_data *PPacketIrpEvent;
996 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_EVENT_AMP_RECEIVER_REPORT\n"));
997 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
998 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_RECEIVER_REPORT;
999 PPacketIrpEvent->Length = 2;
1001 PPacketIrpEvent->Data[0] = pBtHciInfo->TestCtrType;
1003 PPacketIrpEvent->Data[1] = Reason;
1005 pu4Temp = (u32 *)&PPacketIrpEvent->Data[2];
1006 *pu4Temp = pBtHciInfo->TestEventType;
1008 pu2Temp = (u16 *)&PPacketIrpEvent->Data[6];
1009 *pu2Temp = pBtHciInfo->TestNumOfFrame;
1011 pu2Temp = (u16 *)&PPacketIrpEvent->Data[8];
1012 *pu2Temp = pBtHciInfo->TestNumOfErrFrame;
1014 pu4Temp = (u32 *)&PPacketIrpEvent->Data[10];
1015 *pu4Temp = pBtHciInfo->TestNumOfBits;
1017 pu4Temp = (u32 *)&PPacketIrpEvent->Data[14];
1018 *pu4Temp = pBtHciInfo->TestNumOfErrBits;
1020 bthci_IndicateEvent(padapter, PPacketIrpEvent, 20);
1022 /* Return to Idel state with RX and TX off. */
1026 pBtHciInfo->TestNumOfFrame = 0x00;
1030 bthci_EventChannelSelected(
1031 struct rtw_adapter *padapter,
1035 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1036 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1037 u8 localBuf[3] = "";
1038 struct packet_irp_hcievent_data *PPacketIrpEvent;
1040 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_CHANNEL_SELECT)) {
1041 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1042 ("[BT event], Channel Selected, Ignore to send this event due to event mask page 2\n"));
1046 RTPRINT(FIOCTL, IOCTL_BT_EVENT|IOCTL_STATE,
1047 ("[BT event], Channel Selected, PhyLinkHandle %d\n",
1048 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle));
1050 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1051 PPacketIrpEvent->EventCode = HCI_EVENT_CHANNEL_SELECT;
1052 PPacketIrpEvent->Length = 1;
1053 PPacketIrpEvent->Data[0] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1054 bthci_IndicateEvent(padapter, PPacketIrpEvent, 3);
1058 bthci_EventDisconnectPhyLinkComplete(
1059 struct rtw_adapter *padapter,
1060 enum hci_status HciStatus,
1061 enum hci_status Reason,
1065 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1066 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1067 u8 localBuf[5] = "";
1068 struct packet_irp_hcievent_data *PPacketIrpEvent;
1070 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE)) {
1071 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1072 ("[BT event], Disconnect Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1075 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1076 ("[BT event], Disconnect Physical Link Complete, Status = 0x%x, PLH = 0x%x Reason = 0x%x\n",
1077 HciStatus, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle, Reason));
1078 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1079 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_PHY_LINK_COMPLETE;
1080 PPacketIrpEvent->Length = 3;
1081 PPacketIrpEvent->Data[0] = HciStatus;
1082 PPacketIrpEvent->Data[1] = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1083 PPacketIrpEvent->Data[2] = Reason;
1084 bthci_IndicateEvent(padapter, PPacketIrpEvent, 5);
1088 bthci_EventPhysicalLinkComplete(
1089 struct rtw_adapter *padapter,
1090 enum hci_status HciStatus,
1095 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1096 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1097 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1098 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1099 u8 localBuf[4] = "";
1100 struct packet_irp_hcievent_data *PPacketIrpEvent;
1103 pBtMgnt->bPhyLinkInProgress = false;
1104 pBtDbg->dbgHciInfo.hciCmdPhyLinkStatus = HciStatus;
1105 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_PHY_LINK_COMPLETE)) {
1106 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1107 ("[BT event], Physical Link Complete, Ignore to send this event due to event mask page 2\n"));
1111 if (EntryNum == 0xff) {
1112 /* connection not started yet, just use the input physical link handle to response. */
1113 PL_handle = PLHandle;
1115 /* connection is under progress, use the phy link handle we recorded. */
1116 PL_handle = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1117 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = false;
1120 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Physical Link Complete, Status = 0x%x PhyLinkHandle = 0x%x\n", HciStatus,
1123 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1124 PPacketIrpEvent->EventCode = HCI_EVENT_PHY_LINK_COMPLETE;
1125 PPacketIrpEvent->Length = 2;
1127 PPacketIrpEvent->Data[0] = HciStatus;
1128 PPacketIrpEvent->Data[1] = PL_handle;
1129 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1134 bthci_EventCommandStatus(
1135 struct rtw_adapter *padapter,
1138 enum hci_status HciStatus
1142 u8 localBuf[6] = "";
1143 struct packet_irp_hcievent_data *PPacketIrpEvent;
1144 u8 Num_Hci_Comm = 0x1;
1145 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1146 ("[BT event], CommandStatus, Opcode = 0x%02x%02x, OGF = 0x%x, OCF = 0x%x, Status = 0x%x, Num_HCI_COMM = 0x%x\n",
1147 (HCIOPCODEHIGHT(OCF, OGF)), (HCIOPCODELOW(OCF, OGF)), OGF, OCF, HciStatus, Num_Hci_Comm));
1149 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1150 PPacketIrpEvent->EventCode = HCI_EVENT_COMMAND_STATUS;
1151 PPacketIrpEvent->Length = 4;
1152 PPacketIrpEvent->Data[0] = HciStatus; /* current pending */
1153 PPacketIrpEvent->Data[1] = Num_Hci_Comm; /* packet # */
1154 PPacketIrpEvent->Data[2] = HCIOPCODELOW(OCF, OGF);
1155 PPacketIrpEvent->Data[3] = HCIOPCODEHIGHT(OCF, OGF);
1157 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1162 bthci_EventLogicalLinkComplete(
1163 struct rtw_adapter *padapter,
1164 enum hci_status HciStatus,
1171 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1172 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1173 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1174 u8 localBuf[7] = "";
1175 struct packet_irp_hcievent_data *PPacketIrpEvent;
1177 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_LOGICAL_LINK_COMPLETE)) {
1178 RTPRINT(FIOCTL, IOCTL_BT_EVENT,
1179 ("[BT event], Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1182 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Logical Link Complete, PhyLinkHandle = 0x%x, LogLinkHandle = 0x%x, Status = 0x%x\n",
1183 PhyLinkHandle, LogLinkHandle, HciStatus));
1185 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1186 PPacketIrpEvent->EventCode = HCI_EVENT_LOGICAL_LINK_COMPLETE;
1187 PPacketIrpEvent->Length = 5;
1189 PPacketIrpEvent->Data[0] = HciStatus;/* status code */
1190 /* Logical link handle */
1191 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1192 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1193 /* Physical link handle */
1194 PPacketIrpEvent->Data[3] = TWOBYTE_LOWBYTE(PhyLinkHandle);
1195 /* corresponding Tx flow spec ID */
1196 if (HciStatus == HCI_STATUS_SUCCESS) {
1197 PPacketIrpEvent->Data[4] =
1198 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData[LogLinkIndex].Tx_Flow_Spec.Identifier;
1200 PPacketIrpEvent->Data[4] = 0x0;
1203 bthci_IndicateEvent(padapter, PPacketIrpEvent, 7);
1207 bthci_EventDisconnectLogicalLinkComplete(
1208 struct rtw_adapter *padapter,
1209 enum hci_status HciStatus,
1211 enum hci_status Reason
1214 u8 localBuf[6] = "";
1215 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1216 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1217 struct packet_irp_hcievent_data *PPacketIrpEvent;
1219 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE)) {
1220 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Ignore to send this event due to event mask page 2\n"));
1223 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Disconnect Logical Link Complete, Status = 0x%x, LLH = 0x%x Reason = 0x%x\n", HciStatus, LogLinkHandle, Reason));
1225 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1226 PPacketIrpEvent->EventCode = HCI_EVENT_DISCONNECT_LOGICAL_LINK_COMPLETE;
1227 PPacketIrpEvent->Length = 4;
1229 PPacketIrpEvent->Data[0] = HciStatus;
1230 /* Logical link handle */
1231 PPacketIrpEvent->Data[1] = TWOBYTE_LOWBYTE(LogLinkHandle);
1232 PPacketIrpEvent->Data[2] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1233 /* Disconnect reason */
1234 PPacketIrpEvent->Data[3] = Reason;
1236 bthci_IndicateEvent(padapter, PPacketIrpEvent, 6);
1240 bthci_EventFlushOccurred(
1241 struct rtw_adapter *padapter,
1245 u8 localBuf[4] = "";
1246 struct packet_irp_hcievent_data *PPacketIrpEvent;
1247 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("bthci_EventFlushOccurred(), LLH = 0x%x\n", LogLinkHandle));
1249 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1250 PPacketIrpEvent->EventCode = HCI_EVENT_FLUSH_OCCRUED;
1251 PPacketIrpEvent->Length = 2;
1252 /* Logical link handle */
1253 PPacketIrpEvent->Data[0] = TWOBYTE_LOWBYTE(LogLinkHandle);
1254 PPacketIrpEvent->Data[1] = TWOBYTE_HIGHTBYTE(LogLinkHandle);
1256 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
1259 static enum hci_status
1260 bthci_BuildPhysicalLink(
1261 struct rtw_adapter *padapter,
1262 struct packet_irp_hcicmd_data *pHciCmd,
1266 enum hci_status status = HCI_STATUS_SUCCESS;
1267 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1268 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1271 /* Send HCI Command status event to AMP. */
1272 bthci_EventCommandStatus(padapter,
1273 LINK_CONTROL_COMMANDS,
1275 HCI_STATUS_SUCCESS);
1277 PLH = *((u8 *)pHciCmd->Data);
1279 /* Check if resource or bt connection is under progress, if yes, reject the link creation. */
1280 if (!bthci_AddEntry(padapter)) {
1281 status = HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE;
1282 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1286 EntryNum = pBtMgnt->CurrentConnectEntryNum;
1287 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle = PLH;
1288 pBtMgnt->BtCurrentPhyLinkhandle = PLH;
1290 if (pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1291 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Create/Accept PhysicalLink, AMP controller is busy\n"));
1292 status = HCI_STATUS_CONTROLLER_BUSY;
1293 bthci_EventPhysicalLinkComplete(padapter, status, INVALID_ENTRY_NUM, PLH);
1297 /* Record Key and the info */
1298 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen = (*((u8 *)pHciCmd->Data+1));
1299 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType = (*((u8 *)pHciCmd->Data+2));
1300 memcpy(pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1301 (((u8 *)pHciCmd->Data+3)), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1302 memcpy(pBTInfo->BtAsocEntry[EntryNum].PMK, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey, PMK_LEN);
1303 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildPhysicalLink, EntryNum = %d, PLH = 0x%x KeyLen = 0x%x, KeyType = 0x%x\n",
1304 EntryNum, pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1305 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen,
1306 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyType));
1307 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("BtAMPKey\n"), pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKey,
1308 pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtAMPKeyLen);
1309 RTPRINT_DATA(FIOCTL, (IOCTL_BT_LOGO|IOCTL_BT_HCICMD), ("PMK\n"), pBTInfo->BtAsocEntry[EntryNum].PMK,
1312 if (OCF == HCI_CREATE_PHYSICAL_LINK) {
1313 /* These macros require braces */
1314 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_CREATE_PHY_LINK, EntryNum);
1315 } else if (OCF == HCI_ACCEPT_PHYSICAL_LINK) {
1316 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ACCEPT_PHY_LINK, EntryNum);
1323 bthci_BuildLogicalLink(
1324 struct rtw_adapter *padapter,
1325 struct packet_irp_hcicmd_data *pHciCmd,
1329 enum hci_status status = HCI_STATUS_SUCCESS;
1330 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1331 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
1332 u8 PhyLinkHandle, EntryNum;
1333 static u16 AssignLogHandle = 1;
1335 struct hci_flow_spec TxFlowSpec;
1336 struct hci_flow_spec RxFlowSpec;
1337 u32 MaxSDUSize, ArriveTime, Bandwidth;
1339 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1341 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1344 &pHciCmd->Data[1], sizeof(struct hci_flow_spec));
1346 &pHciCmd->Data[17], sizeof(struct hci_flow_spec));
1348 MaxSDUSize = TxFlowSpec.MaximumSDUSize;
1349 ArriveTime = TxFlowSpec.SDUInterArrivalTime;
1351 if (bthci_CheckLogLinkBehavior(padapter, TxFlowSpec) && bthci_CheckLogLinkBehavior(padapter, RxFlowSpec))
1352 Bandwidth = BTTOTALBANDWIDTH;
1353 else if (MaxSDUSize == 0xffff && ArriveTime == 0xffffffff)
1354 Bandwidth = BTTOTALBANDWIDTH;
1356 Bandwidth = MaxSDUSize*8*1000/(ArriveTime+244);
1358 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
1359 ("BuildLogicalLink, PhyLinkHandle = 0x%x, MaximumSDUSize = 0x%x, SDUInterArrivalTime = 0x%x, Bandwidth = 0x%x\n",
1360 PhyLinkHandle, MaxSDUSize, ArriveTime, Bandwidth));
1362 if (EntryNum == 0xff) {
1363 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Invalid Physical Link handle = 0x%x, status = HCI_STATUS_UNKNOW_CONNECT_ID, return\n", PhyLinkHandle));
1364 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1366 /* When we receive Create/Accept logical link command, we should send command status event first. */
1367 bthci_EventCommandStatus(padapter,
1368 LINK_CONTROL_COMMANDS,
1374 if (!pBtMgnt->bLogLinkInProgress) {
1375 if (bthci_PhyLinkConnectionInProgress(padapter, PhyLinkHandle)) {
1376 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Physical link connection in progress, status = HCI_STATUS_CMD_DISALLOW, return\n"));
1377 status = HCI_STATUS_CMD_DISALLOW;
1379 pBtMgnt->bPhyLinkInProgressStartLL = true;
1380 /* When we receive Create/Accept logical link command, we should send command status event first. */
1381 bthci_EventCommandStatus(padapter,
1382 LINK_CONTROL_COMMANDS,
1389 if (Bandwidth > BTTOTALBANDWIDTH) {
1390 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_QOS_REJECT, Bandwidth = 0x%x, return\n", Bandwidth));
1391 status = HCI_STATUS_QOS_REJECT;
1393 /* When we receive Create/Accept logical link command, we should send command status event first. */
1394 bthci_EventCommandStatus(padapter,
1395 LINK_CONTROL_COMMANDS,
1399 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("status = HCI_STATUS_SUCCESS\n"));
1400 status = HCI_STATUS_SUCCESS;
1402 /* When we receive Create/Accept logical link command, we should send command status event first. */
1403 bthci_EventCommandStatus(padapter,
1404 LINK_CONTROL_COMMANDS,
1410 if (pBTinfo->BtAsocEntry[EntryNum].BtCurrentState != HCI_STATE_CONNECTED) {
1411 bthci_EventLogicalLinkComplete(padapter,
1412 HCI_STATUS_CMD_DISALLOW, 0, 0, 0, EntryNum);
1416 pBtMgnt->bLogLinkInProgress = true;
1418 /* find an unused logical link index and copy the data */
1419 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
1420 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle == 0) {
1421 enum hci_status LogCompEventstatus = HCI_STATUS_SUCCESS;
1423 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
1424 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle = AssignLogHandle;
1425 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("BuildLogicalLink, EntryNum = %d, physical link handle = 0x%x, logical link handle = 0x%x\n",
1426 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle,
1427 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle));
1428 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Tx_Flow_Spec,
1429 &TxFlowSpec, sizeof(struct hci_flow_spec));
1430 memcpy(&pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].Rx_Flow_Spec,
1431 &RxFlowSpec, sizeof(struct hci_flow_spec));
1433 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = false;
1435 if (pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCancelCMDIsSetandComplete)
1436 LogCompEventstatus = HCI_STATUS_UNKNOW_CONNECT_ID;
1437 bthci_EventLogicalLinkComplete(padapter,
1439 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtPhyLinkhandle,
1440 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].BtLogLinkhandle, i, EntryNum);
1442 pBTinfo->BtAsocEntry[EntryNum].LogLinkCmdData[i].bLLCompleteEventIsSet = true;
1445 pBtMgnt->BtCurrentLogLinkhandle = AssignLogHandle;
1452 bthci_EventLogicalLinkComplete(padapter,
1453 HCI_STATUS_CONNECT_RJT_LIMIT_RESOURCE, 0, 0, 0, EntryNum);
1455 pBtMgnt->bLogLinkInProgress = false;
1458 bthci_EventLogicalLinkComplete(padapter,
1459 HCI_STATUS_CONTROLLER_BUSY, 0, 0, 0, EntryNum);
1465 bthci_StartBeaconAndConnect(
1466 struct rtw_adapter *padapter,
1467 struct packet_irp_hcicmd_data *pHciCmd,
1471 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1472 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1473 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
1475 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("StartBeaconAndConnect, CurrentAssocNum =%d, AMPRole =%d\n",
1477 pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole));
1479 if (!pBtMgnt->CheckChnlIsSuit) {
1480 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONNECT_REJ_NOT_SUIT_CHNL_FOUND, CurrentAssocNum, INVALID_PL_HANDLE);
1481 bthci_RemoveEntryByEntryNum(padapter, CurrentAssocNum);
1485 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1486 rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
1487 padapter->eeprompriv.mac_addr[0],
1488 padapter->eeprompriv.mac_addr[1],
1489 padapter->eeprompriv.mac_addr[2],
1490 padapter->eeprompriv.mac_addr[3],
1491 padapter->eeprompriv.mac_addr[4],
1492 padapter->eeprompriv.mac_addr[5]);
1493 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1494 rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
1495 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[0],
1496 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[1],
1497 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[2],
1498 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[3],
1499 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[4],
1500 pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[5]);
1503 FillOctetString(pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid, pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 21);
1504 pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsid.Length = 21;
1506 /* To avoid set the start ap or connect twice, or the original connection will be disconnected. */
1507 if (!pBtMgnt->bBTConnectInProgress) {
1508 pBtMgnt->bBTConnectInProgress = true;
1509 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress ON!!\n"));
1510 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_STARTING, STATE_CMD_MAC_START_COMPLETE, CurrentAssocNum);
1512 /* 20100325 Joseph: Check RF ON/OFF. */
1513 /* If RF OFF, it reschedule connecting operation after 50ms. */
1514 if (!bthci_CheckRfStateBeforeConnect(padapter))
1517 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
1518 /* These macros need braces */
1519 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_COMPLETE, CurrentAssocNum);
1520 } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
1521 bthci_ResponderStartToScan(padapter);
1524 RT_PRINT_STR(_module_rtl871x_mlme_c_, _drv_notice_,
1525 "StartBeaconAndConnect, SSID:\n",
1526 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Octet,
1527 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].BTSsid.Length);
1530 static void bthci_ResetBtMgnt(struct bt_mgnt *pBtMgnt)
1532 pBtMgnt->BtOperationOn = false;
1533 pBtMgnt->bBTConnectInProgress = false;
1534 pBtMgnt->bLogLinkInProgress = false;
1535 pBtMgnt->bPhyLinkInProgress = false;
1536 pBtMgnt->bPhyLinkInProgressStartLL = false;
1537 pBtMgnt->DisconnectEntryNum = 0xff;
1538 pBtMgnt->bStartSendSupervisionPkt = false;
1539 pBtMgnt->JoinerNeedSendAuth = false;
1540 pBtMgnt->CurrentBTConnectionCnt = 0;
1541 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
1542 pBtMgnt->BTReceiveConnectPkt = BT_DISCONNECT;
1543 pBtMgnt->BTAuthCount = 0;
1544 pBtMgnt->btLogoTest = 0;
1547 static void bthci_ResetBtHciInfo(struct bt_hci_info *pBtHciInfo)
1549 pBtHciInfo->BTEventMask = 0;
1550 pBtHciInfo->BTEventMaskPage2 = 0;
1551 pBtHciInfo->ConnAcceptTimeout = 10000;
1552 pBtHciInfo->PageTimeout = 0x30;
1553 pBtHciInfo->LocationDomainAware = 0x0;
1554 pBtHciInfo->LocationDomain = 0x5858;
1555 pBtHciInfo->LocationDomainOptions = 0x58;
1556 pBtHciInfo->LocationOptions = 0x0;
1557 pBtHciInfo->FlowControlMode = 0x1; /* 0:Packet based data flow control mode(BR/EDR), 1: Data block based data flow control mode(AMP). */
1559 pBtHciInfo->enFlush_LLH = 0;
1560 pBtHciInfo->FLTO_LLH = 0;
1562 /* Test command only */
1563 pBtHciInfo->bTestIsEnd = true;
1564 pBtHciInfo->bInTestMode = false;
1565 pBtHciInfo->bTestNeedReport = false;
1566 pBtHciInfo->TestScenario = 0xff;
1567 pBtHciInfo->TestReportInterval = 0x01;
1568 pBtHciInfo->TestCtrType = 0x5d;
1569 pBtHciInfo->TestEventType = 0x00;
1570 pBtHciInfo->TestNumOfFrame = 0;
1571 pBtHciInfo->TestNumOfErrFrame = 0;
1572 pBtHciInfo->TestNumOfBits = 0;
1573 pBtHciInfo->TestNumOfErrBits = 0;
1576 static void bthci_ResetBtSec(struct rtw_adapter *padapter, struct bt_security *pBtSec)
1578 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1580 /* Set BT used HW or SW encrypt !! */
1581 if (GET_HAL_DATA(padapter)->bBTMode)
1582 pBtSec->bUsedHwEncrypt = true;
1584 pBtSec->bUsedHwEncrypt = false;
1585 RT_TRACE(_module_rtl871x_security_c_, _drv_info_, ("%s: bUsedHwEncrypt =%d\n", __func__, pBtSec->bUsedHwEncrypt));
1587 pBtSec->RSNIE.Octet = pBtSec->RSNIEBuf;
1590 static void bthci_ResetBtExtInfo(struct bt_mgnt *pBtMgnt)
1594 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
1595 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = 0;
1596 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = 0;
1597 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = 0;
1598 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = BT_PROFILE_NONE;
1599 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = BT_SPEC_2_1_EDR;
1600 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = 0;
1601 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
1602 pBtMgnt->ExtConfig.linkInfo[i].linkRole = BT_LINK_MASTER;
1605 pBtMgnt->ExtConfig.CurrentConnectHandle = 0;
1606 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = 0;
1607 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = 0;
1608 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
1609 pBtMgnt->ExtConfig.NumberOfHandle = 0;
1610 pBtMgnt->ExtConfig.NumberOfSCO = 0;
1611 pBtMgnt->ExtConfig.CurrentBTStatus = 0;
1612 pBtMgnt->ExtConfig.HCIExtensionVer = 0;
1614 pBtMgnt->ExtConfig.bManualControl = false;
1615 pBtMgnt->ExtConfig.bBTBusy = false;
1616 pBtMgnt->ExtConfig.bBTA2DPBusy = false;
1619 static enum hci_status bthci_CmdReset(struct rtw_adapter *_padapter, u8 bNeedSendEvent)
1621 enum hci_status status = HCI_STATUS_SUCCESS;
1622 struct rtw_adapter *padapter;
1623 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1624 struct bt_30info *pBTInfo;
1625 struct bt_mgnt *pBtMgnt;
1626 struct bt_hci_info *pBtHciInfo;
1627 struct bt_security *pBtSec;
1628 struct bt_dgb *pBtDbg;
1631 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_CmdReset()\n"));
1633 padapter = GetDefaultAdapter(_padapter);
1634 pBTInfo = GET_BT_INFO(padapter);
1635 pBtMgnt = &pBTInfo->BtMgnt;
1636 pBtHciInfo = &pBTInfo->BtHciInfo;
1637 pBtSec = &pBTInfo->BtSec;
1638 pBtDbg = &pBTInfo->BtDbg;
1640 pBTInfo->padapter = padapter;
1642 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++)
1643 bthci_ResetEntry(padapter, i);
1645 bthci_ResetBtMgnt(pBtMgnt);
1646 bthci_ResetBtHciInfo(pBtHciInfo);
1647 bthci_ResetBtSec(padapter, pBtSec);
1649 pBtMgnt->BTChannel = BT_Default_Chnl;
1650 pBtMgnt->CheckChnlIsSuit = true;
1652 pBTInfo->BTBeaconTmrOn = false;
1654 pBtMgnt->bCreateSpportQos = true;
1656 del_timer_sync(&pBTInfo->BTHCIDiscardAclDataTimer);
1657 del_timer_sync(&pBTInfo->BTBeaconTimer);
1659 HALBT_SetRtsCtsNoLenLimit(padapter);
1661 /* Maybe we need to take care Group != AES case !! */
1662 /* now we Pairwise and Group all used AES !! */
1664 bthci_ResetBtExtInfo(pBtMgnt);
1666 /* send command complete event here when all data are received. */
1667 if (bNeedSendEvent) {
1668 u8 localBuf[6] = "";
1671 struct packet_irp_hcievent_data *PPacketIrpEvent;
1673 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1675 len += bthci_CommandCompleteHeader(&localBuf[0],
1676 OGF_SET_EVENT_MASK_COMMAND,
1680 /* Return parameters starts from here */
1681 pRetPar = &PPacketIrpEvent->Data[len];
1682 pRetPar[0] = status; /* status */
1684 PPacketIrpEvent->Length = len;
1686 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1692 static enum hci_status
1693 bthci_CmdWriteRemoteAMPAssoc(
1694 struct rtw_adapter *padapter,
1695 struct packet_irp_hcicmd_data *pHciCmd
1698 enum hci_status status = HCI_STATUS_SUCCESS;
1699 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1700 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
1704 pBtDbg->dbgHciInfo.hciCmdCntWriteRemoteAmpAssoc++;
1705 PhyLinkHandle = *((u8 *)pHciCmd->Data);
1706 CurrentAssocNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
1708 if (CurrentAssocNum == 0xff) {
1709 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, No such Handle in the Entry\n"));
1710 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1711 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1715 if (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment == NULL) {
1716 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, AMP controller is busy\n"));
1717 status = HCI_STATUS_CONTROLLER_BUSY;
1718 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1722 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.BtPhyLinkhandle = PhyLinkHandle;/* u8 *)pHciCmd->Data); */
1723 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
1724 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen = *((u16 *)((u8 *)pHciCmd->Data+3));
1726 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("WriteRemoteAMPAssoc, LenSoFar = 0x%x, AssocRemLen = 0x%x\n",
1727 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar,
1728 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1730 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO),
1731 ("WriteRemoteAMPAssoc fragment \n"),
1733 pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen+5);
1734 if ((pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen) > MAX_AMP_ASSOC_FRAG_LEN) {
1735 memcpy(((u8 *)pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8)))),
1736 (u8 *)pHciCmd->Data+5,
1737 MAX_AMP_ASSOC_FRAG_LEN);
1739 memcpy((u8 *)(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocfragment)+(pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.LenSoFar*(sizeof(u8))),
1740 ((u8 *)pHciCmd->Data+5),
1741 (pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen));
1743 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "WriteRemoteAMPAssoc :\n",
1744 pHciCmd->Data+5, pBTInfo->BtAsocEntry[CurrentAssocNum].AmpAsocCmdData.AMPAssocRemLen);
1746 if (!bthci_GetAssocInfo(padapter, CurrentAssocNum))
1747 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
1749 bthci_EventWriteRemoteAmpAssoc(padapter, status, PhyLinkHandle);
1751 bthci_StartBeaconAndConnect(padapter, pHciCmd, CurrentAssocNum);
1758 static enum hci_status bthci_CmdReadConnectionAcceptTimeout(struct rtw_adapter *padapter)
1760 enum hci_status status = HCI_STATUS_SUCCESS;
1761 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
1762 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1763 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1764 u8 localBuf[8] = "";
1767 struct packet_irp_hcievent_data *PPacketIrpEvent;
1770 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1772 len += bthci_CommandCompleteHeader(&localBuf[0],
1773 OGF_SET_EVENT_MASK_COMMAND,
1774 HCI_READ_CONNECTION_ACCEPT_TIMEOUT,
1777 /* Return parameters starts from here */
1778 pRetPar = &PPacketIrpEvent->Data[len];
1779 pRetPar[0] = status; /* status */
1780 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
1781 *pu2Temp = pBtHciInfo->ConnAcceptTimeout;
1783 PPacketIrpEvent->Length = len;
1785 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1791 static enum hci_status
1792 bthci_CmdSetEventFilter(
1793 struct rtw_adapter *padapter,
1794 struct packet_irp_hcicmd_data *pHciCmd
1797 enum hci_status status = HCI_STATUS_SUCCESS;
1803 static enum hci_status
1804 bthci_CmdWriteConnectionAcceptTimeout(
1805 struct rtw_adapter *padapter,
1806 struct packet_irp_hcicmd_data *pHciCmd
1809 enum hci_status status = HCI_STATUS_SUCCESS;
1810 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1811 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1813 u8 localBuf[6] = "";
1816 struct packet_irp_hcievent_data *PPacketIrpEvent;
1818 pu2Temp = (u16 *)&pHciCmd->Data[0];
1819 pBtHciInfo->ConnAcceptTimeout = *pu2Temp;
1820 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ConnAcceptTimeout = 0x%x",
1821 pBtHciInfo->ConnAcceptTimeout));
1823 /* send command complete event here when all data are received. */
1824 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1826 len += bthci_CommandCompleteHeader(&localBuf[0],
1827 OGF_SET_EVENT_MASK_COMMAND,
1828 HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT,
1831 /* Return parameters starts from here */
1832 pRetPar = &PPacketIrpEvent->Data[len];
1833 pRetPar[0] = status; /* status */
1835 PPacketIrpEvent->Length = len;
1837 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1842 static enum hci_status
1843 bthci_CmdReadPageTimeout(
1844 struct rtw_adapter *padapter,
1845 struct packet_irp_hcicmd_data *pHciCmd
1848 enum hci_status status = HCI_STATUS_SUCCESS;
1849 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1850 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1851 u8 localBuf[8] = "";
1854 struct packet_irp_hcievent_data *PPacketIrpEvent;
1857 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1859 len += bthci_CommandCompleteHeader(&localBuf[0],
1860 OGF_SET_EVENT_MASK_COMMAND,
1861 HCI_READ_PAGE_TIMEOUT,
1864 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Read PageTimeout = 0x%x\n", pBtHciInfo->PageTimeout));
1865 /* Return parameters starts from here */
1866 pRetPar = &PPacketIrpEvent->Data[len];
1867 pRetPar[0] = status; /* status */
1868 pu2Temp = (u16 *)&pRetPar[1]; /* Page_Timeout */
1869 *pu2Temp = pBtHciInfo->PageTimeout;
1871 PPacketIrpEvent->Length = len;
1873 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1878 static enum hci_status
1879 bthci_CmdWritePageTimeout(
1880 struct rtw_adapter *padapter,
1881 struct packet_irp_hcicmd_data *pHciCmd
1884 enum hci_status status = HCI_STATUS_SUCCESS;
1885 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
1886 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
1889 pu2Temp = (u16 *)&pHciCmd->Data[0];
1890 pBtHciInfo->PageTimeout = *pu2Temp;
1891 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Write PageTimeout = 0x%x\n",
1892 pBtHciInfo->PageTimeout));
1894 /* send command complete event here when all data are received. */
1896 u8 localBuf[6] = "";
1899 struct packet_irp_hcievent_data *PPacketIrpEvent;
1901 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1903 len += bthci_CommandCompleteHeader(&localBuf[0],
1904 OGF_SET_EVENT_MASK_COMMAND,
1905 HCI_WRITE_PAGE_TIMEOUT,
1908 /* Return parameters starts from here */
1909 pRetPar = &PPacketIrpEvent->Data[len];
1910 pRetPar[0] = status; /* status */
1912 PPacketIrpEvent->Length = len;
1914 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1920 static enum hci_status
1921 bthci_CmdReadLinkSupervisionTimeout(
1922 struct rtw_adapter *padapter,
1923 struct packet_irp_hcicmd_data *pHciCmd
1926 enum hci_status status = HCI_STATUS_SUCCESS;
1927 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1928 u8 physicalLinkHandle, EntryNum;
1930 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1932 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1934 if (EntryNum == 0xff) {
1935 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLinkSupervisionTimeout, No such Handle in the Entry\n"));
1936 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1940 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle)
1941 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1944 u8 localBuf[10] = "";
1947 struct packet_irp_hcievent_data *PPacketIrpEvent;
1950 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
1952 len += bthci_CommandCompleteHeader(&localBuf[0],
1953 OGF_SET_EVENT_MASK_COMMAND,
1954 HCI_READ_LINK_SUPERVISION_TIMEOUT,
1957 /* Return parameters starts from here */
1958 pRetPar = &PPacketIrpEvent->Data[len];
1959 pRetPar[0] = status;
1960 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
1962 pu2Temp = (u16 *)&pRetPar[3]; /* Conn_Accept_Timeout */
1963 *pu2Temp = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout;
1965 PPacketIrpEvent->Length = len;
1967 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
1973 static enum hci_status
1974 bthci_CmdWriteLinkSupervisionTimeout(
1975 struct rtw_adapter *padapter,
1976 struct packet_irp_hcicmd_data *pHciCmd
1979 enum hci_status status = HCI_STATUS_SUCCESS;
1980 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
1981 u8 physicalLinkHandle, EntryNum;
1983 physicalLinkHandle = *((u8 *)pHciCmd->Data);
1985 EntryNum = bthci_GetCurrentEntryNum(padapter, physicalLinkHandle);
1987 if (EntryNum == 0xff) {
1988 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("WriteLinkSupervisionTimeout, No such Handle in the Entry\n"));
1989 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1991 if (pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle != physicalLinkHandle) {
1992 status = HCI_STATUS_UNKNOW_CONNECT_ID;
1994 pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout = *((u16 *)(((u8 *)pHciCmd->Data)+2));
1995 RTPRINT(FIOCTL, IOCTL_STATE, ("BT Write LinkSuperversionTimeout[%d] = 0x%x\n",
1996 EntryNum, pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.LinkSuperversionTimeout));
2001 u8 localBuf[8] = "";
2004 struct packet_irp_hcievent_data *PPacketIrpEvent;
2006 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2008 len += bthci_CommandCompleteHeader(&localBuf[0],
2009 OGF_SET_EVENT_MASK_COMMAND,
2010 HCI_WRITE_LINK_SUPERVISION_TIMEOUT,
2013 /* Return parameters starts from here */
2014 pRetPar = &PPacketIrpEvent->Data[len];
2015 pRetPar[0] = status;
2016 pRetPar[1] = pBTinfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle;
2019 PPacketIrpEvent->Length = len;
2021 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2027 static enum hci_status
2028 bthci_CmdEnhancedFlush(
2029 struct rtw_adapter *padapter,
2030 struct packet_irp_hcicmd_data *pHciCmd
2033 enum hci_status status = HCI_STATUS_SUCCESS;
2034 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2035 struct bt_hci_info *pBtHciInfo = &pBTinfo->BtHciInfo;
2039 logicHandle = *((u16 *)&pHciCmd->Data[0]);
2040 Packet_Type = pHciCmd->Data[2];
2042 if (Packet_Type != 0)
2043 status = HCI_STATUS_INVALID_HCI_CMD_PARA_VALUE;
2045 pBtHciInfo->enFlush_LLH = logicHandle;
2047 if (bthci_DiscardTxPackets(padapter, pBtHciInfo->enFlush_LLH))
2048 bthci_EventFlushOccurred(padapter, pBtHciInfo->enFlush_LLH);
2050 /* should send command status event */
2051 bthci_EventCommandStatus(padapter,
2052 OGF_SET_EVENT_MASK_COMMAND,
2056 if (pBtHciInfo->enFlush_LLH) {
2057 bthci_EventEnhancedFlushComplete(padapter, pBtHciInfo->enFlush_LLH);
2058 pBtHciInfo->enFlush_LLH = 0;
2064 static enum hci_status
2065 bthci_CmdReadLogicalLinkAcceptTimeout(
2066 struct rtw_adapter *padapter,
2067 struct packet_irp_hcicmd_data *pHciCmd
2070 enum hci_status status = HCI_STATUS_SUCCESS;
2071 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2072 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2073 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2074 u8 localBuf[8] = "";
2077 struct packet_irp_hcievent_data *PPacketIrpEvent;
2080 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2082 len += bthci_CommandCompleteHeader(&localBuf[0],
2083 OGF_SET_EVENT_MASK_COMMAND,
2084 HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT,
2087 /* Return parameters starts from here */
2088 pRetPar = &PPacketIrpEvent->Data[len];
2089 pRetPar[0] = status;
2091 pu2Temp = (u16 *)&pRetPar[1]; /* Conn_Accept_Timeout */
2092 *pu2Temp = pBtHciInfo->LogicalAcceptTimeout;
2094 PPacketIrpEvent->Length = len;
2096 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2101 static enum hci_status
2102 bthci_CmdWriteLogicalLinkAcceptTimeout(
2103 struct rtw_adapter *padapter,
2104 struct packet_irp_hcicmd_data *pHciCmd
2107 enum hci_status status = HCI_STATUS_SUCCESS;
2108 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2109 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2110 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2111 u8 localBuf[6] = "";
2114 struct packet_irp_hcievent_data *PPacketIrpEvent;
2116 pBtHciInfo->LogicalAcceptTimeout = *((u16 *)pHciCmd->Data);
2118 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2120 len += bthci_CommandCompleteHeader(&localBuf[0],
2121 OGF_SET_EVENT_MASK_COMMAND,
2122 HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT,
2125 /* Return parameters starts from here */
2126 pRetPar = &PPacketIrpEvent->Data[len];
2127 pRetPar[0] = status;
2130 PPacketIrpEvent->Length = len;
2132 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2136 static enum hci_status
2137 bthci_CmdSetEventMask(
2138 struct rtw_adapter *padapter,
2139 struct packet_irp_hcicmd_data *pHciCmd
2142 enum hci_status status = HCI_STATUS_SUCCESS;
2143 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2144 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2145 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2147 u8 localBuf[6] = "";
2150 struct packet_irp_hcievent_data *PPacketIrpEvent;
2152 pu8Temp = (u8 *)&pHciCmd->Data[0];
2153 pBtHciInfo->BTEventMask = *pu8Temp;
2154 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("BTEventMask = 0x%"i64fmt"x\n",
2155 pBtHciInfo->BTEventMask));
2157 /* send command complete event here when all data are received. */
2158 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2160 len += bthci_CommandCompleteHeader(&localBuf[0],
2161 OGF_SET_EVENT_MASK_COMMAND,
2165 /* Return parameters starts from here */
2166 pRetPar = &PPacketIrpEvent->Data[len];
2167 pRetPar[0] = status; /* status */
2169 PPacketIrpEvent->Length = len;
2171 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2177 static enum hci_status
2178 bthci_CmdSetEventMaskPage2(
2179 struct rtw_adapter *padapter,
2180 struct packet_irp_hcicmd_data *pHciCmd
2183 enum hci_status status = HCI_STATUS_SUCCESS;
2184 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2185 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2187 u8 localBuf[6] = "";
2190 struct packet_irp_hcievent_data *PPacketIrpEvent;
2192 pu8Temp = (u8 *)&pHciCmd->Data[0];
2193 pBtHciInfo->BTEventMaskPage2 = *pu8Temp;
2194 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("BTEventMaskPage2 = 0x%"i64fmt"x\n",
2195 pBtHciInfo->BTEventMaskPage2));
2197 /* send command complete event here when all data are received. */
2198 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2200 len += bthci_CommandCompleteHeader(&localBuf[0],
2201 OGF_SET_EVENT_MASK_COMMAND,
2202 HCI_SET_EVENT_MASK_PAGE_2,
2205 /* Return parameters starts from here */
2206 pRetPar = &PPacketIrpEvent->Data[len];
2207 pRetPar[0] = status; /* status */
2209 PPacketIrpEvent->Length = len;
2211 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2216 static enum hci_status
2217 bthci_CmdReadLocationData(
2218 struct rtw_adapter *padapter,
2219 struct packet_irp_hcicmd_data *pHciCmd
2222 enum hci_status status = HCI_STATUS_SUCCESS;
2223 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2224 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2225 u8 localBuf[12] = "";
2228 struct packet_irp_hcievent_data *PPacketIrpEvent;
2231 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2233 len += bthci_CommandCompleteHeader(&localBuf[0],
2234 OGF_SET_EVENT_MASK_COMMAND,
2235 HCI_READ_LOCATION_DATA,
2237 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2238 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2239 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2240 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2242 /* Return parameters starts from here */
2243 pRetPar = &PPacketIrpEvent->Data[len];
2244 pRetPar[0] = status;
2246 pRetPar[1] = pBtHciInfo->LocationDomainAware; /* 0x0; Location_Domain_Aware */
2247 pu2Temp = (u16 *)&pRetPar[2]; /* Location_Domain */
2248 *pu2Temp = pBtHciInfo->LocationDomain; /* 0x5858; */
2249 pRetPar[4] = pBtHciInfo->LocationDomainOptions; /* 0x58; Location_Domain_Options */
2250 pRetPar[5] = pBtHciInfo->LocationOptions; /* 0x0; Location_Options */
2252 PPacketIrpEvent->Length = len;
2254 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2258 static enum hci_status
2259 bthci_CmdWriteLocationData(
2260 struct rtw_adapter *padapter,
2261 struct packet_irp_hcicmd_data *pHciCmd
2264 enum hci_status status = HCI_STATUS_SUCCESS;
2265 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2266 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2268 u8 localBuf[6] = "";
2271 struct packet_irp_hcievent_data *PPacketIrpEvent;
2273 pBtHciInfo->LocationDomainAware = pHciCmd->Data[0];
2274 pu2Temp = (u16 *)&pHciCmd->Data[1];
2275 pBtHciInfo->LocationDomain = *pu2Temp;
2276 pBtHciInfo->LocationDomainOptions = pHciCmd->Data[3];
2277 pBtHciInfo->LocationOptions = pHciCmd->Data[4];
2278 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainAware = 0x%x\n", pBtHciInfo->LocationDomainAware));
2279 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Domain = 0x%x\n", pBtHciInfo->LocationDomain));
2280 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DomainOptions = 0x%x\n", pBtHciInfo->LocationDomainOptions));
2281 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Options = 0x%x\n", pBtHciInfo->LocationOptions));
2283 /* send command complete event here when all data are received. */
2284 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2286 len += bthci_CommandCompleteHeader(&localBuf[0],
2287 OGF_SET_EVENT_MASK_COMMAND,
2288 HCI_WRITE_LOCATION_DATA,
2291 /* Return parameters starts from here */
2292 pRetPar = &PPacketIrpEvent->Data[len];
2293 pRetPar[0] = status; /* status */
2295 PPacketIrpEvent->Length = len;
2297 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2302 static enum hci_status
2303 bthci_CmdReadFlowControlMode(
2304 struct rtw_adapter *padapter,
2305 struct packet_irp_hcicmd_data *pHciCmd
2308 enum hci_status status = HCI_STATUS_SUCCESS;
2309 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2310 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2311 u8 localBuf[7] = "";
2314 struct packet_irp_hcievent_data *PPacketIrpEvent;
2316 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2318 len += bthci_CommandCompleteHeader(&localBuf[0],
2319 OGF_SET_EVENT_MASK_COMMAND,
2320 HCI_READ_FLOW_CONTROL_MODE,
2323 /* Return parameters starts from here */
2324 pRetPar = &PPacketIrpEvent->Data[len];
2325 pRetPar[0] = status;
2326 pRetPar[1] = pBtHciInfo->FlowControlMode; /* Flow Control Mode */
2328 PPacketIrpEvent->Length = len;
2330 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2334 static enum hci_status
2335 bthci_CmdWriteFlowControlMode(
2336 struct rtw_adapter *padapter,
2337 struct packet_irp_hcicmd_data *pHciCmd
2340 enum hci_status status = HCI_STATUS_SUCCESS;
2341 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2342 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2343 u8 localBuf[6] = "";
2346 struct packet_irp_hcievent_data *PPacketIrpEvent;
2348 pBtHciInfo->FlowControlMode = pHciCmd->Data[0];
2350 /* send command complete event here when all data are received. */
2351 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2353 len += bthci_CommandCompleteHeader(&localBuf[0],
2354 OGF_SET_EVENT_MASK_COMMAND,
2355 HCI_WRITE_FLOW_CONTROL_MODE,
2358 /* Return parameters starts from here */
2359 pRetPar = &PPacketIrpEvent->Data[len];
2360 pRetPar[0] = status; /* status */
2362 PPacketIrpEvent->Length = len;
2364 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2369 static enum hci_status
2370 bthci_CmdReadBestEffortFlushTimeout(
2371 struct rtw_adapter *padapter,
2372 struct packet_irp_hcicmd_data *pHciCmd
2375 enum hci_status status = HCI_STATUS_SUCCESS;
2376 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2377 u16 i, j, logicHandle;
2378 u32 BestEffortFlushTimeout = 0xffffffff;
2381 logicHandle = *((u16 *)pHciCmd->Data);
2382 /* find an matched logical link index and copy the data */
2383 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2384 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2385 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2386 BestEffortFlushTimeout = pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout;
2394 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2397 u8 localBuf[10] = "";
2400 struct packet_irp_hcievent_data *PPacketIrpEvent;
2403 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2405 len += bthci_CommandCompleteHeader(&localBuf[0],
2406 OGF_SET_EVENT_MASK_COMMAND,
2407 HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT,
2410 /* Return parameters starts from here */
2411 pRetPar = &PPacketIrpEvent->Data[len];
2412 pRetPar[0] = status;
2413 pu4Temp = (u32 *)&pRetPar[1]; /* Best_Effort_Flush_Timeout */
2414 *pu4Temp = BestEffortFlushTimeout;
2416 PPacketIrpEvent->Length = len;
2418 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2423 static enum hci_status
2424 bthci_CmdWriteBestEffortFlushTimeout(
2425 struct rtw_adapter *padapter,
2426 struct packet_irp_hcicmd_data *pHciCmd
2429 enum hci_status status = HCI_STATUS_SUCCESS;
2430 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
2431 u16 i, j, logicHandle;
2432 u32 BestEffortFlushTimeout = 0xffffffff;
2435 logicHandle = *((u16 *)pHciCmd->Data);
2436 BestEffortFlushTimeout = *((u32 *)(pHciCmd->Data+1));
2438 /* find an matched logical link index and copy the data */
2439 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
2440 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
2441 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
2442 pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BestEffortFlushTimeout = BestEffortFlushTimeout;
2450 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2453 u8 localBuf[6] = "";
2456 struct packet_irp_hcievent_data *PPacketIrpEvent;
2458 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2460 len += bthci_CommandCompleteHeader(&localBuf[0],
2461 OGF_SET_EVENT_MASK_COMMAND,
2462 HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT,
2465 /* Return parameters starts from here */
2466 pRetPar = &PPacketIrpEvent->Data[len];
2467 pRetPar[0] = status;
2469 PPacketIrpEvent->Length = len;
2471 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2476 static enum hci_status
2477 bthci_CmdShortRangeMode(
2478 struct rtw_adapter *padapter,
2479 struct packet_irp_hcicmd_data *pHciCmd
2482 enum hci_status status = HCI_STATUS_SUCCESS;
2483 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2484 u8 PhyLinkHandle, EntryNum, ShortRangeMode;
2486 PhyLinkHandle = pHciCmd->Data[0];
2487 ShortRangeMode = pHciCmd->Data[1];
2488 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x, Short_Range_Mode = 0x%x\n", PhyLinkHandle, ShortRangeMode));
2490 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2491 if (EntryNum != 0xff) {
2492 pBTInfo->BtAsocEntry[EntryNum].ShortRangeMode = ShortRangeMode;
2494 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PhyLinkHandle));
2495 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2498 bthci_EventCommandStatus(padapter,
2499 OGF_SET_EVENT_MASK_COMMAND,
2500 HCI_SHORT_RANGE_MODE,
2503 bthci_EventShortRangeModeChangeComplete(padapter, status, ShortRangeMode, EntryNum);
2508 static enum hci_status bthci_CmdReadLocalSupportedCommands(struct rtw_adapter *padapter)
2510 enum hci_status status = HCI_STATUS_SUCCESS;
2511 u8 localBuf[TmpLocalBufSize] = "";
2512 u8 *pRetPar, *pSupportedCmds;
2514 struct packet_irp_hcievent_data *PPacketIrpEvent;
2516 /* send command complete event here when all data are received. */
2517 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2518 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2520 len += bthci_CommandCompleteHeader(&localBuf[0],
2521 OGF_INFORMATIONAL_PARAMETERS,
2522 HCI_READ_LOCAL_SUPPORTED_COMMANDS,
2525 /* Return parameters starts from here */
2526 pRetPar = &PPacketIrpEvent->Data[len];
2527 pRetPar[0] = status; /* status */
2529 pSupportedCmds = &pRetPar[1];
2530 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[5]= 0xc0\nBit [6]= Set Event Mask, [7]= Reset\n"));
2531 pSupportedCmds[5] = 0xc0;
2532 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[6]= 0x01\nBit [0]= Set Event Filter\n"));
2533 pSupportedCmds[6] = 0x01;
2534 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[7]= 0x0c\nBit [2]= Read Connection Accept Timeout, [3]= Write Connection Accept Timeout\n"));
2535 pSupportedCmds[7] = 0x0c;
2536 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[10]= 0x80\nBit [7]= Host Number Of Completed Packets\n"));
2537 pSupportedCmds[10] = 0x80;
2538 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[11]= 0x03\nBit [0]= Read Link Supervision Timeout, [1]= Write Link Supervision Timeout\n"));
2539 pSupportedCmds[11] = 0x03;
2540 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"));
2541 pSupportedCmds[14] = 0xa8;
2542 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"));
2543 pSupportedCmds[15] = 0x1c;
2544 /* pSupportedCmds[16] = 0x04; */
2545 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD|IOCTL_BT_LOGO), ("Octet[19]= 0x40\nBit [6]= Enhanced Flush\n"));
2546 pSupportedCmds[19] = 0x40;
2547 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"));
2548 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"));
2549 pSupportedCmds[21] = 0xff;
2550 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"));
2551 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"));
2552 pSupportedCmds[22] = 0xff;
2553 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"));
2554 pSupportedCmds[23] = 0x07;
2555 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"));
2556 pSupportedCmds[24] = 0x1c;
2558 PPacketIrpEvent->Length = len;
2560 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2565 static enum hci_status bthci_CmdReadLocalSupportedFeatures(struct rtw_adapter *padapter)
2567 enum hci_status status = HCI_STATUS_SUCCESS;
2568 u8 localBuf[TmpLocalBufSize] = "";
2571 struct packet_irp_hcievent_data *PPacketIrpEvent;
2573 /* send command complete event here when all data are received. */
2574 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2575 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2577 len += bthci_CommandCompleteHeader(&localBuf[0],
2578 OGF_INFORMATIONAL_PARAMETERS,
2579 HCI_READ_LOCAL_SUPPORTED_FEATURES,
2582 /* Return parameters starts from here */
2583 pRetPar = &PPacketIrpEvent->Data[len];
2584 pRetPar[0] = status; /* status */
2586 PPacketIrpEvent->Length = len;
2588 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2592 static enum hci_status bthci_CmdReadLocalAMPAssoc(struct rtw_adapter *padapter,
2593 struct packet_irp_hcicmd_data *pHciCmd)
2595 enum hci_status status = HCI_STATUS_SUCCESS;
2596 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2597 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
2598 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2599 u8 PhyLinkHandle, EntryNum;
2601 pBtDbg->dbgHciInfo.hciCmdCntReadLocalAmpAssoc++;
2602 PhyLinkHandle = *((u8 *)pHciCmd->Data);
2603 EntryNum = bthci_GetCurrentEntryNum(padapter, PhyLinkHandle);
2605 if ((EntryNum == 0xff) && PhyLinkHandle != 0) {
2606 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x\n",
2607 EntryNum, PhyLinkHandle));
2608 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2609 } else if (pBtMgnt->bPhyLinkInProgressStartLL) {
2610 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2611 pBtMgnt->bPhyLinkInProgressStartLL = false;
2613 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.BtPhyLinkhandle = *((u8 *)pHciCmd->Data);
2614 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar = *((u16 *)((u8 *)pHciCmd->Data+1));
2615 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen = *((u16 *)((u8 *)pHciCmd->Data+3));
2616 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("ReadLocalAMPAssoc, LenSoFar =%d, MaxRemoteASSOCLen =%d\n",
2617 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar,
2618 pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.MaxRemoteASSOCLen));
2621 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, EntryNum = %d !!!!!, physical link handle = 0x%x, LengthSoFar = %x \n",
2622 EntryNum, PhyLinkHandle, pBTInfo->BtAsocEntry[EntryNum].AmpAsocCmdData.LenSoFar));
2624 /* send command complete event here when all data are received. */
2626 struct packet_irp_hcievent_data *PPacketIrpEvent;
2628 /* PVOID buffer = padapter->IrpHCILocalbuf.Ptr; */
2629 u8 localBuf[TmpLocalBufSize] = "";
2632 u16 typeLen = 0, remainLen = 0, ret_index = 0;
2635 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2636 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2637 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2639 totalLen += bthci_CommandCompleteHeader(&localBuf[0],
2640 OGF_STATUS_PARAMETERS,
2641 HCI_READ_LOCAL_AMP_ASSOC,
2643 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2644 /* Return parameters starts from here */
2645 pRetPar = &PPacketIrpEvent->Data[totalLen];
2646 pRetPar[0] = status; /* status */
2647 pRetPar[1] = *((u8 *)pHciCmd->Data);
2648 pRemainLen = (u16 *)&pRetPar[2]; /* AMP_ASSOC_Remaining_Length */
2649 totalLen += 4; /* 0]~[3] */
2652 typeLen = bthci_AssocMACAddr(padapter, &pRetPar[ret_index]);
2653 totalLen += typeLen;
2654 remainLen += typeLen;
2655 ret_index += typeLen;
2656 typeLen = bthci_AssocPreferredChannelList(padapter, &pRetPar[ret_index], EntryNum);
2657 totalLen += typeLen;
2658 remainLen += typeLen;
2659 ret_index += typeLen;
2660 typeLen = bthci_PALCapabilities(padapter, &pRetPar[ret_index]);
2661 totalLen += typeLen;
2662 remainLen += typeLen;
2663 ret_index += typeLen;
2664 typeLen = bthci_AssocPALVer(padapter, &pRetPar[ret_index]);
2665 totalLen += typeLen;
2666 remainLen += typeLen;
2667 PPacketIrpEvent->Length = (u8)totalLen;
2668 *pRemainLen = remainLen; /* AMP_ASSOC_Remaining_Length */
2669 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("ReadLocalAMPAssoc, Remaining_Len =%d \n", remainLen));
2670 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("AMP_ASSOC_fragment : \n"), PPacketIrpEvent->Data, totalLen);
2672 bthci_IndicateEvent(padapter, PPacketIrpEvent, totalLen+2);
2678 static enum hci_status bthci_CmdReadFailedContactCounter(struct rtw_adapter *padapter,
2679 struct packet_irp_hcicmd_data *pHciCmd)
2682 enum hci_status status = HCI_STATUS_SUCCESS;
2683 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2684 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2685 u8 localBuf[TmpLocalBufSize] = "";
2688 struct packet_irp_hcievent_data *PPacketIrpEvent;
2691 handle = *((u16 *)pHciCmd->Data);
2692 /* send command complete event here when all data are received. */
2693 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2694 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2696 len += bthci_CommandCompleteHeader(&localBuf[0],
2697 OGF_STATUS_PARAMETERS,
2698 HCI_READ_FAILED_CONTACT_COUNTER,
2701 /* Return parameters starts from here */
2702 pRetPar = &PPacketIrpEvent->Data[len];
2703 pRetPar[0] = status; /* status */
2704 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2705 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2706 pRetPar[3] = TWOBYTE_LOWBYTE(pBtHciInfo->FailContactCount);
2707 pRetPar[4] = TWOBYTE_HIGHTBYTE(pBtHciInfo->FailContactCount);
2709 PPacketIrpEvent->Length = len;
2711 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2716 static enum hci_status
2717 bthci_CmdResetFailedContactCounter(
2718 struct rtw_adapter *padapter,
2719 struct packet_irp_hcicmd_data *pHciCmd
2722 enum hci_status status = HCI_STATUS_SUCCESS;
2723 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
2724 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2725 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
2727 u8 localBuf[TmpLocalBufSize] = "";
2730 struct packet_irp_hcievent_data *PPacketIrpEvent;
2732 handle = *((u16 *)pHciCmd->Data);
2733 pBtHciInfo->FailContactCount = 0;
2735 /* send command complete event here when all data are received. */
2736 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2737 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2738 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2740 len += bthci_CommandCompleteHeader(&localBuf[0],
2741 OGF_STATUS_PARAMETERS,
2742 HCI_RESET_FAILED_CONTACT_COUNTER,
2745 /* Return parameters starts from here */
2746 pRetPar = &PPacketIrpEvent->Data[len];
2747 pRetPar[0] = status; /* status */
2748 pRetPar[1] = TWOBYTE_LOWBYTE(handle);
2749 pRetPar[2] = TWOBYTE_HIGHTBYTE(handle);
2751 PPacketIrpEvent->Length = len;
2753 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2758 /* BT 3.0+HS [Vol 2] 7.4.1 */
2760 static enum hci_status
2761 bthci_CmdReadLocalVersionInformation(
2762 struct rtw_adapter *padapter
2765 enum hci_status status = HCI_STATUS_SUCCESS;
2766 /* send command complete event here when all data are received. */
2767 u8 localBuf[TmpLocalBufSize] = "";
2770 struct packet_irp_hcievent_data *PPacketIrpEvent;
2773 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2774 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2776 len += bthci_CommandCompleteHeader(&localBuf[0],
2777 OGF_INFORMATIONAL_PARAMETERS,
2778 HCI_READ_LOCAL_VERSION_INFORMATION,
2781 /* Return parameters starts from here */
2782 pRetPar = &PPacketIrpEvent->Data[len];
2783 pRetPar[0] = status; /* status */
2784 pRetPar[1] = 0x05; /* HCI_Version */
2785 pu2Temp = (u16 *)&pRetPar[2]; /* HCI_Revision */
2787 pRetPar[4] = 0x05; /* LMP/PAL_Version */
2788 pu2Temp = (u16 *)&pRetPar[5]; /* Manufacturer_Name */
2790 pu2Temp = (u16 *)&pRetPar[7]; /* LMP/PAL_Subversion */
2793 PPacketIrpEvent->Length = len;
2795 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LOCAL_VERSION_INFORMATION\n"));
2796 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Status %x\n", status));
2797 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Version = 0x05\n"));
2798 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI_Revision = 0x0001\n"));
2799 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Version = 0x05\n"));
2800 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("Manufacturer_Name = 0x0001\n"));
2801 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("LMP/PAL_Subversion = 0x0001\n"));
2803 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2809 static enum hci_status bthci_CmdReadDataBlockSize(struct rtw_adapter *padapter)
2811 enum hci_status status = HCI_STATUS_SUCCESS;
2812 u8 localBuf[TmpLocalBufSize] = "";
2815 struct packet_irp_hcievent_data *PPacketIrpEvent;
2818 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2819 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2821 len += bthci_CommandCompleteHeader(&localBuf[0],
2822 OGF_INFORMATIONAL_PARAMETERS,
2823 HCI_READ_DATA_BLOCK_SIZE,
2826 /* Return parameters starts from here */
2827 pRetPar = &PPacketIrpEvent->Data[len];
2828 pRetPar[0] = HCI_STATUS_SUCCESS; /* status */
2829 pu2Temp = (u16 *)&pRetPar[1]; /* Max_ACL_Data_Packet_Length */
2830 *pu2Temp = Max80211PALPDUSize;
2832 pu2Temp = (u16 *)&pRetPar[3]; /* Data_Block_Length */
2833 *pu2Temp = Max80211PALPDUSize;
2834 pu2Temp = (u16 *)&pRetPar[5]; /* Total_Num_Data_Blocks */
2835 *pu2Temp = BTTotalDataBlockNum;
2837 PPacketIrpEvent->Length = len;
2839 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2845 static enum hci_status bthci_CmdReadBufferSize(struct rtw_adapter *padapter)
2847 enum hci_status status = HCI_STATUS_SUCCESS;
2848 u8 localBuf[TmpLocalBufSize] = "";
2851 struct packet_irp_hcievent_data *PPacketIrpEvent;
2854 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2855 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2856 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2858 len += bthci_CommandCompleteHeader(&localBuf[0],
2859 OGF_INFORMATIONAL_PARAMETERS,
2860 HCI_READ_BUFFER_SIZE,
2862 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Synchronous_Data_Packet_Length = 0x%x\n", BTSynDataPacketLength));
2863 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_ACL_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2864 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("Total_Num_Synchronous_Data_Packets = 0x%x\n", BTTotalDataBlockNum));
2865 /* Return parameters starts from here */
2866 pRetPar = &PPacketIrpEvent->Data[len];
2867 pRetPar[0] = status; /* status */
2868 pu2Temp = (u16 *)&pRetPar[1]; /* HC_ACL_Data_Packet_Length */
2869 *pu2Temp = Max80211PALPDUSize;
2871 pRetPar[3] = BTSynDataPacketLength; /* HC_Synchronous_Data_Packet_Length */
2872 pu2Temp = (u16 *)&pRetPar[4]; /* HC_Total_Num_ACL_Data_Packets */
2873 *pu2Temp = BTTotalDataBlockNum;
2874 pu2Temp = (u16 *)&pRetPar[6]; /* HC_Total_Num_Synchronous_Data_Packets */
2875 *pu2Temp = BTTotalDataBlockNum;
2877 PPacketIrpEvent->Length = len;
2879 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2884 static enum hci_status bthci_CmdReadLocalAMPInfo(struct rtw_adapter *padapter)
2886 enum hci_status status = HCI_STATUS_SUCCESS;
2887 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
2888 u8 localBuf[TmpLocalBufSize] = "";
2891 struct packet_irp_hcievent_data *PPacketIrpEvent;
2894 u32 TotalBandwidth = BTTOTALBANDWIDTH, MaxBandGUBandwidth = BTMAXBANDGUBANDWIDTH;
2895 u8 ControlType = 0x01, AmpStatus = 0x01;
2896 u32 MaxFlushTimeout = 10000, BestEffortFlushTimeout = 5000;
2897 u16 MaxPDUSize = Max80211PALPDUSize, PalCap = 0x1, AmpAssocLen = Max80211AMPASSOCLen, MinLatency = 20;
2899 if ((ppwrctrl->rfoff_reason & RF_CHANGE_BY_HW) ||
2900 (ppwrctrl->rfoff_reason & RF_CHANGE_BY_SW)) {
2901 AmpStatus = AMP_STATUS_NO_CAPACITY_FOR_BT;
2904 PlatformZeroMemory(&localBuf[0], TmpLocalBufSize);
2905 /* PPacketIrpEvent = (struct packet_irp_hcievent_data *)(buffer); */
2906 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2908 len += bthci_CommandCompleteHeader(&localBuf[0],
2909 OGF_STATUS_PARAMETERS,
2910 HCI_READ_LOCAL_AMP_INFO,
2913 /* Return parameters starts from here */
2914 pRetPar = &PPacketIrpEvent->Data[len];
2915 pRetPar[0] = status; /* status */
2916 pRetPar[1] = AmpStatus; /* AMP_Status */
2917 pu4Temp = (u32 *)&pRetPar[2]; /* Total_Bandwidth */
2918 *pu4Temp = TotalBandwidth; /* 0x19bfcc00;0x7530; */
2919 pu4Temp = (u32 *)&pRetPar[6]; /* Max_Guaranteed_Bandwidth */
2920 *pu4Temp = MaxBandGUBandwidth; /* 0x19bfcc00;0x4e20; */
2921 pu4Temp = (u32 *)&pRetPar[10]; /* Min_Latency */
2922 *pu4Temp = MinLatency; /* 150; */
2923 pu4Temp = (u32 *)&pRetPar[14]; /* Max_PDU_Size */
2924 *pu4Temp = MaxPDUSize;
2925 pRetPar[18] = ControlType; /* Controller_Type */
2926 pu2Temp = (u16 *)&pRetPar[19]; /* PAL_Capabilities */
2928 pu2Temp = (u16 *)&pRetPar[21]; /* AMP_ASSOC_Length */
2929 *pu2Temp = AmpAssocLen;
2930 pu4Temp = (u32 *)&pRetPar[23]; /* Max_Flush_Timeout */
2931 *pu4Temp = MaxFlushTimeout;
2932 pu4Temp = (u32 *)&pRetPar[27]; /* Best_Effort_Flush_Timeout */
2933 *pu4Temp = BestEffortFlushTimeout;
2935 PPacketIrpEvent->Length = len;
2936 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("AmpStatus = 0x%x\n",
2938 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TotalBandwidth = 0x%x, MaxBandGUBandwidth = 0x%x, MinLatency = 0x%x, \n MaxPDUSize = 0x%x, ControlType = 0x%x\n",
2939 TotalBandwidth, MaxBandGUBandwidth, MinLatency, MaxPDUSize, ControlType));
2940 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PalCap = 0x%x, AmpAssocLen = 0x%x, MaxFlushTimeout = 0x%x, BestEffortFlushTimeout = 0x%x\n",
2941 PalCap, AmpAssocLen, MaxFlushTimeout, BestEffortFlushTimeout));
2942 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
2946 static enum hci_status
2947 bthci_CmdCreatePhysicalLink(
2948 struct rtw_adapter *padapter,
2949 struct packet_irp_hcicmd_data *pHciCmd
2952 enum hci_status status;
2953 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2954 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
2956 pBtDbg->dbgHciInfo.hciCmdCntCreatePhyLink++;
2958 status = bthci_BuildPhysicalLink(padapter,
2959 pHciCmd, HCI_CREATE_PHYSICAL_LINK);
2964 static enum hci_status
2965 bthci_CmdReadLinkQuality(
2966 struct rtw_adapter *padapter,
2967 struct packet_irp_hcicmd_data *pHciCmd
2970 enum hci_status status = HCI_STATUS_SUCCESS;
2971 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2973 u8 EntryNum, LinkQuality = 0x55;
2975 PLH = *((u16 *)&pHciCmd->Data[0]);
2976 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("PLH = 0x%x\n", PLH));
2978 EntryNum = bthci_GetCurrentEntryNum(padapter, (u8)PLH);
2979 if (EntryNum == 0xff) {
2980 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("No such PLH(0x%x)\n", PLH));
2981 status = HCI_STATUS_UNKNOW_CONNECT_ID;
2985 u8 localBuf[11] = "";
2988 struct packet_irp_hcievent_data *PPacketIrpEvent;
2990 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
2992 len += bthci_CommandCompleteHeader(&localBuf[0],
2993 OGF_STATUS_PARAMETERS,
2994 HCI_READ_LINK_QUALITY,
2997 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" PLH = 0x%x\n Link Quality = 0x%x\n", PLH, LinkQuality));
2999 /* Return parameters starts from here */
3000 pRetPar = &PPacketIrpEvent->Data[len];
3001 pRetPar[0] = status; /* status */
3002 *((u16 *)&pRetPar[1]) = pBTInfo->BtAsocEntry[EntryNum].PhyLinkCmdData.BtPhyLinkhandle; /* Handle */
3003 pRetPar[3] = 0x55; /* Link Quailty */
3005 PPacketIrpEvent->Length = len;
3007 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3013 static enum hci_status bthci_CmdReadRSSI(struct rtw_adapter *padapter)
3015 enum hci_status status = HCI_STATUS_SUCCESS;
3019 static enum hci_status
3020 bthci_CmdCreateLogicalLink(
3021 struct rtw_adapter *padapter,
3022 struct packet_irp_hcicmd_data *pHciCmd
3025 enum hci_status status = HCI_STATUS_SUCCESS;
3026 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3027 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3029 pBtDbg->dbgHciInfo.hciCmdCntCreateLogLink++;
3031 bthci_BuildLogicalLink(padapter, pHciCmd,
3032 HCI_CREATE_LOGICAL_LINK);
3037 static enum hci_status
3038 bthci_CmdAcceptLogicalLink(
3039 struct rtw_adapter *padapter,
3040 struct packet_irp_hcicmd_data *pHciCmd
3043 enum hci_status status = HCI_STATUS_SUCCESS;
3044 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3045 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3047 pBtDbg->dbgHciInfo.hciCmdCntAcceptLogLink++;
3049 bthci_BuildLogicalLink(padapter, pHciCmd,
3050 HCI_ACCEPT_LOGICAL_LINK);
3055 static enum hci_status
3056 bthci_CmdDisconnectLogicalLink(
3057 struct rtw_adapter *padapter,
3058 struct packet_irp_hcicmd_data *pHciCmd
3061 enum hci_status status = HCI_STATUS_SUCCESS;
3062 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3063 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3064 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3065 struct bt_dgb *pBtDbg = &pBTinfo->BtDbg;
3067 u8 i, j, find = 0, LogLinkCount = 0;
3069 pBtDbg->dbgHciInfo.hciCmdCntDisconnectLogLink++;
3071 logicHandle = *((u16 *)pHciCmd->Data);
3072 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle = 0x%x\n", logicHandle));
3074 /* find an created logical link index and clear the data */
3075 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3076 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3077 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3078 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("DisconnectLogicalLink, logicHandle is matched 0x%x\n", logicHandle));
3079 bthci_ResetFlowSpec(padapter, j, i);
3081 pBtMgnt->DisconnectEntryNum = j;
3088 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3091 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3092 if (pBTinfo->BtAsocEntry[pBtMgnt->DisconnectEntryNum].LogLinkCmdData[i].BtLogLinkhandle != 0)
3096 /* When we receive Create logical link command, we should send command status event first. */
3097 bthci_EventCommandStatus(padapter,
3098 LINK_CONTROL_COMMANDS,
3099 HCI_DISCONNECT_LOGICAL_LINK,
3102 /* When we determines the logical link is established, we should send command complete event. */
3104 if (status == HCI_STATUS_SUCCESS) {
3105 bthci_EventDisconnectLogicalLinkComplete(padapter, status,
3106 logicHandle, HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST);
3109 if (LogLinkCount == 0)
3110 mod_timer(&pBTinfo->BTDisconnectPhyLinkTimer,
3111 jiffies + msecs_to_jiffies(100));
3116 static enum hci_status
3117 bthci_CmdLogicalLinkCancel(struct rtw_adapter *padapter,
3118 struct packet_irp_hcicmd_data *pHciCmd)
3120 enum hci_status status = HCI_STATUS_SUCCESS;
3121 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3122 struct bt_mgnt *pBtMgnt = &pBTinfo->BtMgnt;
3123 u8 CurrentEntryNum, CurrentLogEntryNum;
3125 u8 physicalLinkHandle, TxFlowSpecID, i;
3126 u16 CurrentLogicalHandle;
3128 physicalLinkHandle = *((u8 *)pHciCmd->Data);
3129 TxFlowSpecID = *(((u8 *)pHciCmd->Data)+1);
3131 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, physicalLinkHandle = 0x%x, TxFlowSpecID = 0x%x\n",
3132 physicalLinkHandle, TxFlowSpecID));
3134 CurrentEntryNum = pBtMgnt->CurrentConnectEntryNum;
3135 CurrentLogicalHandle = pBtMgnt->BtCurrentLogLinkhandle;
3137 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("CurrentEntryNum = 0x%x, CurrentLogicalHandle = 0x%x\n",
3138 CurrentEntryNum, CurrentLogicalHandle));
3140 CurrentLogEntryNum = 0xff;
3141 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3142 if ((CurrentLogicalHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtLogLinkhandle) &&
3143 (physicalLinkHandle == pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[i].BtPhyLinkhandle)) {
3144 CurrentLogEntryNum = i;
3149 if (CurrentLogEntryNum == 0xff) {
3150 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, CurrentLogEntryNum == 0xff !!!!\n"));
3151 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3154 if (pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCompleteEventIsSet) {
3155 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("LogicalLinkCancel, LLCompleteEventIsSet!!!!\n"));
3156 status = HCI_STATUS_ACL_CONNECT_EXISTS;
3161 u8 localBuf[8] = "";
3164 struct packet_irp_hcievent_data *PPacketIrpEvent;
3166 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3168 len += bthci_CommandCompleteHeader(&localBuf[0],
3169 LINK_CONTROL_COMMANDS,
3170 HCI_LOGICAL_LINK_CANCEL,
3173 /* Return parameters starts from here */
3174 pRetPar = &PPacketIrpEvent->Data[len];
3175 pRetPar[0] = status; /* status */
3176 pRetPar[1] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtPhyLinkhandle;
3177 pRetPar[2] = pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].BtTxFlowSpecID;
3179 PPacketIrpEvent->Length = len;
3181 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3184 pBTinfo->BtAsocEntry[CurrentEntryNum].LogLinkCmdData[CurrentLogEntryNum].bLLCancelCMDIsSetandComplete = true;
3189 static enum hci_status
3190 bthci_CmdFlowSpecModify(struct rtw_adapter *padapter,
3191 struct packet_irp_hcicmd_data *pHciCmd)
3193 enum hci_status status = HCI_STATUS_SUCCESS;
3194 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3195 struct bt_30info *pBTinfo = GET_BT_INFO(padapter);
3199 logicHandle = *((u16 *)pHciCmd->Data);
3200 /* find an matched logical link index and copy the data */
3201 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
3202 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
3203 if (pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle == logicHandle) {
3204 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec,
3205 &pHciCmd->Data[2], sizeof(struct hci_flow_spec));
3206 memcpy(&pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Rx_Flow_Spec,
3207 &pHciCmd->Data[18], sizeof(struct hci_flow_spec));
3209 bthci_CheckLogLinkBehavior(padapter, pBTinfo->BtAsocEntry[j].LogLinkCmdData[i].Tx_Flow_Spec);
3215 RTPRINT(FIOCTL, IOCTL_BT_LOGO, ("FlowSpecModify, LLH = 0x%x, \n", logicHandle));
3217 /* When we receive Flow Spec Modify command, we should send command status event first. */
3218 bthci_EventCommandStatus(padapter,
3219 LINK_CONTROL_COMMANDS,
3220 HCI_FLOW_SPEC_MODIFY,
3221 HCI_STATUS_SUCCESS);
3224 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3226 bthci_EventSendFlowSpecModifyComplete(padapter, status, logicHandle);
3231 static enum hci_status
3232 bthci_CmdAcceptPhysicalLink(struct rtw_adapter *padapter,
3233 struct packet_irp_hcicmd_data *pHciCmd)
3235 enum hci_status status;
3236 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3237 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3239 pBtDbg->dbgHciInfo.hciCmdCntAcceptPhyLink++;
3241 status = bthci_BuildPhysicalLink(padapter,
3242 pHciCmd, HCI_ACCEPT_PHYSICAL_LINK);
3247 static enum hci_status
3248 bthci_CmdDisconnectPhysicalLink(struct rtw_adapter *padapter,
3249 struct packet_irp_hcicmd_data *pHciCmd)
3251 enum hci_status status = HCI_STATUS_SUCCESS;
3252 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3253 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3254 u8 PLH, CurrentEntryNum, PhysLinkDisconnectReason;
3256 pBtDbg->dbgHciInfo.hciCmdCntDisconnectPhyLink++;
3258 PLH = *((u8 *)pHciCmd->Data);
3259 PhysLinkDisconnectReason = (*((u8 *)pHciCmd->Data+1));
3260 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK PhyHandle = 0x%x, Reason = 0x%x\n",
3261 PLH, PhysLinkDisconnectReason));
3263 CurrentEntryNum = bthci_GetCurrentEntryNum(padapter, PLH);
3265 if (CurrentEntryNum == 0xff) {
3266 RTPRINT(FIOCTL, IOCTL_BT_HCICMD,
3267 ("DisconnectPhysicalLink, No such Handle in the Entry\n"));
3268 status = HCI_STATUS_UNKNOW_CONNECT_ID;
3270 pBTInfo->BtAsocEntry[CurrentEntryNum].PhyLinkDisconnectReason =
3271 (enum hci_status)PhysLinkDisconnectReason;
3273 /* Send HCI Command status event to AMP. */
3274 bthci_EventCommandStatus(padapter, LINK_CONTROL_COMMANDS,
3275 HCI_DISCONNECT_PHYSICAL_LINK, status);
3277 if (status != HCI_STATUS_SUCCESS)
3280 /* The macros below require { and } in the if statement */
3281 if (pBTInfo->BtAsocEntry[CurrentEntryNum].BtCurrentState == HCI_STATE_DISCONNECTED) {
3282 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3284 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_DISCONNECT_PHY_LINK, CurrentEntryNum);
3289 static enum hci_status
3290 bthci_CmdSetACLLinkDataFlowMode(struct rtw_adapter *padapter,
3291 struct packet_irp_hcicmd_data *pHciCmd)
3293 enum hci_status status = HCI_STATUS_SUCCESS;
3294 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3295 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3296 u8 localBuf[8] = "";
3299 struct packet_irp_hcievent_data *PPacketIrpEvent;
3302 pBtMgnt->ExtConfig.CurrentConnectHandle = *((u16 *)pHciCmd->Data);
3303 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode = *((u8 *)pHciCmd->Data)+2;
3304 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode = *((u8 *)pHciCmd->Data)+3;
3305 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Connection Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic mode = 0x%x",
3306 pBtMgnt->ExtConfig.CurrentConnectHandle,
3307 pBtMgnt->ExtConfig.CurrentIncomingTrafficMode,
3308 pBtMgnt->ExtConfig.CurrentOutgoingTrafficMode));
3311 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3313 len += bthci_CommandCompleteHeader(&localBuf[0],
3315 HCI_SET_ACL_LINK_DATA_FLOW_MODE,
3318 /* Return parameters starts from here */
3319 pRetPar = &PPacketIrpEvent->Data[len];
3320 pRetPar[0] = status; /* status */
3322 pu2Temp = (u16 *)&pRetPar[1];
3323 *pu2Temp = pBtMgnt->ExtConfig.CurrentConnectHandle;
3325 PPacketIrpEvent->Length = len;
3327 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3331 static enum hci_status
3332 bthci_CmdSetACLLinkStatus(struct rtw_adapter *padapter,
3333 struct packet_irp_hcicmd_data *pHciCmd)
3335 enum hci_status status = HCI_STATUS_SUCCESS;
3336 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3337 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3338 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3342 pBtDbg->dbgHciInfo.hciCmdCntSetAclLinkStatus++;
3343 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "SetACLLinkStatus, Hex Data :\n",
3344 &pHciCmd->Data[0], pHciCmd->Length);
3346 /* Only Core Stack v251 and later version support this command. */
3347 pBtMgnt->bSupportProfile = true;
3349 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3350 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3352 pTriple = &pHciCmd->Data[1];
3353 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3354 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3355 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = pTriple[2];
3356 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = pTriple[3];
3357 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3358 ("Connection_Handle = 0x%x, Incoming Traffic mode = 0x%x, Outgoing Traffic Mode = 0x%x\n",
3359 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3360 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode,
3361 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode));
3366 u8 localBuf[6] = "";
3369 struct packet_irp_hcievent_data *PPacketIrpEvent;
3371 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3373 len += bthci_CommandCompleteHeader(&localBuf[0],
3375 HCI_SET_ACL_LINK_STATUS,
3378 /* Return parameters starts from here */
3379 pRetPar = &PPacketIrpEvent->Data[len];
3380 pRetPar[0] = status; /* status */
3383 PPacketIrpEvent->Length = len;
3385 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3391 static enum hci_status
3392 bthci_CmdSetSCOLinkStatus(
3393 struct rtw_adapter *padapter,
3394 struct packet_irp_hcicmd_data *pHciCmd
3397 enum hci_status status = HCI_STATUS_SUCCESS;
3398 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3399 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3400 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3402 pBtDbg->dbgHciInfo.hciCmdCntSetScoLinkStatus++;
3403 pBtMgnt->ExtConfig.NumberOfSCO = *((u8 *)pHciCmd->Data);
3404 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfSCO = 0x%x\n",
3405 pBtMgnt->ExtConfig.NumberOfSCO));
3408 u8 localBuf[6] = "";
3411 struct packet_irp_hcievent_data *PPacketIrpEvent;
3413 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3415 len += bthci_CommandCompleteHeader(&localBuf[0],
3417 HCI_SET_SCO_LINK_STATUS,
3420 /* Return parameters starts from here */
3421 pRetPar = &PPacketIrpEvent->Data[len];
3422 pRetPar[0] = status; /* status */
3425 PPacketIrpEvent->Length = len;
3427 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3433 static enum hci_status
3434 bthci_CmdSetRSSIValue(
3435 struct rtw_adapter *padapter,
3436 struct packet_irp_hcicmd_data *pHciCmd
3439 enum hci_status status = HCI_STATUS_SUCCESS;
3440 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3441 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3444 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3445 if (pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle == *((u16 *)&pHciCmd->Data[0])) {
3446 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI = (s8)(pHciCmd->Data[2]);
3447 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL,
3448 ("Connection_Handle = 0x%x, RSSI = %d \n",
3449 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3450 pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI));
3452 /* get the minimum bt rssi value */
3453 if (pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI <= min_bt_rssi)
3454 min_bt_rssi = pBtMgnt->ExtConfig.linkInfo[i].BT_RSSI;
3457 pBtMgnt->ExtConfig.MIN_BT_RSSI = min_bt_rssi;
3458 RTPRINT(FBT, BT_TRACE, ("[bt rssi], the min rssi is %d\n", min_bt_rssi));
3461 u8 localBuf[6] = "";
3464 struct packet_irp_hcievent_data *PPacketIrpEvent;
3466 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3468 len += bthci_CommandCompleteHeader(&localBuf[0],
3473 /* Return parameters starts from here */
3474 pRetPar = &PPacketIrpEvent->Data[len];
3475 pRetPar[0] = status; /* status */
3478 PPacketIrpEvent->Length = len;
3480 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3486 static enum hci_status
3487 bthci_CmdSetCurrentBluetoothStatus(
3488 struct rtw_adapter *padapter,
3489 struct packet_irp_hcicmd_data *pHciCmd
3492 enum hci_status status = HCI_STATUS_SUCCESS;
3493 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
3494 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3495 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3497 pBtMgnt->ExtConfig.CurrentBTStatus = *((u8 *)&pHciCmd->Data[0]);
3498 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("SetCurrentBluetoothStatus, CurrentBTStatus = 0x%x\n",
3499 pBtMgnt->ExtConfig.CurrentBTStatus));
3502 u8 localBuf[6] = "";
3505 struct packet_irp_hcievent_data *PPacketIrpEvent;
3507 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3509 len += bthci_CommandCompleteHeader(&localBuf[0],
3511 HCI_SET_CURRENT_BLUETOOTH_STATUS,
3514 /* Return parameters starts from here */
3515 pRetPar = &PPacketIrpEvent->Data[len];
3516 pRetPar[0] = status; /* status */
3519 PPacketIrpEvent->Length = len;
3521 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3527 static enum hci_status
3528 bthci_CmdExtensionVersionNotify(
3529 struct rtw_adapter *padapter,
3530 struct packet_irp_hcicmd_data *pHciCmd
3533 enum hci_status status = HCI_STATUS_SUCCESS;
3534 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3535 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3536 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3538 pBtDbg->dbgHciInfo.hciCmdCntExtensionVersionNotify++;
3539 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "ExtensionVersionNotify, Hex Data :\n",
3540 &pHciCmd->Data[0], pHciCmd->Length);
3542 pBtMgnt->ExtConfig.HCIExtensionVer = *((u16 *)&pHciCmd->Data[0]);
3543 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = 0x%x\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3546 u8 localBuf[6] = "";
3549 struct packet_irp_hcievent_data *PPacketIrpEvent;
3551 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3553 len += bthci_CommandCompleteHeader(&localBuf[0],
3555 HCI_EXTENSION_VERSION_NOTIFY,
3558 /* Return parameters starts from here */
3559 pRetPar = &PPacketIrpEvent->Data[len];
3560 pRetPar[0] = status; /* status */
3563 PPacketIrpEvent->Length = len;
3565 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3571 static enum hci_status
3572 bthci_CmdLinkStatusNotify(
3573 struct rtw_adapter *padapter,
3574 struct packet_irp_hcicmd_data *pHciCmd
3577 enum hci_status status = HCI_STATUS_SUCCESS;
3578 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3579 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3580 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3584 pBtDbg->dbgHciInfo.hciCmdCntLinkStatusNotify++;
3585 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "LinkStatusNotify, Hex Data :\n",
3586 &pHciCmd->Data[0], pHciCmd->Length);
3588 /* Current only RTL8723 support this command. */
3589 pBtMgnt->bSupportProfile = true;
3591 pBtMgnt->ExtConfig.NumberOfHandle = *((u8 *)pHciCmd->Data);
3592 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("NumberOfHandle = 0x%x\n", pBtMgnt->ExtConfig.NumberOfHandle));
3593 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCIExtensionVer = %d\n", pBtMgnt->ExtConfig.HCIExtensionVer));
3595 pTriple = &pHciCmd->Data[1];
3596 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
3597 if (pBtMgnt->ExtConfig.HCIExtensionVer < 1) {
3598 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3599 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3600 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3601 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3602 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d\n",
3603 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3604 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3605 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec));
3607 } else if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
3608 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle = *((u16 *)&pTriple[0]);
3609 pBtMgnt->ExtConfig.linkInfo[i].BTProfile = pTriple[2];
3610 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec = pTriple[3];
3611 pBtMgnt->ExtConfig.linkInfo[i].linkRole = pTriple[4];
3612 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT,
3613 ("Connection_Handle = 0x%x, BTProfile =%d, BTSpec =%d, LinkRole =%d\n",
3614 pBtMgnt->ExtConfig.linkInfo[i].ConnectHandle,
3615 pBtMgnt->ExtConfig.linkInfo[i].BTProfile,
3616 pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec,
3617 pBtMgnt->ExtConfig.linkInfo[i].linkRole));
3622 BTHCI_UpdateBTProfileRTKToMoto(padapter);
3624 u8 localBuf[6] = "";
3627 struct packet_irp_hcievent_data *PPacketIrpEvent;
3629 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3631 len += bthci_CommandCompleteHeader(&localBuf[0],
3633 HCI_LINK_STATUS_NOTIFY,
3636 /* Return parameters starts from here */
3637 pRetPar = &PPacketIrpEvent->Data[len];
3638 pRetPar[0] = status; /* status */
3641 PPacketIrpEvent->Length = len;
3643 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3649 static enum hci_status
3650 bthci_CmdBtOperationNotify(
3651 struct rtw_adapter *padapter,
3652 struct packet_irp_hcicmd_data *pHciCmd
3655 enum hci_status status = HCI_STATUS_SUCCESS;
3656 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3657 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3659 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Bt Operation notify, Hex Data :\n",
3660 &pHciCmd->Data[0], pHciCmd->Length);
3662 pBtMgnt->ExtConfig.btOperationCode = *((u8 *)pHciCmd->Data);
3663 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("btOperationCode = 0x%x\n", pBtMgnt->ExtConfig.btOperationCode));
3664 switch (pBtMgnt->ExtConfig.btOperationCode) {
3665 case HCI_BT_OP_NONE:
3666 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Operation None!!\n"));
3668 case HCI_BT_OP_INQUIRY_START:
3669 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire start!!\n"));
3671 case HCI_BT_OP_INQUIRY_FINISH:
3672 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Inquire finished!!\n"));
3674 case HCI_BT_OP_PAGING_START:
3675 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging is started!!\n"));
3677 case HCI_BT_OP_PAGING_SUCCESS:
3678 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete successfully!!\n"));
3680 case HCI_BT_OP_PAGING_UNSUCCESS:
3681 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Paging complete unsuccessfully!!\n"));
3683 case HCI_BT_OP_PAIRING_START:
3684 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing start!!\n"));
3686 case HCI_BT_OP_PAIRING_FINISH:
3687 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Pairing finished!!\n"));
3689 case HCI_BT_OP_BT_DEV_ENABLE:
3690 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is enabled!!\n"));
3692 case HCI_BT_OP_BT_DEV_DISABLE:
3693 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : BT Device is disabled!!\n"));
3696 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[bt operation] : Unknown, error!!\n"));
3699 BTDM_AdjustForBtOperation(padapter);
3701 u8 localBuf[6] = "";
3704 struct packet_irp_hcievent_data *PPacketIrpEvent;
3706 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3708 len += bthci_CommandCompleteHeader(&localBuf[0],
3710 HCI_BT_OPERATION_NOTIFY,
3713 /* Return parameters starts from here */
3714 pRetPar = &PPacketIrpEvent->Data[len];
3715 pRetPar[0] = status; /* status */
3718 PPacketIrpEvent->Length = len;
3720 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3726 static enum hci_status
3727 bthci_CmdEnableWifiScanNotify(struct rtw_adapter *padapter,
3728 struct packet_irp_hcicmd_data *pHciCmd)
3730 enum hci_status status = HCI_STATUS_SUCCESS;
3731 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3732 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
3734 RTPRINT_DATA(FIOCTL, IOCTL_BT_HCICMD_EXT, "Enable Wifi scan notify, Hex Data :\n",
3735 &pHciCmd->Data[0], pHciCmd->Length);
3737 pBtMgnt->ExtConfig.bEnableWifiScanNotify = *((u8 *)pHciCmd->Data);
3738 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("bEnableWifiScanNotify = %d\n", pBtMgnt->ExtConfig.bEnableWifiScanNotify));
3741 u8 localBuf[6] = "";
3744 struct packet_irp_hcievent_data *PPacketIrpEvent;
3746 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3748 len += bthci_CommandCompleteHeader(&localBuf[0],
3750 HCI_ENABLE_WIFI_SCAN_NOTIFY,
3753 /* Return parameters starts from here */
3754 pRetPar = &PPacketIrpEvent->Data[len];
3755 pRetPar[0] = status; /* status */
3758 PPacketIrpEvent->Length = len;
3760 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3766 static enum hci_status
3767 bthci_CmdWIFICurrentChannel(struct rtw_adapter *padapter,
3768 struct packet_irp_hcicmd_data *pHciCmd)
3770 enum hci_status status = HCI_STATUS_SUCCESS;
3771 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3772 u8 chnl = pmlmeext->cur_channel;
3774 if (pmlmeext->cur_bwmode == HT_CHANNEL_WIDTH_40) {
3775 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
3777 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
3781 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current Channel = 0x%x\n", chnl));
3784 u8 localBuf[8] = "";
3787 struct packet_irp_hcievent_data *PPacketIrpEvent;
3789 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3791 len += bthci_CommandCompleteHeader(&localBuf[0],
3793 HCI_WIFI_CURRENT_CHANNEL,
3796 /* Return parameters starts from here */
3797 pRetPar = &PPacketIrpEvent->Data[len];
3798 pRetPar[0] = status; /* status */
3799 pRetPar[1] = chnl; /* current channel */
3801 PPacketIrpEvent->Length = len;
3803 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3809 static enum hci_status
3810 bthci_CmdWIFICurrentBandwidth(struct rtw_adapter *padapter,
3811 struct packet_irp_hcicmd_data *pHciCmd)
3813 enum hci_status status = HCI_STATUS_SUCCESS;
3814 enum ht_channel_width bw;
3817 bw = padapter->mlmeextpriv.cur_bwmode;
3819 if (bw == HT_CHANNEL_WIDTH_20)
3821 else if (bw == HT_CHANNEL_WIDTH_40)
3824 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("Current BW = 0x%x\n",
3828 u8 localBuf[8] = "";
3831 struct packet_irp_hcievent_data *PPacketIrpEvent;
3833 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3835 len += bthci_CommandCompleteHeader(&localBuf[0],
3837 HCI_WIFI_CURRENT_BANDWIDTH,
3840 /* Return parameters starts from here */
3841 pRetPar = &PPacketIrpEvent->Data[len];
3842 pRetPar[0] = status; /* status */
3843 pRetPar[1] = CurrentBW; /* current BW */
3845 PPacketIrpEvent->Length = len;
3847 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3853 static enum hci_status
3854 bthci_CmdWIFIConnectionStatus(
3855 struct rtw_adapter *padapter,
3856 struct packet_irp_hcicmd_data *pHciCmd
3859 enum hci_status status = HCI_STATUS_SUCCESS;
3860 u8 connectStatus = HCI_WIFI_NOT_CONNECTED;
3862 if (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) {
3863 if (padapter->stapriv.asoc_sta_count >= 3)
3864 connectStatus = HCI_WIFI_CONNECTED;
3866 connectStatus = HCI_WIFI_NOT_CONNECTED;
3867 } else if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE|WIFI_ASOC_STATE)) {
3868 connectStatus = HCI_WIFI_CONNECTED;
3869 } else if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING)) {
3870 connectStatus = HCI_WIFI_CONNECT_IN_PROGRESS;
3872 connectStatus = HCI_WIFI_NOT_CONNECTED;
3876 u8 localBuf[8] = "";
3879 struct packet_irp_hcievent_data *PPacketIrpEvent;
3881 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3883 len += bthci_CommandCompleteHeader(&localBuf[0],
3885 HCI_WIFI_CONNECTION_STATUS,
3888 /* Return parameters starts from here */
3889 pRetPar = &PPacketIrpEvent->Data[len];
3890 pRetPar[0] = status; /* status */
3891 pRetPar[1] = connectStatus; /* connect status */
3893 PPacketIrpEvent->Length = len;
3895 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3901 static enum hci_status
3902 bthci_CmdEnableDeviceUnderTestMode(
3903 struct rtw_adapter *padapter,
3904 struct packet_irp_hcicmd_data *pHciCmd
3907 enum hci_status status = HCI_STATUS_SUCCESS;
3908 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3909 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3911 pBtHciInfo->bInTestMode = true;
3912 pBtHciInfo->bTestIsEnd = false;
3914 /* send command complete event here when all data are received. */
3916 u8 localBuf[6] = "";
3919 struct packet_irp_hcievent_data *PPacketIrpEvent;
3921 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3923 len += bthci_CommandCompleteHeader(&localBuf[0],
3924 OGF_TESTING_COMMANDS,
3925 HCI_ENABLE_DEVICE_UNDER_TEST_MODE,
3928 /* Return parameters starts from here */
3929 pRetPar = &PPacketIrpEvent->Data[len];
3930 pRetPar[0] = status; /* status */
3932 PPacketIrpEvent->Length = len;
3934 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
3940 static enum hci_status
3941 bthci_CmdAMPTestEnd(struct rtw_adapter *padapter,
3942 struct packet_irp_hcicmd_data *pHciCmd)
3944 enum hci_status status = HCI_STATUS_SUCCESS;
3945 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3946 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3947 u8 bFilterOutNonAssociatedBSSID = true;
3949 if (!pBtHciInfo->bInTestMode) {
3950 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3951 status = HCI_STATUS_CMD_DISALLOW;
3955 pBtHciInfo->bTestIsEnd = true;
3957 del_timer_sync(&pBTInfo->BTTestSendPacketTimer);
3959 rtw_hal_set_hwreg23a(padapter, HW_VAR_CHECK_BSSID, (u8 *)(&bFilterOutNonAssociatedBSSID));
3961 /* send command complete event here when all data are received. */
3963 u8 localBuf[4] = "";
3964 struct packet_irp_hcievent_data *PPacketIrpEvent;
3966 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
3967 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
3968 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
3969 PPacketIrpEvent->Length = 2;
3971 PPacketIrpEvent->Data[0] = status;
3972 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario;
3974 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
3977 bthci_EventAMPReceiverReport(padapter, 0x01);
3982 static enum hci_status
3983 bthci_CmdAMPTestCommand(struct rtw_adapter *padapter,
3984 struct packet_irp_hcicmd_data *pHciCmd)
3986 enum hci_status status = HCI_STATUS_SUCCESS;
3987 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3988 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
3990 if (!pBtHciInfo->bInTestMode) {
3991 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Not in Test mode, return status = HCI_STATUS_CMD_DISALLOW\n"));
3992 status = HCI_STATUS_CMD_DISALLOW;
3996 pBtHciInfo->TestScenario = *((u8 *)pHciCmd->Data);
3998 if (pBtHciInfo->TestScenario == 0x01)
3999 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
4000 else if (pBtHciInfo->TestScenario == 0x02)
4001 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
4003 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("No Such Test !!!!!!!!!!!!!!!!!! \n"));
4005 if (pBtHciInfo->bTestIsEnd) {
4006 u8 localBuf[5] = "";
4007 struct packet_irp_hcievent_data *PPacketIrpEvent;
4009 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("AMP Test End Event \n"));
4010 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4011 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_TEST_END;
4012 PPacketIrpEvent->Length = 2;
4014 PPacketIrpEvent->Data[0] = status;
4015 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
4017 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
4019 /* Return to Idel state with RX and TX off. */
4024 /* should send command status event */
4025 bthci_EventCommandStatus(padapter,
4026 OGF_TESTING_COMMANDS,
4027 HCI_AMP_TEST_COMMAND,
4030 /* The HCI_AMP_Start Test Event shall be generated when the */
4031 /* HCI_AMP_Test_Command has completed and the first data is ready to be sent */
4035 u8 localBuf[5] = "";
4036 struct packet_irp_hcievent_data *PPacketIrpEvent;
4038 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), (" HCI_AMP_Start Test Event \n"));
4039 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4040 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_START_TEST;
4041 PPacketIrpEvent->Length = 2;
4043 PPacketIrpEvent->Data[0] = status;
4044 PPacketIrpEvent->Data[1] = pBtHciInfo->TestScenario ;
4046 bthci_IndicateEvent(padapter, PPacketIrpEvent, 4);
4048 /* Return to Idel state with RX and TX off. */
4051 if (pBtHciInfo->TestScenario == 0x01) {
4053 When in a transmitter test scenario and the frames/bursts count have been
4054 transmitted the HCI_AMP_Test_End event shall be sent.
4056 mod_timer(&pBTInfo->BTTestSendPacketTimer,
4057 jiffies + msecs_to_jiffies(50));
4058 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("TX Single Test \n"));
4059 } else if (pBtHciInfo->TestScenario == 0x02) {
4060 u8 bFilterOutNonAssociatedBSSID = false;
4061 rtw_hal_set_hwreg23a(padapter, HW_VAR_CHECK_BSSID, (u8 *)(&bFilterOutNonAssociatedBSSID));
4062 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_BT_LOGO), ("Receive Frame Test \n"));
4068 static enum hci_status
4069 bthci_CmdEnableAMPReceiverReports(struct rtw_adapter *padapter,
4070 struct packet_irp_hcicmd_data *pHciCmd)
4072 enum hci_status status = HCI_STATUS_SUCCESS;
4073 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4074 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4076 if (!pBtHciInfo->bInTestMode) {
4077 status = HCI_STATUS_CMD_DISALLOW;
4078 /* send command complete event here when all data are received. */
4080 u8 localBuf[6] = "";
4083 struct packet_irp_hcievent_data *PPacketIrpEvent;
4085 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4087 len += bthci_CommandCompleteHeader(&localBuf[0],
4088 OGF_TESTING_COMMANDS,
4089 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4092 /* Return parameters starts from here */
4093 pRetPar = &PPacketIrpEvent->Data[len];
4094 pRetPar[0] = status; /* status */
4096 PPacketIrpEvent->Length = len;
4098 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4103 pBtHciInfo->bTestNeedReport = *((u8 *)pHciCmd->Data);
4104 pBtHciInfo->TestReportInterval = (*((u8 *)pHciCmd->Data+2));
4106 bthci_EventAMPReceiverReport(padapter, 0x00);
4108 /* send command complete event here when all data are received. */
4110 u8 localBuf[6] = "";
4113 struct packet_irp_hcievent_data *PPacketIrpEvent;
4115 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4117 len += bthci_CommandCompleteHeader(&localBuf[0],
4118 OGF_TESTING_COMMANDS,
4119 HCI_ENABLE_AMP_RECEIVER_REPORTS,
4122 /* Return parameters starts from here */
4123 pRetPar = &PPacketIrpEvent->Data[len];
4124 pRetPar[0] = status; /* status */
4126 PPacketIrpEvent->Length = len;
4128 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4134 static enum hci_status
4135 bthci_CmdHostBufferSize(struct rtw_adapter *padapter,
4136 struct packet_irp_hcicmd_data *pHciCmd)
4138 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4139 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4140 struct packet_irp_hcievent_data *PPacketIrpEvent;
4141 enum hci_status status = HCI_STATUS_SUCCESS;
4142 u8 localBuf[6] = "";
4146 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].ACLPacketsData.ACLDataPacketLen = *((u16 *)pHciCmd->Data);
4147 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].SyncDataPacketLen = *((u8 *)(pHciCmd->Data+2));
4148 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalNumACLDataPackets = *((u16 *)(pHciCmd->Data+3));
4149 pBTInfo->BtAsocEntry[pBtMgnt->CurrentConnectEntryNum].TotalSyncNumDataPackets = *((u16 *)(pHciCmd->Data+5));
4151 /* send command complete event here when all data are received. */
4152 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
4154 len += bthci_CommandCompleteHeader(&localBuf[0],
4155 OGF_SET_EVENT_MASK_COMMAND,
4156 HCI_HOST_BUFFER_SIZE,
4159 /* Return parameters starts from here */
4160 pRetPar = &PPacketIrpEvent->Data[len];
4161 pRetPar[0] = status; /* status */
4163 PPacketIrpEvent->Length = len;
4165 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
4170 static enum hci_status
4171 bthci_CmdHostNumberOfCompletedPackets(struct rtw_adapter *padapter,
4172 struct packet_irp_hcicmd_data *pHciCmd)
4174 enum hci_status status = HCI_STATUS_SUCCESS;
4179 static enum hci_status
4180 bthci_UnknownCMD(struct rtw_adapter *padapter, struct packet_irp_hcicmd_data *pHciCmd)
4182 enum hci_status status = HCI_STATUS_UNKNOW_HCI_CMD;
4183 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4184 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
4186 pBtDbg->dbgHciInfo.hciCmdCntUnknown++;
4187 bthci_EventCommandStatus(padapter,
4195 static enum hci_status
4196 bthci_HandleOGFInformationalParameters(struct rtw_adapter *padapter,
4197 struct packet_irp_hcicmd_data *pHciCmd)
4199 enum hci_status status = HCI_STATUS_SUCCESS;
4201 switch (pHciCmd->OCF) {
4202 case HCI_READ_LOCAL_VERSION_INFORMATION:
4203 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_VERSION_INFORMATION\n"));
4204 status = bthci_CmdReadLocalVersionInformation(padapter);
4206 case HCI_READ_LOCAL_SUPPORTED_COMMANDS:
4207 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_COMMANDS\n"));
4208 status = bthci_CmdReadLocalSupportedCommands(padapter);
4210 case HCI_READ_LOCAL_SUPPORTED_FEATURES:
4211 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_SUPPORTED_FEATURES\n"));
4212 status = bthci_CmdReadLocalSupportedFeatures(padapter);
4214 case HCI_READ_BUFFER_SIZE:
4215 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BUFFER_SIZE\n"));
4216 status = bthci_CmdReadBufferSize(padapter);
4218 case HCI_READ_DATA_BLOCK_SIZE:
4219 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_DATA_BLOCK_SIZE\n"));
4220 status = bthci_CmdReadDataBlockSize(padapter);
4223 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFInformationalParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4224 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4225 status = bthci_UnknownCMD(padapter, pHciCmd);
4231 static enum hci_status
4232 bthci_HandleOGFSetEventMaskCMD(struct rtw_adapter *padapter,
4233 struct packet_irp_hcicmd_data *pHciCmd)
4235 enum hci_status status = HCI_STATUS_SUCCESS;
4237 switch (pHciCmd->OCF) {
4238 case HCI_SET_EVENT_MASK:
4239 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK\n"));
4240 status = bthci_CmdSetEventMask(padapter, pHciCmd);
4243 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET\n"));
4244 status = bthci_CmdReset(padapter, true);
4246 case HCI_READ_CONNECTION_ACCEPT_TIMEOUT:
4247 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_CONNECTION_ACCEPT_TIMEOUT\n"));
4248 status = bthci_CmdReadConnectionAcceptTimeout(padapter);
4250 case HCI_SET_EVENT_FILTER:
4251 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_FILTER\n"));
4252 status = bthci_CmdSetEventFilter(padapter, pHciCmd);
4254 case HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT:
4255 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT\n"));
4256 status = bthci_CmdWriteConnectionAcceptTimeout(padapter, pHciCmd);
4258 case HCI_READ_PAGE_TIMEOUT:
4259 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_PAGE_TIMEOUT\n"));
4260 status = bthci_CmdReadPageTimeout(padapter, pHciCmd);
4262 case HCI_WRITE_PAGE_TIMEOUT:
4263 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_PAGE_TIMEOUT\n"));
4264 status = bthci_CmdWritePageTimeout(padapter, pHciCmd);
4266 case HCI_HOST_NUMBER_OF_COMPLETED_PACKETS:
4267 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_NUMBER_OF_COMPLETED_PACKETS\n"));
4268 status = bthci_CmdHostNumberOfCompletedPackets(padapter, pHciCmd);
4270 case HCI_READ_LINK_SUPERVISION_TIMEOUT:
4271 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_SUPERVISION_TIMEOUT\n"));
4272 status = bthci_CmdReadLinkSupervisionTimeout(padapter, pHciCmd);
4274 case HCI_WRITE_LINK_SUPERVISION_TIMEOUT:
4275 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LINK_SUPERVISION_TIMEOUT\n"));
4276 status = bthci_CmdWriteLinkSupervisionTimeout(padapter, pHciCmd);
4278 case HCI_ENHANCED_FLUSH:
4279 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENHANCED_FLUSH\n"));
4280 status = bthci_CmdEnhancedFlush(padapter, pHciCmd);
4282 case HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT:
4283 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4284 status = bthci_CmdReadLogicalLinkAcceptTimeout(padapter, pHciCmd);
4286 case HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT:
4287 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT\n"));
4288 status = bthci_CmdWriteLogicalLinkAcceptTimeout(padapter, pHciCmd);
4290 case HCI_SET_EVENT_MASK_PAGE_2:
4291 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_MASK_PAGE_2\n"));
4292 status = bthci_CmdSetEventMaskPage2(padapter, pHciCmd);
4294 case HCI_READ_LOCATION_DATA:
4295 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCATION_DATA\n"));
4296 status = bthci_CmdReadLocationData(padapter, pHciCmd);
4298 case HCI_WRITE_LOCATION_DATA:
4299 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_LOCATION_DATA\n"));
4300 status = bthci_CmdWriteLocationData(padapter, pHciCmd);
4302 case HCI_READ_FLOW_CONTROL_MODE:
4303 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FLOW_CONTROL_MODE\n"));
4304 status = bthci_CmdReadFlowControlMode(padapter, pHciCmd);
4306 case HCI_WRITE_FLOW_CONTROL_MODE:
4307 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_FLOW_CONTROL_MODE\n"));
4308 status = bthci_CmdWriteFlowControlMode(padapter, pHciCmd);
4310 case HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT:
4311 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4312 status = bthci_CmdReadBestEffortFlushTimeout(padapter, pHciCmd);
4314 case HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT:
4315 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_BEST_EFFORT_FLUSH_TIMEOUT\n"));
4316 status = bthci_CmdWriteBestEffortFlushTimeout(padapter, pHciCmd);
4318 case HCI_SHORT_RANGE_MODE:
4319 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SHORT_RANGE_MODE\n"));
4320 status = bthci_CmdShortRangeMode(padapter, pHciCmd);
4322 case HCI_HOST_BUFFER_SIZE:
4323 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_BUFFER_SIZE\n"));
4324 status = bthci_CmdHostBufferSize(padapter, pHciCmd);
4327 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFSetEventMaskCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4328 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4329 status = bthci_UnknownCMD(padapter, pHciCmd);
4335 static enum hci_status
4336 bthci_HandleOGFStatusParameters(struct rtw_adapter *padapter,
4337 struct packet_irp_hcicmd_data *pHciCmd)
4339 enum hci_status status = HCI_STATUS_SUCCESS;
4341 switch (pHciCmd->OCF) {
4342 case HCI_READ_FAILED_CONTACT_COUNTER:
4343 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_FAILED_CONTACT_COUNTER\n"));
4344 status = bthci_CmdReadFailedContactCounter(padapter, pHciCmd);
4346 case HCI_RESET_FAILED_CONTACT_COUNTER:
4347 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_RESET_FAILED_CONTACT_COUNTER\n"));
4348 status = bthci_CmdResetFailedContactCounter(padapter, pHciCmd);
4350 case HCI_READ_LINK_QUALITY:
4351 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_QUALITY\n"));
4352 status = bthci_CmdReadLinkQuality(padapter, pHciCmd);
4355 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_RSSI\n"));
4356 status = bthci_CmdReadRSSI(padapter);
4358 case HCI_READ_LOCAL_AMP_INFO:
4359 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_INFO\n"));
4360 status = bthci_CmdReadLocalAMPInfo(padapter);
4362 case HCI_READ_LOCAL_AMP_ASSOC:
4363 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_ASSOC\n"));
4364 status = bthci_CmdReadLocalAMPAssoc(padapter, pHciCmd);
4366 case HCI_WRITE_REMOTE_AMP_ASSOC:
4367 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_REMOTE_AMP_ASSOC\n"));
4368 status = bthci_CmdWriteRemoteAMPAssoc(padapter, pHciCmd);
4371 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFStatusParameters(), Unknown case = 0x%x\n", pHciCmd->OCF));
4372 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4373 status = bthci_UnknownCMD(padapter, pHciCmd);
4379 static enum hci_status
4380 bthci_HandleOGFLinkControlCMD(struct rtw_adapter *padapter,
4381 struct packet_irp_hcicmd_data *pHciCmd)
4383 enum hci_status status = HCI_STATUS_SUCCESS;
4385 switch (pHciCmd->OCF) {
4386 case HCI_CREATE_PHYSICAL_LINK:
4387 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_PHYSICAL_LINK\n"));
4388 status = bthci_CmdCreatePhysicalLink(padapter, pHciCmd);
4390 case HCI_ACCEPT_PHYSICAL_LINK:
4391 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_PHYSICAL_LINK\n"));
4392 status = bthci_CmdAcceptPhysicalLink(padapter, pHciCmd);
4394 case HCI_DISCONNECT_PHYSICAL_LINK:
4395 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_PHYSICAL_LINK\n"));
4396 status = bthci_CmdDisconnectPhysicalLink(padapter, pHciCmd);
4398 case HCI_CREATE_LOGICAL_LINK:
4399 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_CREATE_LOGICAL_LINK\n"));
4400 status = bthci_CmdCreateLogicalLink(padapter, pHciCmd);
4402 case HCI_ACCEPT_LOGICAL_LINK:
4403 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ACCEPT_LOGICAL_LINK\n"));
4404 status = bthci_CmdAcceptLogicalLink(padapter, pHciCmd);
4406 case HCI_DISCONNECT_LOGICAL_LINK:
4407 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_DISCONNECT_LOGICAL_LINK\n"));
4408 status = bthci_CmdDisconnectLogicalLink(padapter, pHciCmd);
4410 case HCI_LOGICAL_LINK_CANCEL:
4411 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_LOGICAL_LINK_CANCEL\n"));
4412 status = bthci_CmdLogicalLinkCancel(padapter, pHciCmd);
4414 case HCI_FLOW_SPEC_MODIFY:
4415 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_FLOW_SPEC_MODIFY\n"));
4416 status = bthci_CmdFlowSpecModify(padapter, pHciCmd);
4419 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("bthci_HandleOGFLinkControlCMD(), Unknown case = 0x%x\n", pHciCmd->OCF));
4420 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4421 status = bthci_UnknownCMD(padapter, pHciCmd);
4427 static enum hci_status
4428 bthci_HandleOGFTestingCMD(struct rtw_adapter *padapter,
4429 struct packet_irp_hcicmd_data *pHciCmd)
4431 enum hci_status status = HCI_STATUS_SUCCESS;
4432 switch (pHciCmd->OCF) {
4433 case HCI_ENABLE_DEVICE_UNDER_TEST_MODE:
4434 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_DEVICE_UNDER_TEST_MODE\n"));
4435 bthci_CmdEnableDeviceUnderTestMode(padapter, pHciCmd);
4437 case HCI_AMP_TEST_END:
4438 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_END\n"));
4439 bthci_CmdAMPTestEnd(padapter, pHciCmd);
4441 case HCI_AMP_TEST_COMMAND:
4442 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_AMP_TEST_COMMAND\n"));
4443 bthci_CmdAMPTestCommand(padapter, pHciCmd);
4445 case HCI_ENABLE_AMP_RECEIVER_REPORTS:
4446 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_ENABLE_AMP_RECEIVER_REPORTS\n"));
4447 bthci_CmdEnableAMPReceiverReports(padapter, pHciCmd);
4450 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
4451 status = bthci_UnknownCMD(padapter, pHciCmd);
4457 static enum hci_status
4458 bthci_HandleOGFExtension(struct rtw_adapter *padapter,
4459 struct packet_irp_hcicmd_data *pHciCmd)
4461 enum hci_status status = HCI_STATUS_SUCCESS;
4462 switch (pHciCmd->OCF) {
4463 case HCI_SET_ACL_LINK_DATA_FLOW_MODE:
4464 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_DATA_FLOW_MODE\n"));
4465 status = bthci_CmdSetACLLinkDataFlowMode(padapter, pHciCmd);
4467 case HCI_SET_ACL_LINK_STATUS:
4468 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_ACL_LINK_STATUS\n"));
4469 status = bthci_CmdSetACLLinkStatus(padapter, pHciCmd);
4471 case HCI_SET_SCO_LINK_STATUS:
4472 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_SCO_LINK_STATUS\n"));
4473 status = bthci_CmdSetSCOLinkStatus(padapter, pHciCmd);
4475 case HCI_SET_RSSI_VALUE:
4476 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("HCI_SET_RSSI_VALUE\n"));
4477 status = bthci_CmdSetRSSIValue(padapter, pHciCmd);
4479 case HCI_SET_CURRENT_BLUETOOTH_STATUS:
4480 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_SET_CURRENT_BLUETOOTH_STATUS\n"));
4481 status = bthci_CmdSetCurrentBluetoothStatus(padapter, pHciCmd);
4483 /* The following is for RTK8723 */
4485 case HCI_EXTENSION_VERSION_NOTIFY:
4486 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_EXTENSION_VERSION_NOTIFY\n"));
4487 status = bthci_CmdExtensionVersionNotify(padapter, pHciCmd);
4489 case HCI_LINK_STATUS_NOTIFY:
4490 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_LINK_STATUS_NOTIFY\n"));
4491 status = bthci_CmdLinkStatusNotify(padapter, pHciCmd);
4493 case HCI_BT_OPERATION_NOTIFY:
4494 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_BT_OPERATION_NOTIFY\n"));
4495 status = bthci_CmdBtOperationNotify(padapter, pHciCmd);
4497 case HCI_ENABLE_WIFI_SCAN_NOTIFY:
4498 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_ENABLE_WIFI_SCAN_NOTIFY\n"));
4499 status = bthci_CmdEnableWifiScanNotify(padapter, pHciCmd);
4502 /* The following is for IVT */
4503 case HCI_WIFI_CURRENT_CHANNEL:
4504 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_CHANNEL\n"));
4505 status = bthci_CmdWIFICurrentChannel(padapter, pHciCmd);
4507 case HCI_WIFI_CURRENT_BANDWIDTH:
4508 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CURRENT_BANDWIDTH\n"));
4509 status = bthci_CmdWIFICurrentBandwidth(padapter, pHciCmd);
4511 case HCI_WIFI_CONNECTION_STATUS:
4512 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_WIFI_CONNECTION_STATUS\n"));
4513 status = bthci_CmdWIFIConnectionStatus(padapter, pHciCmd);
4517 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("HCI_UNKNOWN_COMMAND\n"));
4518 status = bthci_UnknownCMD(padapter, pHciCmd);
4525 bthci_StateStarting(struct rtw_adapter *padapter,
4526 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4528 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4529 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4531 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Starting], "));
4533 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4534 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4535 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4536 pBtMgnt->bNeedNotifyAMPNoCap = true;
4537 BTHCI_DisconnectPeer(padapter, EntryNum);
4539 case STATE_CMD_DISCONNECT_PHY_LINK:
4540 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4542 bthci_EventDisconnectPhyLinkComplete(padapter,
4544 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4547 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4549 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4551 BTHCI_DisconnectPeer(padapter, EntryNum);
4553 case STATE_CMD_MAC_START_COMPLETE:
4554 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_START_COMPLETE\n"));
4555 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_CREATOR)
4556 bthci_EventChannelSelected(padapter, EntryNum);
4559 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4565 bthci_StateConnecting(struct rtw_adapter *padapter,
4566 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4568 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4569 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4571 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connecting], "));
4573 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4574 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4575 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4576 pBtMgnt->bNeedNotifyAMPNoCap = true;
4577 BTHCI_DisconnectPeer(padapter, EntryNum);
4579 case STATE_CMD_MAC_CONNECT_COMPLETE:
4580 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_COMPLETE\n"));
4582 if (pBTInfo->BtAsocEntry[EntryNum].AMPRole == AMP_BTAP_JOINER) {
4583 RT_TRACE(_module_rtl871x_security_c_,
4584 _drv_info_, ("StateConnecting \n"));
4587 case STATE_CMD_DISCONNECT_PHY_LINK:
4588 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4590 bthci_EventDisconnectPhyLinkComplete(padapter,
4592 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4595 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4597 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4599 BTHCI_DisconnectPeer(padapter, EntryNum);
4602 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4603 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4604 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONTROLLER_BUSY;
4605 /* Because this state cmd is caused by the BTHCI_EventAMPStatusChange(), */
4606 /* we don't need to send event in the following BTHCI_DisconnectPeer() again. */
4607 pBtMgnt->bNeedNotifyAMPNoCap = false;
4608 BTHCI_DisconnectPeer(padapter, EntryNum);
4611 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4617 bthci_StateConnected(struct rtw_adapter *padapter,
4618 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4620 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4621 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4622 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4624 u16 logicHandle = 0;
4626 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Connected], "));
4628 case STATE_CMD_DISCONNECT_PHY_LINK:
4629 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4631 /* When we are trying to disconnect the phy link, we should disconnect log link first, */
4632 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
4633 if (pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle != 0) {
4634 logicHandle = pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle;
4636 bthci_EventDisconnectLogicalLinkComplete(padapter, HCI_STATUS_SUCCESS,
4637 logicHandle, pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason);
4639 pBTInfo->BtAsocEntry[EntryNum].LogLinkCmdData->BtLogLinkhandle = 0;
4643 bthci_EventDisconnectPhyLinkComplete(padapter,
4645 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4648 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4650 BTHCI_DisconnectPeer(padapter, EntryNum);
4653 case STATE_CMD_MAC_DISCONNECT_INDICATE:
4654 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_DISCONNECT_INDICATE\n"));
4656 bthci_EventDisconnectPhyLinkComplete(padapter,
4658 /* TODO: Remote Host not local host */
4659 HCI_STATUS_CONNECT_TERMINATE_LOCAL_HOST,
4661 BTHCI_DisconnectPeer(padapter, EntryNum);
4664 case STATE_CMD_ENTER_STATE:
4665 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4667 if (pBtMgnt->bBTConnectInProgress) {
4668 pBtMgnt->bBTConnectInProgress = false;
4669 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4671 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = HCI_STATE_CONNECTED;
4672 pBTInfo->BtAsocEntry[EntryNum].b4waySuccess = true;
4673 pBtMgnt->bStartSendSupervisionPkt = true;
4675 /* for rate adaptive */
4677 if (padapter->HalFunc.UpdateRAMaskHandler)
4678 padapter->HalFunc.UpdateRAMaskHandler(padapter, MAX_FW_SUPPORT_MACID_NUM-1-EntryNum, 0);
4680 rtw_hal_set_hwreg23a(padapter, HW_VAR_BASIC_RATE, padapter->mlmepriv.cur_network.network.SupportedRates);
4681 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
4684 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4690 bthci_StateAuth(struct rtw_adapter *padapter, enum hci_state_with_cmd StateCmd,
4693 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4694 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4696 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Authenticating], "));
4698 case STATE_CMD_CONNECT_ACCEPT_TIMEOUT:
4699 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CONNECT_ACCEPT_TIMEOUT\n"));
4700 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_CONNECT_ACCEPT_TIMEOUT;
4701 pBtMgnt->bNeedNotifyAMPNoCap = true;
4702 BTHCI_DisconnectPeer(padapter, EntryNum);
4704 case STATE_CMD_DISCONNECT_PHY_LINK:
4705 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4706 bthci_EventDisconnectPhyLinkComplete(padapter,
4708 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4711 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_UNKNOW_CONNECT_ID;
4713 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4715 BTHCI_DisconnectPeer(padapter, EntryNum);
4717 case STATE_CMD_4WAY_FAILED:
4718 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_FAILED\n"));
4720 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus = HCI_STATUS_AUTH_FAIL;
4721 pBtMgnt->bNeedNotifyAMPNoCap = true;
4723 BTHCI_DisconnectPeer(padapter, EntryNum);
4725 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4727 case STATE_CMD_4WAY_SUCCESSED:
4728 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_4WAY_SUCCESSED\n"));
4730 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_SUCCESS, EntryNum, INVALID_PL_HANDLE);
4732 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4734 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4737 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4743 bthci_StateDisconnecting(struct rtw_adapter *padapter,
4744 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4746 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4747 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4749 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnecting], "));
4751 case STATE_CMD_MAC_CONNECT_CANCEL_INDICATE:
4752 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_MAC_CONNECT_CANCEL_INDICATE\n"));
4753 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4754 bthci_EventPhysicalLinkComplete(padapter,
4755 pBTInfo->BtAsocEntry[EntryNum].PhysLinkCompleteStatus,
4756 EntryNum, INVALID_PL_HANDLE);
4759 if (pBtMgnt->bBTConnectInProgress) {
4760 pBtMgnt->bBTConnectInProgress = false;
4761 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4764 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4766 case STATE_CMD_DISCONNECT_PHY_LINK:
4767 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4769 bthci_EventDisconnectPhyLinkComplete(padapter,
4771 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4774 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4776 BTHCI_DisconnectPeer(padapter, EntryNum);
4779 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4785 bthci_StateDisconnected(struct rtw_adapter *padapter,
4786 enum hci_state_with_cmd StateCmd, u8 EntryNum)
4788 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
4789 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4790 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
4791 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4793 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT state], [Disconnected], "));
4795 case STATE_CMD_CREATE_PHY_LINK:
4796 case STATE_CMD_ACCEPT_PHY_LINK:
4797 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4798 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_CREATE_PHY_LINK\n"));
4800 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ACCEPT_PHY_LINK\n"));
4802 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], Disable IPS and LPS\n"));
4803 ips_leave23a(padapter);
4804 LPS_Leave23a(padapter);
4806 pBtMgnt->bPhyLinkInProgress = true;
4807 pBtMgnt->BTCurrentConnectType = BT_DISCONNECT;
4808 pBtMgnt->CurrentBTConnectionCnt++;
4809 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], CurrentBTConnectionCnt = %d\n",
4810 pBtMgnt->CurrentBTConnectionCnt));
4811 pBtMgnt->BtOperationOn = true;
4812 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], Bt Operation ON!! CurrentConnectEntryNum = %d\n",
4813 pBtMgnt->CurrentConnectEntryNum));
4815 if (pBtMgnt->bBTConnectInProgress) {
4816 bthci_EventPhysicalLinkComplete(padapter, HCI_STATUS_CONTROLLER_BUSY, INVALID_ENTRY_NUM, pBtMgnt->BtCurrentPhyLinkhandle);
4817 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4821 if (StateCmd == STATE_CMD_CREATE_PHY_LINK)
4822 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_CREATOR;
4824 pBTInfo->BtAsocEntry[EntryNum].AMPRole = AMP_BTAP_JOINER;
4826 /* 1. MAC not yet in selected channel */
4827 while (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR)) {
4828 RTPRINT(FIOCTL, IOCTL_STATE, ("Scan/Roaming/Wifi Link is in Progress, wait 200 ms\n"));
4831 /* 2. MAC already in selected channel */
4832 RTPRINT(FIOCTL, IOCTL_STATE, ("Channel is Ready\n"));
4833 mod_timer(&pBTInfo->BTHCIJoinTimeoutTimer,
4834 jiffies + msecs_to_jiffies(pBtHciInfo->ConnAcceptTimeout));
4836 pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent = true;
4838 case STATE_CMD_DISCONNECT_PHY_LINK:
4839 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_DISCONNECT_PHY_LINK\n"));
4841 del_timer_sync(&pBTInfo->BTHCIJoinTimeoutTimer);
4843 bthci_EventDisconnectPhyLinkComplete(padapter,
4845 pBTInfo->BtAsocEntry[EntryNum].PhyLinkDisconnectReason,
4848 if (pBTInfo->BtAsocEntry[EntryNum].bNeedPhysLinkCompleteEvent) {
4849 bthci_EventPhysicalLinkComplete(padapter,
4850 HCI_STATUS_UNKNOW_CONNECT_ID,
4851 EntryNum, INVALID_PL_HANDLE);
4854 if (pBtMgnt->bBTConnectInProgress) {
4855 pBtMgnt->bBTConnectInProgress = false;
4856 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
4858 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTED, STATE_CMD_ENTER_STATE, EntryNum);
4859 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
4861 case STATE_CMD_ENTER_STATE:
4862 RTPRINT(FIOCTL, IOCTL_STATE, ("STATE_CMD_ENTER_STATE\n"));
4865 RTPRINT(FIOCTL, IOCTL_STATE, ("State command(%d) is Wrong !!!\n", StateCmd));
4870 void BTHCI_EventParse(struct rtw_adapter *padapter, void *pEvntData, u32 dataLen)
4874 u8 BTHCI_HsConnectionEstablished(struct rtw_adapter *padapter)
4876 u8 bBtConnectionExist = false;
4877 struct bt_30info *pBtinfo = GET_BT_INFO(padapter);
4880 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
4881 if (pBtinfo->BtAsocEntry[i].b4waySuccess) {
4882 bBtConnectionExist = true;
4887 /*RTPRINT(FIOCTL, IOCTL_STATE, (" BTHCI_HsConnectionEstablished(), connection exist = %d\n", bBtConnectionExist)); */
4889 return bBtConnectionExist;
4893 BTHCI_CheckProfileExist(struct rtw_adapter *padapter,
4894 enum bt_traffic_mode_profile Profile)
4896 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4897 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4898 u8 IsPRofile = false;
4901 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4902 if (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile == Profile) {
4911 void BTHCI_UpdateBTProfileRTKToMoto(struct rtw_adapter *padapter)
4913 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4914 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4917 pBtMgnt->ExtConfig.NumberOfSCO = 0;
4919 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
4920 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = BT_PROFILE_NONE;
4922 if (pBtMgnt->ExtConfig.linkInfo[i].BTProfile == BT_PROFILE_SCO)
4923 pBtMgnt->ExtConfig.NumberOfSCO++;
4925 pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile = pBtMgnt->ExtConfig.linkInfo[i].BTProfile;
4926 switch (pBtMgnt->ExtConfig.linkInfo[i].TrafficProfile) {
4927 case BT_PROFILE_SCO:
4929 case BT_PROFILE_PAN:
4930 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_BE;
4931 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4933 case BT_PROFILE_A2DP:
4934 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GULB;
4935 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_GULB;
4937 case BT_PROFILE_HID:
4938 pBtMgnt->ExtConfig.linkInfo[i].IncomingTrafficMode = BT_MOTOR_EXT_GUL;
4939 pBtMgnt->ExtConfig.linkInfo[i].OutgoingTrafficMode = BT_MOTOR_EXT_BE;
4946 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RTK, NumberOfHandle = %d, NumberOfSCO = %d\n",
4947 pBtMgnt->ExtConfig.NumberOfHandle, pBtMgnt->ExtConfig.NumberOfSCO));
4950 void BTHCI_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
4952 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4953 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4955 if (pBtMgnt->ExtConfig.bEnableWifiScanNotify)
4956 bthci_EventExtWifiScanNotify(padapter, scanType);
4961 struct rtw_adapter *padapter,
4963 enum hci_state_with_cmd StateCmd,
4967 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
4968 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
4970 if (EntryNum == 0xff) {
4971 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, error EntryNum = 0x%x \n", EntryNum));
4974 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, EntryNum = 0x%x, CurrentState = 0x%x, BtNextState = 0x%x, StateCmd = 0x%x , StateToEnter = 0x%x\n",
4975 EntryNum, pBTInfo->BtAsocEntry[EntryNum].BtCurrentState, pBTInfo->BtAsocEntry[EntryNum].BtNextState, StateCmd, StateToEnter));
4977 if (pBTInfo->BtAsocEntry[EntryNum].BtNextState & StateToEnter) {
4978 pBTInfo->BtAsocEntry[EntryNum].BtCurrentState = StateToEnter;
4980 switch (StateToEnter) {
4981 case HCI_STATE_STARTING:
4982 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTING;
4983 bthci_StateStarting(padapter, StateCmd, EntryNum);
4985 case HCI_STATE_CONNECTING:
4986 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTING | HCI_STATE_DISCONNECTING | HCI_STATE_AUTHENTICATING;
4987 bthci_StateConnecting(padapter, StateCmd, EntryNum);
4989 case HCI_STATE_AUTHENTICATING:
4990 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTING | HCI_STATE_CONNECTED;
4991 bthci_StateAuth(padapter, StateCmd, EntryNum);
4993 case HCI_STATE_CONNECTED:
4994 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_CONNECTED | HCI_STATE_DISCONNECTING;
4995 bthci_StateConnected(padapter, StateCmd, EntryNum);
4997 case HCI_STATE_DISCONNECTING:
4998 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_DISCONNECTING;
4999 bthci_StateDisconnecting(padapter, StateCmd, EntryNum);
5001 case HCI_STATE_DISCONNECTED:
5002 pBTInfo->BtAsocEntry[EntryNum].BtNextState = HCI_STATE_DISCONNECTED | HCI_STATE_STARTING | HCI_STATE_CONNECTING;
5003 bthci_StateDisconnected(padapter, StateCmd, EntryNum);
5006 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Unknown state to enter!!!\n"));
5010 RTPRINT(FIOCTL, IOCTL_STATE, (" StateMachine, Wrong state to enter\n"));
5013 /* 20100325 Joseph: Disable/Enable IPS/LPS according to BT status. */
5014 if (!pBtMgnt->bBTConnectInProgress && !pBtMgnt->BtOperationOn) {
5015 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT PS], ips_enter23a()\n"));
5016 ips_enter23a(padapter);
5020 void BTHCI_DisconnectPeer(struct rtw_adapter *padapter, u8 EntryNum)
5022 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5023 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
5025 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, (" BTHCI_DisconnectPeer()\n"));
5027 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, EntryNum);
5029 if (pBTInfo->BtAsocEntry[EntryNum].bUsed) {
5030 /*BTPKT_SendDeauthentication(padapter, pBTInfo->BtAsocEntry[EntryNum].BTRemoteMACAddr, unspec_reason); not porting yet */
5033 if (pBtMgnt->bBTConnectInProgress) {
5034 pBtMgnt->bBTConnectInProgress = false;
5035 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT Flag], BT Connect in progress OFF!!\n"));
5038 bthci_RemoveEntryByEntryNum(padapter, EntryNum);
5040 if (pBtMgnt->bNeedNotifyAMPNoCap) {
5041 RTPRINT(FIOCTL, IOCTL_STATE, ("[BT AMPStatus], set to invalid in BTHCI_DisconnectPeer()\n"));
5042 BTHCI_EventAMPStatusChange(padapter, AMP_STATUS_NO_CAPACITY_FOR_BT);
5046 void BTHCI_EventNumOfCompletedDataBlocks(struct rtw_adapter *padapter)
5048 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
5049 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5050 struct bt_hci_info *pBtHciInfo = &pBTInfo->BtHciInfo;
5051 u8 localBuf[TmpLocalBufSize] = "";
5052 u8 *pRetPar, *pTriple;
5053 u8 len = 0, i, j, handleNum = 0;
5054 struct packet_irp_hcievent_data *PPacketIrpEvent;
5055 u16 *pu2Temp, *pPackets, *pHandle, *pDblocks;
5058 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5060 if (!(pBtHciInfo->BTEventMaskPage2 & EMP2_HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS)) {
5061 RTPRINT(FIOCTL, IOCTL_BT_EVENT, ("[BT event], Num Of Completed DataBlocks, Ignore to send NumOfCompletedDataBlocksEvent due to event mask page 2\n"));
5065 /* Return parameters starts from here */
5066 pRetPar = &PPacketIrpEvent->Data[0];
5067 pTriple = &pRetPar[3];
5068 for (j = 0; j < MAX_BT_ASOC_ENTRY_NUM; j++) {
5070 for (i = 0; i < MAX_LOGICAL_LINK_NUM; i++) {
5071 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle) {
5073 pHandle = (u16 *)&pTriple[0]; /* Handle[i] */
5074 pPackets = (u16 *)&pTriple[2]; /* Num_Of_Completed_Packets[i] */
5075 pDblocks = (u16 *)&pTriple[4]; /* Num_Of_Completed_Blocks[i] */
5076 *pHandle = pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].BtLogLinkhandle;
5077 *pPackets = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5078 *pDblocks = (u16)pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount;
5079 if (pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount) {
5081 RTPRINT(FIOCTL, IOCTL_BT_EVENT_DETAIL,
5082 ("[BT event], Num Of Completed DataBlocks, Handle = 0x%x, Num_Of_Completed_Packets = 0x%x, Num_Of_Completed_Blocks = 0x%x\n",
5083 *pHandle, *pPackets, *pDblocks));
5085 pBTInfo->BtAsocEntry[j].LogLinkCmdData[i].TxPacketCount = 0;
5092 pRetPar[2] = handleNum; /* Number_of_Handles */
5094 pu2Temp = (u16 *)&pRetPar[0];
5095 *pu2Temp = BTTotalDataBlockNum;
5098 PPacketIrpEvent->EventCode = HCI_EVENT_NUM_OF_COMPLETE_DATA_BLOCKS;
5099 PPacketIrpEvent->Length = len;
5100 if (handleNum && sent)
5101 bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2);
5104 void BTHCI_EventAMPStatusChange(struct rtw_adapter *padapter, u8 AMP_Status)
5106 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5107 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
5108 struct packet_irp_hcievent_data *PPacketIrpEvent;
5110 u8 localBuf[7] = "";
5113 if (AMP_Status == AMP_STATUS_NO_CAPACITY_FOR_BT) {
5114 pBtMgnt->BTNeedAMPStatusChg = true;
5115 pBtMgnt->bNeedNotifyAMPNoCap = false;
5117 BTHCI_DisconnectAll(padapter);
5118 } else if (AMP_Status == AMP_STATUS_FULL_CAPACITY_FOR_BT) {
5119 pBtMgnt->BTNeedAMPStatusChg = false;
5122 PPacketIrpEvent = (struct packet_irp_hcievent_data *)(&localBuf[0]);
5123 /* Return parameters starts from here */
5124 pRetPar = &PPacketIrpEvent->Data[0];
5126 pRetPar[0] = 0; /* Status */
5128 pRetPar[1] = AMP_Status; /* AMP_Status */
5131 PPacketIrpEvent->EventCode = HCI_EVENT_AMP_STATUS_CHANGE;
5132 PPacketIrpEvent->Length = len;
5133 if (bthci_IndicateEvent(padapter, PPacketIrpEvent, len+2) == RT_STATUS_SUCCESS)
5134 RTPRINT(FIOCTL, (IOCTL_BT_EVENT|IOCTL_STATE), ("[BT event], AMP Status Change, AMP_Status = %d\n", AMP_Status));
5137 void BTHCI_DisconnectAll(struct rtw_adapter *padapter)
5139 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5142 RTPRINT(FIOCTL, IOCTL_STATE, (" DisconnectALL()\n"));
5144 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
5145 if (pBTInfo->BtAsocEntry[i].b4waySuccess) {
5146 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTED, STATE_CMD_DISCONNECT_PHY_LINK, i);
5147 } else if (pBTInfo->BtAsocEntry[i].bUsed) {
5148 if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_CONNECTING) {
5149 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_CONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5150 } else if (pBTInfo->BtAsocEntry[i].BtCurrentState == HCI_STATE_DISCONNECTING) {
5151 BTHCI_SM_WITH_INFO(padapter, HCI_STATE_DISCONNECTING, STATE_CMD_MAC_CONNECT_CANCEL_INDICATE, i);
5159 struct rtw_adapter *padapter,
5160 struct packet_irp_hcicmd_data *pHciCmd
5163 enum hci_status status = HCI_STATUS_SUCCESS;
5164 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
5165 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
5167 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("\n"));
5168 RTPRINT(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), ("HCI Command start, OGF = 0x%x, OCF = 0x%x, Length = 0x%x\n",
5169 pHciCmd->OGF, pHciCmd->OCF, pHciCmd->Length));
5170 if (pHciCmd->Length) {
5171 RTPRINT_DATA(FIOCTL, (IOCTL_BT_HCICMD_DETAIL|IOCTL_BT_LOGO), "HCI Command, Hex Data :\n",
5172 &pHciCmd->Data[0], pHciCmd->Length);
5174 if (pHciCmd->OGF == OGF_EXTENSION) {
5175 if (pHciCmd->OCF == HCI_SET_RSSI_VALUE)
5176 RTPRINT(FIOCTL, IOCTL_BT_EVENT_PERIODICAL, ("[BT cmd], "));
5178 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_EXT, ("[BT cmd], "));
5180 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("[BT cmd], "));
5183 pBtDbg->dbgHciInfo.hciCmdCnt++;
5185 switch (pHciCmd->OGF) {
5186 case LINK_CONTROL_COMMANDS:
5187 status = bthci_HandleOGFLinkControlCMD(padapter, pHciCmd);
5189 case HOLD_MODE_COMMAND:
5191 case OGF_SET_EVENT_MASK_COMMAND:
5192 status = bthci_HandleOGFSetEventMaskCMD(padapter, pHciCmd);
5194 case OGF_INFORMATIONAL_PARAMETERS:
5195 status = bthci_HandleOGFInformationalParameters(padapter, pHciCmd);
5197 case OGF_STATUS_PARAMETERS:
5198 status = bthci_HandleOGFStatusParameters(padapter, pHciCmd);
5200 case OGF_TESTING_COMMANDS:
5201 status = bthci_HandleOGFTestingCMD(padapter, pHciCmd);
5204 status = bthci_HandleOGFExtension(padapter, pHciCmd);
5207 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI Command(), Unknown OGF = 0x%x\n", pHciCmd->OGF));
5208 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_UNKNOWN_COMMAND\n"));
5209 status = bthci_UnknownCMD(padapter, pHciCmd);
5212 RTPRINT(FIOCTL, IOCTL_BT_HCICMD_DETAIL, ("HCI Command execution end!!\n"));
5217 /* ===== End of sync from SD7 driver COMMOM/bt_hci.c ===== */
5220 #ifdef __HALBTC87231ANT_C__ /* HAL/BTCoexist/HalBtc87231Ant.c */
5222 static const char *const BtStateString[] = {
5230 "BT_ACL_INQ_OR_PAG",
5231 "BT_STATE_NOT_DEFINED"
5234 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
5236 static void btdm_SetFwIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
5238 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5239 u8 H2C_Parameter[1] = {0};
5242 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Ignore Wlan_Act !!\n"));
5243 H2C_Parameter[0] |= BIT(0); /* function enable */
5244 pHalData->bt_coexist.bFWCoexistAllOff = false;
5246 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT don't ignore Wlan_Act !!\n"));
5249 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, write 0x25 = 0x%02x\n",
5252 FillH2CCmd(padapter, BT_IGNORE_WLAN_ACT_EID, 1, H2C_Parameter);
5255 static void btdm_NotifyFwScan(struct rtw_adapter *padapter, u8 scanType)
5257 u8 H2C_Parameter[1] = {0};
5259 if (scanType == true)
5260 H2C_Parameter[0] = 0x1;
5262 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Notify FW for wifi scan, write 0x3b = 0x%02x\n",
5265 FillH2CCmd(padapter, 0x3b, 1, H2C_Parameter);
5268 static void btdm_1AntSetPSMode(struct rtw_adapter *padapter,
5269 u8 enable, u8 smartps, u8 mode)
5271 struct pwrctrl_priv *pwrctrl;
5273 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current LPS(%s, %d), smartps =%d\n", enable == true?"ON":"OFF", mode, smartps));
5275 pwrctrl = &padapter->pwrctrlpriv;
5277 if (enable == true) {
5278 rtw_set_ps_mode23a(padapter, PS_MODE_MIN, smartps, mode);
5280 rtw_set_ps_mode23a(padapter, PS_MODE_ACTIVE, 0, 0);
5281 LPS_RF_ON_check23a(padapter, 100);
5285 static void btdm_1AntTSFSwitch(struct rtw_adapter *padapter, u8 enable)
5289 oldVal = rtw_read8(padapter, 0x550);
5292 newVal = oldVal | EN_BCN_FUNCTION;
5294 newVal = oldVal & ~EN_BCN_FUNCTION;
5296 if (oldVal != newVal)
5297 rtw_write8(padapter, 0x550, newVal);
5300 static u8 btdm_Is1AntPsTdmaStateChange(struct rtw_adapter *padapter)
5302 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5303 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5305 if ((pBtdm8723->bPrePsTdmaOn != pBtdm8723->bCurPsTdmaOn) ||
5306 (pBtdm8723->prePsTdma != pBtdm8723->curPsTdma))
5312 /* Before enter TDMA, make sure Power Saving is enable! */
5315 struct rtw_adapter *padapter,
5320 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5321 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5323 pBtdm8723->bCurPsTdmaOn = bTurnOn;
5324 pBtdm8723->curPsTdma = type;
5327 case 1: /* A2DP Level-1 or FTP/OPP */
5329 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5330 /* wide duration for WiFi */
5331 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x0, 0x58);
5334 case 2: /* A2DP Level-2 */
5335 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5336 /* normal duration for WiFi */
5337 BTDM_SetFw3a(padapter, 0xd3, 0x12, 0x12, 0x0, 0x58);
5340 case 3: /* BT FTP/OPP */
5341 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5342 /* normal duration for WiFi */
5343 BTDM_SetFw3a(padapter, 0xd3, 0x30, 0x03, 0x10, 0x58);
5347 case 4: /* for wifi scan & BT is connected */
5348 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5349 /* protect 3 beacons in 3-beacon period & no Tx pause at BT slot */
5350 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x0);
5353 case 5: /* for WiFi connected-busy & BT is Non-Connected-Idle */
5354 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5355 /* SCO mode, Ant fixed at WiFi, WLAN_Act toggle */
5356 BTDM_SetFw3a(padapter, 0x61, 0x15, 0x03, 0x31, 0x00);
5359 case 9: /* ACL high-retry type - 2 */
5360 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5361 /* narrow duration for WiFi */
5362 BTDM_SetFw3a(padapter, 0xd3, 0xa, 0xa, 0x0, 0x58); /* narrow duration for WiFi */
5365 case 10: /* for WiFi connect idle & BT ACL busy or WiFi Connected-Busy & BT is Inquiry */
5366 if (btdm_Is1AntPsTdmaStateChange(padapter))
5367 BTDM_SetFw3a(padapter, 0x13, 0xa, 0xa, 0x0, 0x40);
5369 case 11: /* ACL high-retry type - 3 */
5370 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5371 /* narrow duration for WiFi */
5372 BTDM_SetFw3a(padapter, 0xd3, 0x05, 0x05, 0x00, 0x58);
5375 case 12: /* for WiFi Connected-Busy & BT is Connected-Idle */
5376 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5377 /* Allow High-Pri BT */
5378 BTDM_SetFw3a(padapter, 0xeb, 0x0a, 0x03, 0x31, 0x18);
5381 case 20: /* WiFi only busy , TDMA mode for power saving */
5382 if (btdm_Is1AntPsTdmaStateChange(padapter))
5383 BTDM_SetFw3a(padapter, 0x13, 0x25, 0x25, 0x00, 0x00);
5385 case 27: /* WiFi DHCP/Site Survey & BT SCO busy */
5386 if (btdm_Is1AntPsTdmaStateChange(padapter))
5387 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x31, 0x98);
5389 case 28: /* WiFi DHCP/Site Survey & BT idle */
5390 if (btdm_Is1AntPsTdmaStateChange(padapter))
5391 BTDM_SetFw3a(padapter, 0x69, 0x25, 0x03, 0x31, 0x00);
5393 case 29: /* WiFi DHCP/Site Survey & BT ACL busy */
5394 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5395 BTDM_SetFw3a(padapter, 0xeb, 0x1a, 0x1a, 0x01, 0x18);
5396 rtw_write32(padapter, 0x6c0, 0x5afa5afa);
5397 rtw_write32(padapter, 0x6c4, 0x5afa5afa);
5400 case 30: /* WiFi idle & BT Inquiry */
5401 if (btdm_Is1AntPsTdmaStateChange(padapter))
5402 BTDM_SetFw3a(padapter, 0x93, 0x15, 0x03, 0x14, 0x00);
5404 case 31: /* BT HID */
5405 if (btdm_Is1AntPsTdmaStateChange(padapter))
5406 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x58);
5408 case 32: /* BT SCO & Inquiry */
5409 if (btdm_Is1AntPsTdmaStateChange(padapter))
5410 BTDM_SetFw3a(padapter, 0xab, 0x0a, 0x03, 0x11, 0x98);
5412 case 33: /* BT SCO & WiFi site survey */
5413 if (btdm_Is1AntPsTdmaStateChange(padapter))
5414 BTDM_SetFw3a(padapter, 0xa3, 0x25, 0x03, 0x30, 0x98);
5416 case 34: /* BT HID & WiFi site survey */
5417 if (btdm_Is1AntPsTdmaStateChange(padapter))
5418 BTDM_SetFw3a(padapter, 0xd3, 0x1a, 0x1a, 0x00, 0x18);
5420 case 35: /* BT HID & WiFi Connecting */
5421 if (btdm_Is1AntPsTdmaStateChange(padapter))
5422 BTDM_SetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x00, 0x18);
5426 /* disable PS-TDMA */
5429 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5430 /* Antenna control by PTA, 0x870 = 0x310 */
5431 BTDM_SetFw3a(padapter, 0x8, 0x0, 0x0, 0x0, 0x0);
5436 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5437 /* Antenna control by PTA, 0x870 = 0x310 */
5438 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5440 rtw_write16(padapter, 0x860, 0x210); /* Switch Antenna to BT */
5441 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x210, Switch Antenna to BT\n"));
5444 if (btdm_Is1AntPsTdmaStateChange(padapter)) {
5445 /* Antenna control by PTA, 0x870 = 0x310 */
5446 BTDM_SetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
5448 rtw_write16(padapter, 0x860, 0x110); /* Switch Antenna to WiFi */
5449 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 0x860 = 0x110, Switch Antenna to WiFi\n"));
5454 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Current TDMA(%s, %d)\n",
5455 pBtdm8723->bCurPsTdmaOn?"ON":"OFF", pBtdm8723->curPsTdma));
5457 /* update pre state */
5458 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
5459 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
5463 _btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn, u8 smartps,
5464 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5466 struct pwrctrl_priv *pwrctrl;
5467 struct hal_data_8723a *pHalData;
5468 struct btdm_8723a_1ant *pBtdm8723;
5472 if (!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE) &&
5473 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
5474 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5477 psOption &= ~BIT(0);
5479 RTPRINT(FBT, BT_TRACE,
5480 ("[BTCoex], Set LPS(%s, %d) TDMA(%s, %d)\n",
5481 bPSEn == true?"ON":"OFF", psOption,
5482 bTDMAOn == true?"ON":"OFF", tdmaType));
5484 pwrctrl = &padapter->pwrctrlpriv;
5485 pHalData = GET_HAL_DATA(padapter);
5486 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5489 if (pBtdm8723->bWiFiHalt) {
5490 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Halt!!\n"));
5494 if (pwrctrl->bInSuspend) {
5495 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi in Suspend!!\n"));
5499 if (padapter->bDriverStopped) {
5500 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi driver stopped!!\n"));
5504 if (padapter->bSurpriseRemoved) {
5505 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Enable PS Fail, WiFi Surprise Removed!!\n"));
5509 psMode = PS_MODE_MIN;
5511 psMode = PS_MODE_ACTIVE;
5515 if (psMode != pwrctrl->pwr_mode) {
5517 } else if (psMode != PS_MODE_ACTIVE) {
5518 if (psOption != pwrctrl->bcn_ant_mode)
5520 else if (smartps != pwrctrl->smart_ps)
5530 if (pBtdm8723->bCurPsTdmaOn) {
5532 btdm_1AntPsTdma(padapter, false, tdmaType);
5534 if ((BT_IsBtDisabled(padapter)) ||
5535 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_NO_CONNECTION) ||
5536 (pHalData->bt_coexist.halCoex8723.c2hBtInfo == BT_INFO_STATE_CONNECT_IDLE) ||
5538 btdm_1AntPsTdma(padapter, false, 9);
5540 btdm_1AntPsTdma(padapter, false, 0);
5544 /* change Power Save State */
5545 btdm_1AntSetPSMode(padapter, bPSEn, smartps, psOption);
5548 btdm_1AntPsTdma(padapter, bTDMAOn, tdmaType);
5552 btdm_1AntSetPSTDMA(struct rtw_adapter *padapter, u8 bPSEn,
5553 u8 psOption, u8 bTDMAOn, u8 tdmaType)
5555 _btdm_1AntSetPSTDMA(padapter, bPSEn, 0, psOption, bTDMAOn, tdmaType);
5558 static void btdm_1AntWifiParaAdjust(struct rtw_adapter *padapter, u8 bEnable)
5560 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5561 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5564 pBtdm8723->curWifiPara = 1;
5565 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5566 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_LOW_PENALTY);
5568 pBtdm8723->curWifiPara = 2;
5569 if (pBtdm8723->preWifiPara != pBtdm8723->curWifiPara)
5570 BTDM_SetSwPenaltyTxRateAdaptive(padapter, BT_TX_RATE_ADAPTIVE_NORMAL);
5575 static void btdm_1AntPtaParaReload(struct rtw_adapter *padapter)
5578 rtw_write8(padapter, 0x6cc, 0x0); /* 1-Ant coex */
5579 rtw_write32(padapter, 0x6c8, 0xffff); /* wifi break table */
5580 rtw_write32(padapter, 0x6c4, 0x55555555); /* coex table */
5582 /* Antenna switch control parameter */
5583 rtw_write32(padapter, 0x858, 0xaaaaaaaa);
5584 if (IS_8723A_A_CUT(GET_HAL_DATA(padapter)->VersionID)) {
5585 rtw_write32(padapter, 0x870, 0x0); /* SPDT(connected with TRSW) control by hardware PTA */
5586 rtw_write8(padapter, 0x40, 0x24);
5588 rtw_write8(padapter, 0x40, 0x20);
5589 rtw_write16(padapter, 0x860, 0x210); /* set antenna at bt side if ANTSW is software control */
5590 rtw_write32(padapter, 0x870, 0x300); /* SPDT(connected with TRSW) control by hardware PTA */
5591 rtw_write32(padapter, 0x874, 0x22804000); /* ANTSW keep by GNT_BT */
5594 /* coexistence parameters */
5595 rtw_write8(padapter, 0x778, 0x1); /* enable RTK mode PTA */
5597 /* BT don't ignore WLAN_Act */
5598 btdm_SetFwIgnoreWlanAct(padapter, false);
5603 *1: upgrade (add WiFi duration time)
5605 *-1: downgrade (add BT duration time)
5607 static s8 btdm_1AntTdmaJudgement(struct rtw_adapter *padapter, u8 retry)
5609 struct hal_data_8723a *pHalData;
5610 struct btdm_8723a_1ant *pBtdm8723;
5611 static s8 up, dn, m = 1, n = 3, WaitCount;
5614 pHalData = GET_HAL_DATA(padapter);
5615 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5618 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5629 /* no retry in the last 2-second duration */
5635 /* retry = 0 in consecutive 3m*(2s), add WiFi duration */
5643 } else if (retry <= 3) {
5644 /* retry<= 3 in the last 2-second duration */
5651 /* retry<= 3 in consecutive 2*(2s), minus WiFi duration (add BT duration) */
5654 /* record how many time downgrad WiFi duration */
5659 /* the max number of m is 20 */
5660 /* the longest time of upgrade WiFi duration is 20*3*2s = 120s */
5668 /* retry count > 3 */
5669 /* retry>3, minus WiFi duration (add BT duration) */
5672 /* record how many time downgrad WiFi duration */
5687 static void btdm_1AntTdmaDurationAdjustForACL(struct rtw_adapter *padapter)
5689 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5690 struct btdm_8723a_1ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
5692 if (pBtdm8723->psTdmaGlobalCnt != pBtdm8723->psTdmaMonitorCnt) {
5693 pBtdm8723->psTdmaMonitorCnt = 0;
5694 pBtdm8723->psTdmaGlobalCnt = 0;
5696 if (pBtdm8723->psTdmaMonitorCnt == 0) {
5697 btdm_1AntSetPSTDMA(padapter, true, 0, true, 2);
5698 pBtdm8723->psTdmaDuAdjType = 2;
5700 /* Now we only have 4 level Ps Tdma, */
5701 /* if that's not the following 4 level(will changed by wifi scan, dhcp...), */
5702 /* then we have to adjust it back to the previous record one. */
5703 if ((pBtdm8723->curPsTdma != 1) &&
5704 (pBtdm8723->curPsTdma != 2) &&
5705 (pBtdm8723->curPsTdma != 9) &&
5706 (pBtdm8723->curPsTdma != 11)) {
5707 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5711 judge = btdm_1AntTdmaJudgement(padapter, pHalData->bt_coexist.halCoex8723.btRetryCnt);
5713 if (pBtdm8723->curPsTdma == 1) {
5714 /* Decrease WiFi duration for high BT retry */
5715 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5716 pBtdm8723->psTdmaDuAdjType = 9;
5718 pBtdm8723->psTdmaDuAdjType = 2;
5719 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5720 } else if (pBtdm8723->curPsTdma == 2) {
5721 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5722 pBtdm8723->psTdmaDuAdjType = 9;
5723 } else if (pBtdm8723->curPsTdma == 9) {
5724 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5725 pBtdm8723->psTdmaDuAdjType = 11;
5727 } else if (judge == 1) {
5728 if (pBtdm8723->curPsTdma == 11) {
5729 btdm_1AntSetPSTDMA(padapter, true, 0, true, 9);
5730 pBtdm8723->psTdmaDuAdjType = 9;
5731 } else if (pBtdm8723->curPsTdma == 9) {
5732 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5733 pBtdm8723->psTdmaDuAdjType = 9;
5735 pBtdm8723->psTdmaDuAdjType = 2;
5736 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5737 } else if (pBtdm8723->curPsTdma == 2) {
5738 if (pHalData->bt_coexist.halCoex8723.btInfoExt)
5739 pBtdm8723->psTdmaDuAdjType = 9;
5741 pBtdm8723->psTdmaDuAdjType = 1;
5742 btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
5746 RTPRINT(FBT, BT_TRACE,
5747 ("[BTCoex], ACL current TDMA(%s, %d)\n",
5748 (pBtdm8723->bCurPsTdmaOn ? "ON" : "OFF"), pBtdm8723->curPsTdma));
5750 pBtdm8723->psTdmaMonitorCnt++;
5753 static void btdm_1AntCoexProcessForWifiConnect(struct rtw_adapter *padapter)
5755 struct mlme_priv *pmlmepriv;
5756 struct hal_data_8723a *pHalData;
5757 struct bt_coexist_8723a *pBtCoex;
5758 struct btdm_8723a_1ant *pBtdm8723;
5761 pmlmepriv = &padapter->mlmepriv;
5762 pHalData = GET_HAL_DATA(padapter);
5763 pBtCoex = &pHalData->bt_coexist.halCoex8723;
5764 pBtdm8723 = &pBtCoex->btdm1Ant;
5765 BtState = pBtCoex->c2hBtInfo;
5767 RTPRINT(FBT, BT_TRACE, ("[BTCoex], WiFi is %s\n", BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
5768 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is %s\n", BtStateString[BtState]));
5770 padapter->pwrctrlpriv.btcoex_rfon = false;
5772 if ((!BTDM_IsWifiBusy(padapter)) && (!check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE)) &&
5773 ((BtState == BT_INFO_STATE_NO_CONNECTION) || (BtState == BT_INFO_STATE_CONNECT_IDLE))) {
5775 case BT_INFO_STATE_NO_CONNECTION:
5776 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 9);
5778 case BT_INFO_STATE_CONNECT_IDLE:
5779 _btdm_1AntSetPSTDMA(padapter, true, 2, 0x26, false, 0);
5784 case BT_INFO_STATE_NO_CONNECTION:
5785 case BT_INFO_STATE_CONNECT_IDLE:
5787 btdm_1AntSetPSTDMA(padapter, false, 0, true, 5);
5788 rtw_write32(padapter, 0x6c0, 0x5a5a5a5a);
5789 rtw_write32(padapter, 0x6c4, 0x5a5a5a5a);
5791 case BT_INFO_STATE_ACL_INQ_OR_PAG:
5792 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT PROFILE is BT_INFO_STATE_ACL_INQ_OR_PAG\n"));
5793 case BT_INFO_STATE_INQ_OR_PAG:
5794 padapter->pwrctrlpriv.btcoex_rfon = true;
5795 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
5797 case BT_INFO_STATE_SCO_ONLY_BUSY:
5798 case BT_INFO_STATE_ACL_SCO_BUSY:
5799 if (true == pBtCoex->bC2hBtInquiryPage) {
5800 btdm_1AntSetPSTDMA(padapter, false, 0, true, 32);
5802 #ifdef BTCOEX_CMCC_TEST
5803 btdm_1AntSetPSTDMA(padapter, false, 0, true, 23);
5804 #else /* !BTCOEX_CMCC_TEST */
5805 btdm_1AntSetPSTDMA(padapter, false, 0, false, 8);
5806 rtw_write32(padapter, 0x6c0, 0x5a5a5a5a);
5807 rtw_write32(padapter, 0x6c4, 0x5a5a5a5a);
5808 #endif /* !BTCOEX_CMCC_TEST */
5811 case BT_INFO_STATE_ACL_ONLY_BUSY:
5812 padapter->pwrctrlpriv.btcoex_rfon = true;
5813 if (pBtCoex->c2hBtProfile == BT_INFO_HID) {
5814 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT PROFILE is HID\n"));
5815 btdm_1AntSetPSTDMA(padapter, true, 0, true, 31);
5816 } else if (pBtCoex->c2hBtProfile == BT_INFO_FTP) {
5817 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT PROFILE is FTP/OPP\n"));
5818 btdm_1AntSetPSTDMA(padapter, true, 0, true, 3);
5819 } else if (pBtCoex->c2hBtProfile == (BT_INFO_A2DP|BT_INFO_FTP)) {
5820 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT PROFILE is A2DP_FTP\n"));
5821 btdm_1AntSetPSTDMA(padapter, true, 0, true, 11);
5823 if (pBtCoex->c2hBtProfile == BT_INFO_A2DP)
5824 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT PROFILE is A2DP\n"));
5826 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT PROFILE is UNKNOWN(0x%02X)! Use A2DP Profile\n", pBtCoex->c2hBtProfile));
5827 btdm_1AntTdmaDurationAdjustForACL(padapter);
5833 pBtdm8723->psTdmaGlobalCnt++;
5836 static void btdm_1AntUpdateHalRAMask(struct rtw_adapter *padapter, u32 mac_id, u32 filter)
5841 u8 shortGIrate = false;
5842 int supportRateNum = 0;
5843 struct sta_info *psta;
5844 struct hal_data_8723a *pHalData;
5845 struct dm_priv *pdmpriv;
5846 struct mlme_ext_priv *pmlmeext;
5847 struct mlme_ext_info *pmlmeinfo;
5848 struct wlan_bssid_ex *cur_network;
5850 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d, filter = 0x%08x!!\n", __func__, mac_id, filter));
5852 pHalData = GET_HAL_DATA(padapter);
5853 pdmpriv = &pHalData->dmpriv;
5854 pmlmeext = &padapter->mlmeextpriv;
5855 pmlmeinfo = &pmlmeext->mlmext_info;
5856 cur_network = &pmlmeinfo->network;
5858 if (mac_id >= NUM_STA) { /* CAM_SIZE */
5859 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, MACID =%d illegal!!\n", __func__, mac_id));
5863 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
5865 RTPRINT(FBT, BT_TRACE, ("[BTCoex], %s, Can't find station!!\n", __func__));
5872 case 0:/* for infra mode */
5873 supportRateNum = rtw_get_rateset_len23a(cur_network->SupportedRates);
5874 mask = update_supported_rate23a(cur_network->SupportedRates, supportRateNum);
5875 mask |= (pmlmeinfo->HT_enable) ? update_MSC_rate23a(&pmlmeinfo->HT_caps):0;
5876 if (support_short_GI23a(padapter, &pmlmeinfo->HT_caps))
5879 case 1:/* for broadcast/multicast */
5880 supportRateNum = rtw_get_rateset_len23a(pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5881 mask = update_basic_rate23a(cur_network->SupportedRates, supportRateNum);
5883 default: /* for each sta in IBSS */
5884 supportRateNum = rtw_get_rateset_len23a(pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
5885 mask = update_supported_rate23a(cur_network->SupportedRates, supportRateNum);
5888 mask |= ((raid<<28)&0xf0000000);
5891 init_rate = get_highest_rate_idx23a(mask)&0x3f;
5893 if (pHalData->fw_ractrl) {
5896 arg = mac_id&0x1f;/* MACID */
5898 if (true == shortGIrate)
5901 RTPRINT(FBT, BT_TRACE,
5902 ("[BTCoex], Update FW RAID entry, MASK = 0x%08x, arg = 0x%02x\n",
5905 rtl8723a_set_raid_cmd(padapter, mask, arg);
5908 init_rate |= BIT(6);
5910 rtw_write8(padapter, (REG_INIDATA_RATE_SEL+mac_id), init_rate);
5913 psta->init_rate = init_rate;
5914 pdmpriv->INIDATA_RATE[mac_id] = init_rate;
5917 static void btdm_1AntUpdateHalRAMaskForSCO(struct rtw_adapter *padapter, u8 forceUpdate)
5919 struct btdm_8723a_1ant *pBtdm8723;
5920 struct sta_priv *pstapriv;
5921 struct wlan_bssid_ex *cur_network;
5922 struct sta_info *psta;
5926 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5928 if ((pBtdm8723->bRAChanged == true) && (forceUpdate == false))
5931 pstapriv = &padapter->stapriv;
5932 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5933 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5934 macid = psta->mac_id;
5936 filter |= BIT(_1M_RATE_);
5937 filter |= BIT(_2M_RATE_);
5938 filter |= BIT(_5M_RATE_);
5939 filter |= BIT(_11M_RATE_);
5940 filter |= BIT(_6M_RATE_);
5941 filter |= BIT(_9M_RATE_);
5943 btdm_1AntUpdateHalRAMask(padapter, macid, filter);
5945 pBtdm8723->bRAChanged = true;
5948 static void btdm_1AntRecoverHalRAMask(struct rtw_adapter *padapter)
5950 struct btdm_8723a_1ant *pBtdm8723;
5951 struct sta_priv *pstapriv;
5952 struct wlan_bssid_ex *cur_network;
5953 struct sta_info *psta;
5955 pBtdm8723 = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant;
5957 if (pBtdm8723->bRAChanged == false)
5960 pstapriv = &padapter->stapriv;
5961 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
5962 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5964 Update_RA_Entry23a(padapter, psta);
5966 pBtdm8723->bRAChanged = false;
5970 btdm_1AntBTStateChangeHandler(struct rtw_adapter *padapter,
5971 enum bt_state_1ant oldState, enum bt_state_1ant newState)
5973 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT state change, %s => %s\n", BtStateString[oldState], BtStateString[newState]));
5975 /* BT default ignore wlan active, */
5976 /* WiFi MUST disable this when BT is enable */
5977 if (newState > BT_INFO_STATE_DISABLED)
5978 btdm_SetFwIgnoreWlanAct(padapter, false);
5980 if ((check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
5981 (BTDM_IsWifiConnectionExist(padapter))) {
5982 if ((newState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
5983 (newState == BT_INFO_STATE_ACL_SCO_BUSY)) {
5984 btdm_1AntUpdateHalRAMaskForSCO(padapter, false);
5986 /* Recover original RA setting */
5987 btdm_1AntRecoverHalRAMask(padapter);
5990 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bRAChanged = false;
5993 if (oldState == newState)
5996 if (oldState == BT_INFO_STATE_ACL_ONLY_BUSY) {
5997 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
5998 pHalData->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCnt = 0;
5999 pHalData->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
6002 if ((oldState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6003 (oldState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6004 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6005 pHalData->bt_coexist.halCoex8723.btdm1Ant.psTdmaMonitorCntForSCO = 0;
6008 /* Active 2Ant mechanism when BT Connected */
6009 if ((oldState == BT_INFO_STATE_DISABLED) ||
6010 (oldState == BT_INFO_STATE_NO_CONNECTION)) {
6011 if ((newState != BT_INFO_STATE_DISABLED) &&
6012 (newState != BT_INFO_STATE_NO_CONNECTION)) {
6013 BTDM_SetSwRfRxLpfCorner(padapter, BT_RF_RX_LPF_CORNER_SHRINK);
6014 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6015 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6018 if ((newState == BT_INFO_STATE_DISABLED) ||
6019 (newState == BT_INFO_STATE_NO_CONNECTION)) {
6020 BTDM_SetSwRfRxLpfCorner(padapter, BT_RF_RX_LPF_CORNER_RESUME);
6021 BTDM_AGCTable(padapter, BT_AGCTABLE_OFF);
6022 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_OFF);
6027 static void btdm_1AntBtCoexistHandler(struct rtw_adapter *padapter)
6029 struct hal_data_8723a *pHalData;
6030 struct bt_coexist_8723a *pBtCoex8723;
6031 struct btdm_8723a_1ant *pBtdm8723;
6033 pHalData = GET_HAL_DATA(padapter);
6034 pBtCoex8723 = &pHalData->bt_coexist.halCoex8723;
6035 pBtdm8723 = &pBtCoex8723->btdm1Ant;
6036 padapter->pwrctrlpriv.btcoex_rfon = false;
6037 if (BT_IsBtDisabled(padapter)) {
6038 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is disabled\n"));
6040 if (BTDM_IsWifiConnectionExist(padapter)) {
6041 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is connected\n"));
6043 if (BTDM_IsWifiBusy(padapter)) {
6044 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Wifi is busy\n"));
6045 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6047 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Wifi is idle\n"));
6048 _btdm_1AntSetPSTDMA(padapter, true, 2, 1, false, 9);
6051 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is disconnected\n"));
6053 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6056 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT is enabled\n"));
6058 if (BTDM_IsWifiConnectionExist(padapter)) {
6059 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is connected\n"));
6061 btdm_1AntWifiParaAdjust(padapter, true);
6062 btdm_1AntCoexProcessForWifiConnect(padapter);
6064 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is disconnected\n"));
6066 /* Antenna switch at BT side(0x870 = 0x300, 0x860 = 0x210) after PSTDMA off */
6067 btdm_1AntWifiParaAdjust(padapter, false);
6068 btdm_1AntSetPSTDMA(padapter, false, 0, false, 0);
6072 btdm_1AntBTStateChangeHandler(padapter, pBtCoex8723->prec2hBtInfo, pBtCoex8723->c2hBtInfo);
6073 pBtCoex8723->prec2hBtInfo = pBtCoex8723->c2hBtInfo;
6076 void BTDM_1AntSignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
6078 struct hal_data_8723a *pHalData;
6079 struct btdm_8723a_1ant *pBtdm8723;
6080 u8 RSSI_WiFi_Cmpnstn, RSSI_BT_Cmpnstn;
6082 pHalData = GET_HAL_DATA(padapter);
6083 pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm1Ant;
6084 RSSI_WiFi_Cmpnstn = 0;
6085 RSSI_BT_Cmpnstn = 0;
6087 switch (pBtdm8723->curPsTdma) {
6088 case 1: /* WiFi 52ms */
6089 RSSI_WiFi_Cmpnstn = 11; /* 22*0.48 */
6091 case 2: /* WiFi 36ms */
6092 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6094 case 9: /* WiFi 20ms */
6095 RSSI_WiFi_Cmpnstn = 18; /* 22*0.80 */
6097 case 11: /* WiFi 10ms */
6098 RSSI_WiFi_Cmpnstn = 20; /* 22*0.90 */
6100 case 4: /* WiFi 21ms */
6101 RSSI_WiFi_Cmpnstn = 17; /* 22*0.79 */
6103 case 16: /* WiFi 24ms */
6104 RSSI_WiFi_Cmpnstn = 18; /* 22*0.76 */
6106 case 18: /* WiFi 37ms */
6107 RSSI_WiFi_Cmpnstn = 14; /* 22*0.64 */
6109 case 23: /* Level-1, Antenna switch to BT at all time */
6110 case 24: /* Level-2, Antenna switch to BT at all time */
6111 case 25: /* Level-3a, Antenna switch to BT at all time */
6112 case 26: /* Level-3b, Antenna switch to BT at all time */
6113 case 27: /* Level-3b, Antenna switch to BT at all time */
6114 case 33: /* BT SCO & WiFi site survey */
6115 RSSI_WiFi_Cmpnstn = 22;
6121 if (rssi_wifi && RSSI_WiFi_Cmpnstn) {
6122 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1AntSgnlCmpnstn, case %d, WiFiCmpnstn =%d(%d => %d)\n",
6123 pBtdm8723->curPsTdma, RSSI_WiFi_Cmpnstn, *rssi_wifi, *rssi_wifi+RSSI_WiFi_Cmpnstn));
6124 *rssi_wifi += RSSI_WiFi_Cmpnstn;
6127 if (rssi_bt && RSSI_BT_Cmpnstn) {
6128 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1AntSgnlCmpnstn, case %d, BTCmpnstn =%d(%d => %d)\n",
6129 pBtdm8723->curPsTdma, RSSI_BT_Cmpnstn, *rssi_bt, *rssi_bt+RSSI_BT_Cmpnstn));
6130 *rssi_bt += RSSI_BT_Cmpnstn;
6134 static void BTDM_1AntParaInit(struct rtw_adapter *padapter)
6136 struct hal_data_8723a *pHalData;
6137 struct bt_coexist_8723a *pBtCoex;
6138 struct btdm_8723a_1ant *pBtdm8723;
6140 pHalData = GET_HAL_DATA(padapter);
6141 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6142 pBtdm8723 = &pBtCoex->btdm1Ant;
6144 /* Enable counter statistics */
6145 rtw_write8(padapter, 0x76e, 0x4);
6146 btdm_1AntPtaParaReload(padapter);
6148 pBtdm8723->wifiRssiThresh = 48;
6150 pBtdm8723->bWiFiHalt = false;
6151 pBtdm8723->bRAChanged = false;
6153 if ((pBtCoex->c2hBtInfo != BT_INFO_STATE_DISABLED) &&
6154 (pBtCoex->c2hBtInfo != BT_INFO_STATE_NO_CONNECTION)) {
6155 BTDM_SetSwRfRxLpfCorner(padapter, BT_RF_RX_LPF_CORNER_SHRINK);
6156 BTDM_AGCTable(padapter, BT_AGCTABLE_ON);
6157 BTDM_BBBackOffLevel(padapter, BT_BB_BACKOFF_ON);
6161 static void BTDM_1AntForHalt(struct rtw_adapter *padapter)
6163 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for halt\n"));
6165 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt = true;
6167 btdm_1AntWifiParaAdjust(padapter, false);
6169 /* don't use btdm_1AntSetPSTDMA() here */
6170 /* it will call rtw_set_ps_mode23a() and request pwrpriv->lock. */
6171 /* This will lead to deadlock, if this function is called in IPS */
6172 /* Lucas@20130205 */
6173 btdm_1AntPsTdma(padapter, false, 0);
6175 btdm_SetFwIgnoreWlanAct(padapter, true);
6178 static void BTDM_1AntLpsLeave(struct rtw_adapter *padapter)
6180 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for LPS Leave\n"));
6182 /* Prevent from entering LPS again */
6183 GET_HAL_DATA(padapter)->bt_coexist.halCoex8723.btdm1Ant.bWiFiHalt = true;
6185 btdm_1AntSetPSTDMA(padapter, false, 0, false, 8);
6186 /*btdm_1AntPsTdma(padapter, false, 8); */
6189 static void BTDM_1AntWifiAssociateNotify(struct rtw_adapter *padapter, u8 type)
6191 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6193 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for associate, type =%d\n", type));
6196 rtl8723a_CheckAntenna_Selection(padapter);
6197 if (BT_IsBtDisabled(padapter)) {
6198 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6200 struct bt_coexist_8723a *pBtCoex;
6203 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6204 BtState = pBtCoex->c2hBtInfo;
6206 btdm_1AntTSFSwitch(padapter, true);
6208 if ((BtState == BT_INFO_STATE_NO_CONNECTION) ||
6209 (BtState == BT_INFO_STATE_CONNECT_IDLE)) {
6210 btdm_1AntSetPSTDMA(padapter, false, 0, true, 28);
6211 } else if ((BtState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6212 (BtState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6213 btdm_1AntSetPSTDMA(padapter, false, 0, false, 8);
6214 rtw_write32(padapter, 0x6c0, 0x5a5a5a5a);
6215 rtw_write32(padapter, 0x6c4, 0x5a5a5a5a);
6216 } else if ((BtState == BT_INFO_STATE_ACL_ONLY_BUSY) ||
6217 (BtState == BT_INFO_STATE_ACL_INQ_OR_PAG)) {
6218 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6219 btdm_1AntSetPSTDMA(padapter, false, 0, true, 35);
6221 btdm_1AntSetPSTDMA(padapter, false, 0, true, 29);
6225 if (BT_IsBtDisabled(padapter)) {
6226 if (!BTDM_IsWifiConnectionExist(padapter)) {
6227 btdm_1AntPsTdma(padapter, false, 0);
6228 btdm_1AntTSFSwitch(padapter, false);
6232 btdm_1AntBtCoexistHandler(padapter);
6237 BTDM_1AntMediaStatusNotify(struct rtw_adapter *padapter,
6238 enum rt_media_status mstatus)
6240 struct bt_coexist_8723a *pBtCoex;
6242 pBtCoex = &GET_HAL_DATA(padapter)->bt_coexist.halCoex8723;
6244 RTPRINT(FBT, BT_TRACE, ("\n\n[BTCoex]******************************\n"));
6245 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatus, WiFi %s !!\n",
6246 mstatus == RT_MEDIA_CONNECT?"CONNECT":"DISCONNECT"));
6247 RTPRINT(FBT, BT_TRACE, ("[BTCoex]******************************\n"));
6249 if (RT_MEDIA_CONNECT == mstatus) {
6250 if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) {
6251 if ((pBtCoex->c2hBtInfo == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6252 (pBtCoex->c2hBtInfo == BT_INFO_STATE_ACL_SCO_BUSY))
6253 btdm_1AntUpdateHalRAMaskForSCO(padapter, true);
6256 padapter->pwrctrlpriv.DelayLPSLastTimeStamp = jiffies;
6257 BTDM_1AntForDhcp(padapter);
6259 /* DBG_8723A("%s rtl8723a_DeinitAntenna_Selection\n", __func__); */
6260 rtl8723a_DeinitAntenna_Selection(padapter);
6261 btdm_1AntBtCoexistHandler(padapter);
6262 pBtCoex->btdm1Ant.bRAChanged = false;
6266 void BTDM_1AntForDhcp(struct rtw_adapter *padapter)
6268 struct hal_data_8723a *pHalData;
6270 struct bt_coexist_8723a *pBtCoex;
6271 struct btdm_8723a_1ant *pBtdm8723;
6273 pHalData = GET_HAL_DATA(padapter);
6274 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6275 BtState = pBtCoex->c2hBtInfo;
6276 pBtdm8723 = &pBtCoex->btdm1Ant;
6278 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for DHCP\n"));
6279 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, WiFi is %s\n", BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6280 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for DHCP, %s\n", BtStateString[BtState]));
6282 BTDM_1AntWifiAssociateNotify(padapter, true);
6285 static void BTDM_1AntWifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
6287 struct hal_data_8723a *pHalData;
6289 struct bt_coexist_8723a *pBtCoex;
6290 struct btdm_8723a_1ant *pBtdm8723;
6292 pHalData = GET_HAL_DATA(padapter);
6293 BtState = pHalData->bt_coexist.halCoex8723.c2hBtInfo;
6294 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6295 pBtdm8723 = &pBtCoex->btdm1Ant;
6297 RTPRINT(FBT, BT_TRACE, ("\n[BTCoex], 1Ant for wifi scan =%d!!\n", scanType));
6298 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, WiFi is %s\n", BTDM_IsWifiBusy(padapter)?"Busy":"IDLE"));
6299 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1Ant for wifi scan, %s\n", BtStateString[BtState]));
6302 rtl8723a_CheckAntenna_Selection(padapter);
6303 if (BT_IsBtDisabled(padapter)) {
6304 btdm_1AntSetPSTDMA(padapter, false, 0, false, 9);
6305 } else if (BTDM_IsWifiConnectionExist(padapter) == false) {
6306 BTDM_1AntWifiAssociateNotify(padapter, true);
6308 if ((BtState == BT_INFO_STATE_SCO_ONLY_BUSY) ||
6309 (BtState == BT_INFO_STATE_ACL_SCO_BUSY)) {
6310 if (pBtCoex->bC2hBtInquiryPage) {
6311 btdm_1AntSetPSTDMA(padapter, false, 0, true, 32);
6313 padapter->pwrctrlpriv.btcoex_rfon = true;
6314 btdm_1AntSetPSTDMA(padapter, true, 0, true, 33);
6316 } else if (true == pBtCoex->bC2hBtInquiryPage) {
6317 padapter->pwrctrlpriv.btcoex_rfon = true;
6318 btdm_1AntSetPSTDMA(padapter, true, 0, true, 30);
6319 } else if (BtState == BT_INFO_STATE_ACL_ONLY_BUSY) {
6320 padapter->pwrctrlpriv.btcoex_rfon = true;
6321 if (pBtCoex->c2hBtProfile == BT_INFO_HID)
6322 btdm_1AntSetPSTDMA(padapter, true, 0, true, 34);
6324 btdm_1AntSetPSTDMA(padapter, true, 0, true, 4);
6326 padapter->pwrctrlpriv.btcoex_rfon = true;
6327 btdm_1AntSetPSTDMA(padapter, true, 0, true, 5);
6331 btdm_NotifyFwScan(padapter, 1);
6333 /* WiFi_Finish_Scan */
6334 btdm_NotifyFwScan(padapter, 0);
6335 btdm_1AntBtCoexistHandler(padapter);
6339 static void BTDM_1AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
6341 struct hal_data_8723a *pHalData;
6342 struct bt_30info *pBTInfo;
6343 struct bt_mgnt *pBtMgnt;
6344 struct bt_coexist_8723a *pBtCoex;
6347 pHalData = GET_HAL_DATA(padapter);
6348 pBTInfo = GET_BT_INFO(padapter);
6349 pBtMgnt = &pBTInfo->BtMgnt;
6350 pBtCoex = &pHalData->bt_coexist.halCoex8723;
6352 u1tmp = pBtCoex->c2hBtInfoOriginal;
6353 /* sco BUSY bit is not used on voice over PCM platform */
6354 btState = u1tmp & 0xF;
6355 pBtCoex->c2hBtProfile = u1tmp & 0xE0;
6357 /* default set bt to idle state. */
6358 pBtMgnt->ExtConfig.bBTBusy = false;
6359 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
6361 /* check BIT2 first ==> check if bt is under inquiry or page scan */
6362 if (btState & BIT(2))
6363 pBtCoex->bC2hBtInquiryPage = true;
6365 pBtCoex->bC2hBtInquiryPage = false;
6368 if (!(btState & BIT(0))) {
6369 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
6371 if (btState == 0x1) {
6372 pBtCoex->c2hBtInfo = BT_INFO_STATE_CONNECT_IDLE;
6373 } else if (btState == 0x9) {
6374 if (pBtCoex->bC2hBtInquiryPage == true)
6375 pBtCoex->c2hBtInfo = BT_INFO_STATE_ACL_INQ_OR_PAG;
6377 pBtCoex->c2hBtInfo = BT_INFO_STATE_ACL_ONLY_BUSY;
6378 pBtMgnt->ExtConfig.bBTBusy = true;
6379 } else if (btState == 0x3) {
6380 pBtCoex->c2hBtInfo = BT_INFO_STATE_SCO_ONLY_BUSY;
6381 pBtMgnt->ExtConfig.bBTBusy = true;
6382 } else if (btState == 0xb) {
6383 pBtCoex->c2hBtInfo = BT_INFO_STATE_ACL_SCO_BUSY;
6384 pBtMgnt->ExtConfig.bBTBusy = true;
6386 pBtCoex->c2hBtInfo = BT_INFO_STATE_MAX;
6388 if (pBtMgnt->ExtConfig.bBTBusy)
6389 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_IDLE;
6392 if ((BT_INFO_STATE_NO_CONNECTION == pBtCoex->c2hBtInfo) ||
6393 (BT_INFO_STATE_CONNECT_IDLE == pBtCoex->c2hBtInfo)) {
6394 if (pBtCoex->bC2hBtInquiryPage)
6395 pBtCoex->c2hBtInfo = BT_INFO_STATE_INQ_OR_PAG;
6398 RTPRINT(FBT, BT_TRACE, ("[BTC2H], %s(%d)\n",
6399 BtStateString[pBtCoex->c2hBtInfo], pBtCoex->c2hBtInfo));
6401 if (pBtCoex->c2hBtProfile != BT_INFO_HID)
6402 pBtCoex->c2hBtProfile &= ~BT_INFO_HID;
6405 void BTDM_1AntBtCoexist8723A(struct rtw_adapter *padapter)
6407 struct mlme_priv *pmlmepriv;
6408 struct hal_data_8723a *pHalData;
6409 unsigned long delta_time;
6411 pmlmepriv = &padapter->mlmepriv;
6412 pHalData = GET_HAL_DATA(padapter);
6414 if (check_fwstate(pmlmepriv, WIFI_SITE_MONITOR)) {
6415 /* already done in BTDM_1AntForScan() */
6416 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is under scan progress!!\n"));
6420 if (check_fwstate(pmlmepriv, WIFI_UNDER_LINKING)) {
6421 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is under link progress!!\n"));
6425 /* under DHCP(Special packet) */
6426 delta_time = jiffies - padapter->pwrctrlpriv.DelayLPSLastTimeStamp;
6427 delta_time = jiffies_to_msecs(delta_time);
6428 if (delta_time < 500) {
6429 RTPRINT(FBT, BT_TRACE, ("[BTCoex], wifi is under DHCP "
6430 "progress(%li ms)!!\n", delta_time));
6434 BTDM_CheckWiFiState(padapter);
6436 btdm_1AntBtCoexistHandler(padapter);
6439 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87231Ant.c ===== */
6442 #ifdef __HALBTC87232ANT_C__ /* HAL/BTCoexist/HalBtc87232Ant.c */
6443 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
6445 /* local function start with btdm_ */
6446 static u8 btdm_ActionAlgorithm(struct rtw_adapter *padapter)
6448 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
6449 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
6450 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6451 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6452 u8 bScoExist = false, bBtLinkExist = false, bBtHsModeExist = false;
6453 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
6455 if (pBtMgnt->ExtConfig.NumberOfHandle)
6456 bBtLinkExist = true;
6457 if (pBtMgnt->ExtConfig.NumberOfSCO)
6459 if (BT_HsConnectionEstablished(padapter))
6460 bBtHsModeExist = true;
6462 /* here we get BT status first */
6464 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
6466 if ((bScoExist) || (bBtHsModeExist) ||
6467 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID))) {
6468 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO or HID or HS exists, set BT non-idle !!!\n"));
6469 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6472 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6473 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP))) {
6474 if (BTDM_BtTxRxCounterL(padapter) < 100) {
6475 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx < 100, set BT connected-idle!!!\n"));
6476 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6478 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP, low priority tx+rx >= 100, set BT non-idle!!!\n"));
6479 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6483 if ((pBtMgnt->ExtConfig.NumberOfHandle == 1) &&
6484 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6485 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6486 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6487 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6489 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6490 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6491 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6492 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6493 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6497 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6498 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN, set BT non-idle!!!\n"));
6499 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6502 /* Pan+A2dp profile */
6503 if ((pBtMgnt->ExtConfig.NumberOfHandle == 2) &&
6504 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) &&
6505 (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN))) {
6506 if (BTDM_BtTxRxCounterL(padapter) < 600) {
6507 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority tx+rx < 600, set BT connected-idle!!!\n"));
6508 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6510 if (pHalData->bt_coexist.halCoex8723.lowPriorityTx) {
6511 if ((pHalData->bt_coexist.halCoex8723.lowPriorityRx /
6512 pHalData->bt_coexist.halCoex8723.lowPriorityTx) > 9) {
6513 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, low priority rx/tx > 9, set BT connected-idle!!!\n"));
6514 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
6518 if (BT_2ANT_BT_STATUS_CONNECTED_IDLE != pBtdm8723->btStatus) {
6519 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN+A2DP, set BT non-idle!!!\n"));
6520 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
6524 if (BT_2ANT_BT_STATUS_IDLE != pBtdm8723->btStatus)
6525 pBtMgnt->ExtConfig.bBTBusy = true;
6527 pBtMgnt->ExtConfig.bBTBusy = false;
6529 if (!bBtLinkExist) {
6530 RTPRINT(FBT, BT_TRACE, ("[BTCoex], No profile exists!!!\n"));
6534 if (pBtMgnt->ExtConfig.NumberOfHandle == 1) {
6536 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
6537 algorithm = BT_2ANT_COEX_ALGO_SCO;
6539 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6540 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID only\n"));
6541 algorithm = BT_2ANT_COEX_ALGO_HID;
6542 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6543 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP only\n"));
6544 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6545 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6546 if (bBtHsModeExist) {
6547 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(HS) only\n"));
6548 algorithm = BT_2ANT_COEX_ALGO_PANHS;
6550 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR) only\n"));
6551 algorithm = BT_2ANT_COEX_ALGO_PANEDR;
6554 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d \n",
6555 pBtMgnt->ExtConfig.NumberOfHandle));
6558 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 2) {
6560 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) {
6561 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
6562 algorithm = BT_2ANT_COEX_ALGO_HID;
6563 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6564 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
6565 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6566 if (bBtHsModeExist) {
6567 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
6568 algorithm = BT_2ANT_COEX_ALGO_SCO;
6570 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
6571 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6574 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched ACL profile for NumberOfHandle =%d\n",
6575 pBtMgnt->ExtConfig.NumberOfHandle));
6578 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6579 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6580 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
6581 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6582 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6583 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6584 if (bBtHsModeExist) {
6585 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
6586 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6588 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
6589 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6591 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6592 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6593 if (bBtHsModeExist) {
6594 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
6595 algorithm = BT_2ANT_COEX_ALGO_A2DP;
6597 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
6598 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
6601 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6602 pBtMgnt->ExtConfig.NumberOfHandle));
6605 } else if (pBtMgnt->ExtConfig.NumberOfHandle == 3) {
6607 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6608 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6609 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP\n"));
6610 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6611 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
6612 if (bBtHsModeExist) {
6613 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));
6614 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
6616 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));
6617 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
6619 } else if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6620 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6621 if (bBtHsModeExist) {
6622 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(HS)\n"));
6623 algorithm = BT_2ANT_COEX_ALGO_SCO;
6625 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP + PAN(EDR)\n"));
6628 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6629 pBtMgnt->ExtConfig.NumberOfHandle));
6632 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6633 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6634 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6635 if (bBtHsModeExist) {
6636 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
6637 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANHS;
6639 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
6640 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
6643 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6644 pBtMgnt->ExtConfig.NumberOfHandle));
6647 } else if (pBtMgnt->ExtConfig.NumberOfHandle >= 3) {
6649 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
6650 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
6651 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
6653 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
6655 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(EDR)\n"));
6657 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO exists but why NO matched profile for NumberOfHandle =%d\n",
6658 pBtMgnt->ExtConfig.NumberOfHandle));
6661 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! NO matched profile for NumberOfHandle =%d\n",
6662 pBtMgnt->ExtConfig.NumberOfHandle));
6668 static u8 btdm_NeedToDecBtPwr(struct rtw_adapter *padapter)
6670 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6673 if (BT_Operation(padapter)) {
6674 if (pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB > 47) {
6675 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for HS mode!!\n"));
6678 RTPRINT(FBT, BT_TRACE, ("NO Need to decrease bt power for HS mode!!\n"));
6681 if (BTDM_IsWifiConnectionExist(padapter)) {
6682 RTPRINT(FBT, BT_TRACE, ("Need to decrease bt power for Wifi is connected!!\n"));
6690 btdm_SetCoexTable(struct rtw_adapter *padapter, u32 val0x6c0,
6691 u32 val0x6c8, u8 val0x6cc)
6693 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c0 = 0x%x\n", val0x6c0));
6694 rtw_write32(padapter, 0x6c0, val0x6c0);
6696 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6c8 = 0x%x\n", val0x6c8));
6697 rtw_write32(padapter, 0x6c8, val0x6c8);
6699 RTPRINT(FBT, BT_TRACE, ("set coex table, set 0x6cc = 0x%x\n", val0x6cc));
6700 rtw_write8(padapter, 0x6cc, val0x6cc);
6704 btdm_SetSwFullTimeDacSwing(struct rtw_adapter *padapter, u8 bSwDacSwingOn,
6707 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6709 if (bSwDacSwingOn) {
6710 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing = 0x%x\n", swDacSwingLvl));
6711 PHY_SetBBReg(padapter, 0x880, 0xff000000, swDacSwingLvl);
6712 pHalData->bt_coexist.bSWCoexistAllOff = false;
6714 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SwDacSwing Off!\n"));
6715 PHY_SetBBReg(padapter, 0x880, 0xff000000, 0xc0);
6720 btdm_SetFwDacSwingLevel(struct rtw_adapter *padapter, u8 dacSwingLvl)
6722 u8 H2C_Parameter[1] = {0};
6724 H2C_Parameter[0] = dacSwingLvl;
6726 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Set Dac Swing Level = 0x%x\n", dacSwingLvl));
6727 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write 0x29 = 0x%x\n", H2C_Parameter[0]));
6729 FillH2CCmd(padapter, 0x29, 1, H2C_Parameter);
6732 static void btdm_2AntDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
6734 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6735 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6737 RTPRINT(FBT, BT_TRACE,
6738 ("[BTCoex], Dec BT power = %s\n",
6739 ((bDecBtPwr) ? "ON" : "OFF")));
6740 pBtdm8723->bCurDecBtPwr = bDecBtPwr;
6742 if (pBtdm8723->bPreDecBtPwr == pBtdm8723->bCurDecBtPwr)
6745 BTDM_SetFwDecBtPwr(padapter, pBtdm8723->bCurDecBtPwr);
6747 pBtdm8723->bPreDecBtPwr = pBtdm8723->bCurDecBtPwr;
6751 btdm_2AntFwDacSwingLvl(struct rtw_adapter *padapter, u8 fwDacSwingLvl)
6753 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6754 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6756 RTPRINT(FBT, BT_TRACE, ("[BTCoex], set FW Dac Swing level = %d\n", fwDacSwingLvl));
6757 pBtdm8723->curFwDacSwingLvl = fwDacSwingLvl;
6759 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preFwDacSwingLvl =%d, curFwDacSwingLvl =%d\n", */
6760 /*pBtdm8723->preFwDacSwingLvl, pBtdm8723->curFwDacSwingLvl)); */
6762 if (pBtdm8723->preFwDacSwingLvl == pBtdm8723->curFwDacSwingLvl)
6765 btdm_SetFwDacSwingLevel(padapter, pBtdm8723->curFwDacSwingLvl);
6767 pBtdm8723->preFwDacSwingLvl = pBtdm8723->curFwDacSwingLvl;
6771 btdm_2AntRfShrink(struct rtw_adapter *padapter, u8 bRxRfShrinkOn)
6773 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6774 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6776 RTPRINT(FBT, BT_TRACE,
6777 ("[BTCoex], turn Rx RF Shrink = %s\n",
6778 ((bRxRfShrinkOn) ? "ON" : "OFF")));
6779 pBtdm8723->bCurRfRxLpfShrink = bRxRfShrinkOn;
6781 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreRfRxLpfShrink =%d, bCurRfRxLpfShrink =%d\n", */
6782 /*pBtdm8723->bPreRfRxLpfShrink, pBtdm8723->bCurRfRxLpfShrink)); */
6784 if (pBtdm8723->bPreRfRxLpfShrink == pBtdm8723->bCurRfRxLpfShrink)
6787 BTDM_SetSwRfRxLpfCorner(padapter, (u8)pBtdm8723->bCurRfRxLpfShrink);
6789 pBtdm8723->bPreRfRxLpfShrink = pBtdm8723->bCurRfRxLpfShrink;
6793 btdm_2AntLowPenaltyRa(struct rtw_adapter *padapter, u8 bLowPenaltyRa)
6795 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6796 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6798 RTPRINT(FBT, BT_TRACE,
6799 ("[BTCoex], turn LowPenaltyRA = %s\n",
6800 ((bLowPenaltyRa) ? "ON" : "OFF")));
6801 pBtdm8723->bCurLowPenaltyRa = bLowPenaltyRa;
6803 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreLowPenaltyRa =%d, bCurLowPenaltyRa =%d\n", */
6804 /*pBtdm8723->bPreLowPenaltyRa, pBtdm8723->bCurLowPenaltyRa)); */
6806 if (pBtdm8723->bPreLowPenaltyRa == pBtdm8723->bCurLowPenaltyRa)
6809 BTDM_SetSwPenaltyTxRateAdaptive(padapter, (u8)pBtdm8723->bCurLowPenaltyRa);
6811 pBtdm8723->bPreLowPenaltyRa = pBtdm8723->bCurLowPenaltyRa;
6815 btdm_2AntDacSwing(struct rtw_adapter *padapter,
6816 u8 bDacSwingOn, u32 dacSwingLvl)
6818 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6819 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6821 RTPRINT(FBT, BT_TRACE,
6822 ("[BTCoex], turn DacSwing =%s, dacSwingLvl = 0x%x\n",
6823 (bDacSwingOn ? "ON" : "OFF"), dacSwingLvl));
6824 pBtdm8723->bCurDacSwingOn = bDacSwingOn;
6825 pBtdm8723->curDacSwingLvl = dacSwingLvl;
6827 if ((pBtdm8723->bPreDacSwingOn == pBtdm8723->bCurDacSwingOn) &&
6828 (pBtdm8723->preDacSwingLvl == pBtdm8723->curDacSwingLvl))
6832 btdm_SetSwFullTimeDacSwing(padapter, bDacSwingOn, dacSwingLvl);
6834 pBtdm8723->bPreDacSwingOn = pBtdm8723->bCurDacSwingOn;
6835 pBtdm8723->preDacSwingLvl = pBtdm8723->curDacSwingLvl;
6838 static void btdm_2AntAdcBackOff(struct rtw_adapter *padapter, u8 bAdcBackOff)
6840 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6841 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6843 RTPRINT(FBT, BT_TRACE,
6844 ("[BTCoex], turn AdcBackOff = %s\n",
6845 ((bAdcBackOff) ? "ON" : "OFF")));
6846 pBtdm8723->bCurAdcBackOff = bAdcBackOff;
6848 if (pBtdm8723->bPreAdcBackOff == pBtdm8723->bCurAdcBackOff)
6851 BTDM_BBBackOffLevel(padapter, (u8)pBtdm8723->bCurAdcBackOff);
6853 pBtdm8723->bPreAdcBackOff = pBtdm8723->bCurAdcBackOff;
6856 static void btdm_2AntAgcTable(struct rtw_adapter *padapter, u8 bAgcTableEn)
6858 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6859 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6861 RTPRINT(FBT, BT_TRACE,
6862 ("[BTCoex], %s Agc Table\n", ((bAgcTableEn) ? "Enable" : "Disable")));
6863 pBtdm8723->bCurAgcTableEn = bAgcTableEn;
6865 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], bPreAgcTableEn =%d, bCurAgcTableEn =%d\n", */
6866 /*pBtdm8723->bPreAgcTableEn, pBtdm8723->bCurAgcTableEn)); */
6868 if (pBtdm8723->bPreAgcTableEn == pBtdm8723->bCurAgcTableEn)
6871 BTDM_AGCTable(padapter, (u8)bAgcTableEn);
6873 pBtdm8723->bPreAgcTableEn = pBtdm8723->bCurAgcTableEn;
6877 btdm_2AntCoexTable(struct rtw_adapter *padapter,
6878 u32 val0x6c0, u32 val0x6c8, u8 val0x6cc)
6880 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6881 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6883 RTPRINT(FBT, BT_TRACE, ("[BTCoex], write Coex Table 0x6c0 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
6884 val0x6c0, val0x6c8, val0x6cc));
6885 pBtdm8723->curVal0x6c0 = val0x6c0;
6886 pBtdm8723->curVal0x6c8 = val0x6c8;
6887 pBtdm8723->curVal0x6cc = val0x6cc;
6889 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n", */
6890 /*pBtdm8723->preVal0x6c0, pBtdm8723->preVal0x6c8, pBtdm8723->preVal0x6cc)); */
6891 /* RTPRINT(FBT, BT_TRACE, ("[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n", */
6892 /*pBtdm8723->curVal0x6c0, pBtdm8723->curVal0x6c8, pBtdm8723->curVal0x6cc)); */
6894 if ((pBtdm8723->preVal0x6c0 == pBtdm8723->curVal0x6c0) &&
6895 (pBtdm8723->preVal0x6c8 == pBtdm8723->curVal0x6c8) &&
6896 (pBtdm8723->preVal0x6cc == pBtdm8723->curVal0x6cc))
6899 btdm_SetCoexTable(padapter, val0x6c0, val0x6c8, val0x6cc);
6901 pBtdm8723->preVal0x6c0 = pBtdm8723->curVal0x6c0;
6902 pBtdm8723->preVal0x6c8 = pBtdm8723->curVal0x6c8;
6903 pBtdm8723->preVal0x6cc = pBtdm8723->curVal0x6cc;
6906 static void btdm_2AntIgnoreWlanAct(struct rtw_adapter *padapter, u8 bEnable)
6908 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6909 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6911 RTPRINT(FBT, BT_TRACE,
6912 ("[BTCoex], turn Ignore WlanAct %s\n", (bEnable ? "ON" : "OFF")));
6913 pBtdm8723->bCurIgnoreWlanAct = bEnable;
6916 if (pBtdm8723->bPreIgnoreWlanAct == pBtdm8723->bCurIgnoreWlanAct)
6919 btdm_SetFwIgnoreWlanAct(padapter, bEnable);
6920 pBtdm8723->bPreIgnoreWlanAct = pBtdm8723->bCurIgnoreWlanAct;
6924 btdm_2AntSetFw3a(struct rtw_adapter *padapter, u8 byte1, u8 byte2,
6925 u8 byte3, u8 byte4, u8 byte5)
6927 u8 H2C_Parameter[5] = {0};
6929 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6931 /* byte1[1:0] != 0 means enable pstdma */
6932 /* for 2Ant bt coexist, if byte1 != 0 means enable pstdma */
6934 pHalData->bt_coexist.bFWCoexistAllOff = false;
6935 H2C_Parameter[0] = byte1;
6936 H2C_Parameter[1] = byte2;
6937 H2C_Parameter[2] = byte3;
6938 H2C_Parameter[3] = byte4;
6939 H2C_Parameter[4] = byte5;
6941 pHalData->bt_coexist.fw3aVal[0] = byte1;
6942 pHalData->bt_coexist.fw3aVal[1] = byte2;
6943 pHalData->bt_coexist.fw3aVal[2] = byte3;
6944 pHalData->bt_coexist.fw3aVal[3] = byte4;
6945 pHalData->bt_coexist.fw3aVal[4] = byte5;
6947 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%x%08x\n",
6949 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
6951 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
6954 static void btdm_2AntPsTdma(struct rtw_adapter *padapter, u8 bTurnOn, u8 type)
6956 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
6957 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
6959 u8 bTurnOnByCnt = false;
6960 u8 psTdmaTypeByCnt = 0;
6962 btTxRxCnt = BTDM_BtTxRxCounterH(padapter)+BTDM_BtTxRxCounterL(padapter);
6963 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT TxRx Counters = %d\n", btTxRxCnt));
6964 if (btTxRxCnt > 3000) {
6965 bTurnOnByCnt = true;
6966 psTdmaTypeByCnt = 8;
6968 RTPRINT(FBT, BT_TRACE,
6969 ("[BTCoex], For BTTxRxCounters, turn %s PS TDMA, type =%d\n",
6970 (bTurnOnByCnt ? "ON" : "OFF"), psTdmaTypeByCnt));
6971 pBtdm8723->bCurPsTdmaOn = bTurnOnByCnt;
6972 pBtdm8723->curPsTdma = psTdmaTypeByCnt;
6974 RTPRINT(FBT, BT_TRACE,
6975 ("[BTCoex], turn %s PS TDMA, type =%d\n",
6976 (bTurnOn ? "ON" : "OFF"), type));
6977 pBtdm8723->bCurPsTdmaOn = bTurnOn;
6978 pBtdm8723->curPsTdma = type;
6981 if ((pBtdm8723->bPrePsTdmaOn == pBtdm8723->bCurPsTdmaOn) &&
6982 (pBtdm8723->prePsTdma == pBtdm8723->curPsTdma))
6989 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
6992 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
6995 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
6998 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0xa1, 0x80);
7001 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7004 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7007 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7010 btdm_2AntSetFw3a(padapter, 0xa3, 0x5, 0x5, 0x20, 0x80);
7013 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0xa1, 0x98);
7016 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0xa1, 0x98);
7019 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0xa1, 0x98);
7022 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7025 btdm_2AntSetFw3a(padapter, 0xe3, 0x1a, 0x1a, 0x20, 0x98);
7028 btdm_2AntSetFw3a(padapter, 0xe3, 0x12, 0x12, 0x20, 0x98);
7031 btdm_2AntSetFw3a(padapter, 0xe3, 0xa, 0xa, 0x20, 0x98);
7034 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0x20, 0x98);
7037 btdm_2AntSetFw3a(padapter, 0xa3, 0x2f, 0x2f, 0x20, 0x80);
7040 btdm_2AntSetFw3a(padapter, 0xe3, 0x5, 0x5, 0xa1, 0x98);
7043 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0xa1, 0x98);
7046 btdm_2AntSetFw3a(padapter, 0xe3, 0x25, 0x25, 0x20, 0x98);
7050 /* disable PS tdma */
7053 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7056 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x0, 0x0);
7059 btdm_2AntSetFw3a(padapter, 0x0, 0x0, 0x0, 0x8, 0x0);
7064 /* update pre state */
7065 pBtdm8723->bPrePsTdmaOn = pBtdm8723->bCurPsTdmaOn;
7066 pBtdm8723->prePsTdma = pBtdm8723->curPsTdma;
7069 static void btdm_2AntBtInquiryPage(struct rtw_adapter *padapter)
7071 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7072 btdm_2AntIgnoreWlanAct(padapter, false);
7073 btdm_2AntPsTdma(padapter, true, 8);
7076 static u8 btdm_HoldForBtInqPage(struct rtw_adapter *padapter)
7078 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7079 u32 curTime = jiffies;
7081 if (pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
7082 /* bt inquiry or page is started. */
7083 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime == 0) {
7084 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = curTime;
7085 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page is started at time : 0x%lx \n",
7086 pHalData->bt_coexist.halCoex8723.btInqPageStartTime));
7089 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page started time : 0x%lx, curTime : 0x%x \n",
7090 pHalData->bt_coexist.halCoex8723.btInqPageStartTime, curTime));
7092 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7093 if (((curTime - pHalData->bt_coexist.halCoex8723.btInqPageStartTime)/1000000) >= 10) {
7094 RTPRINT(FBT, BT_TRACE, ("[BTCoex], BT Inquiry/page >= 10sec!!!"));
7095 pHalData->bt_coexist.halCoex8723.btInqPageStartTime = 0;
7099 if (pHalData->bt_coexist.halCoex8723.btInqPageStartTime) {
7100 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7101 btdm_2AntIgnoreWlanAct(padapter, false);
7102 btdm_2AntPsTdma(padapter, true, 8);
7109 static u8 btdm_Is2Ant8723ACommonAction(struct rtw_adapter *padapter)
7111 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7112 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7115 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));
7117 if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7118 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7119 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7120 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt idle!!\n"));
7122 btdm_2AntLowPenaltyRa(padapter, false);
7123 btdm_2AntRfShrink(padapter, false);
7124 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7126 btdm_2AntIgnoreWlanAct(padapter, false);
7127 btdm_2AntPsTdma(padapter, false, 0);
7128 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7129 btdm_2AntDecBtPwr(padapter, false);
7131 btdm_2AntAgcTable(padapter, false);
7132 btdm_2AntAdcBackOff(padapter, false);
7133 btdm_2AntDacSwing(padapter, false, 0xc0);
7136 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7137 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7138 (BT_2ANT_BT_STATUS_IDLE == pBtdm8723->btStatus)) {
7139 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT idle!!\n"));
7141 btdm_2AntLowPenaltyRa(padapter, true);
7142 btdm_2AntRfShrink(padapter, false);
7143 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7145 btdm_2AntIgnoreWlanAct(padapter, false);
7146 btdm_2AntPsTdma(padapter, false, 0);
7147 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7148 btdm_2AntDecBtPwr(padapter, true);
7150 btdm_2AntAgcTable(padapter, false);
7151 btdm_2AntAdcBackOff(padapter, false);
7152 btdm_2AntDacSwing(padapter, false, 0xc0);
7155 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7156 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7157 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7158 RTPRINT(FBT, BT_TRACE, ("Wifi idle + Bt connected idle!!\n"));
7160 btdm_2AntLowPenaltyRa(padapter, true);
7161 btdm_2AntRfShrink(padapter, true);
7162 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7164 btdm_2AntIgnoreWlanAct(padapter, false);
7165 btdm_2AntPsTdma(padapter, false, 0);
7166 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7167 btdm_2AntDecBtPwr(padapter, false);
7169 btdm_2AntAgcTable(padapter, false);
7170 btdm_2AntAdcBackOff(padapter, false);
7171 btdm_2AntDacSwing(padapter, false, 0xc0);
7174 } else if (((BTDM_IsWifiConnectionExist(padapter)) ||
7175 (check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING)))) &&
7176 (BT_2ANT_BT_STATUS_CONNECTED_IDLE == pBtdm8723->btStatus)) {
7177 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + Bt connected idle!!\n"));
7179 btdm_2AntLowPenaltyRa(padapter, true);
7180 btdm_2AntRfShrink(padapter, true);
7181 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7183 btdm_2AntIgnoreWlanAct(padapter, false);
7184 btdm_2AntPsTdma(padapter, false, 0);
7185 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7186 btdm_2AntDecBtPwr(padapter, true);
7188 btdm_2AntAgcTable(padapter, false);
7189 btdm_2AntAdcBackOff(padapter, false);
7190 btdm_2AntDacSwing(padapter, false, 0xc0);
7193 } else if ((!BTDM_IsWifiConnectionExist(padapter)) &&
7194 (!check_fwstate(&padapter->mlmepriv, (_FW_UNDER_SURVEY|_FW_UNDER_LINKING))) &&
7195 (BT_2ANT_BT_STATUS_NON_IDLE == pBtdm8723->btStatus)) {
7196 RTPRINT(FBT, BT_TRACE, ("Wifi idle + BT non-idle!!\n"));
7198 btdm_2AntLowPenaltyRa(padapter, true);
7199 btdm_2AntRfShrink(padapter, true);
7200 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7202 btdm_2AntIgnoreWlanAct(padapter, false);
7203 btdm_2AntPsTdma(padapter, false, 0);
7204 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7205 btdm_2AntDecBtPwr(padapter, false);
7207 btdm_2AntAgcTable(padapter, false);
7208 btdm_2AntAdcBackOff(padapter, false);
7209 btdm_2AntDacSwing(padapter, false, 0xc0);
7213 RTPRINT(FBT, BT_TRACE, ("Wifi non-idle + BT non-idle!!\n"));
7214 btdm_2AntLowPenaltyRa(padapter, true);
7215 btdm_2AntRfShrink(padapter, true);
7216 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
7217 btdm_2AntIgnoreWlanAct(padapter, false);
7218 btdm_2AntFwDacSwingLvl(padapter, 0x20);
7226 btdm_2AntTdmaDurationAdjust(struct rtw_adapter *padapter, u8 bScoHid,
7227 u8 bTxPause, u8 maxInterval)
7229 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7230 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
7231 static s32 up, dn, m, n, WaitCount;
7232 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
7235 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));
7237 if (pBtdm8723->bResetTdmaAdjust) {
7238 pBtdm8723->bResetTdmaAdjust = false;
7239 RTPRINT(FBT, BT_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
7242 if (maxInterval == 1) {
7243 btdm_2AntPsTdma(padapter, true, 15);
7244 pBtdm8723->psTdmaDuAdjType = 15;
7245 } else if (maxInterval == 2) {
7246 btdm_2AntPsTdma(padapter, true, 15);
7247 pBtdm8723->psTdmaDuAdjType = 15;
7248 } else if (maxInterval == 3) {
7249 btdm_2AntPsTdma(padapter, true, 15);
7250 pBtdm8723->psTdmaDuAdjType = 15;
7252 btdm_2AntPsTdma(padapter, true, 15);
7253 pBtdm8723->psTdmaDuAdjType = 15;
7256 if (maxInterval == 1) {
7257 btdm_2AntPsTdma(padapter, true, 11);
7258 pBtdm8723->psTdmaDuAdjType = 11;
7259 } else if (maxInterval == 2) {
7260 btdm_2AntPsTdma(padapter, true, 11);
7261 pBtdm8723->psTdmaDuAdjType = 11;
7262 } else if (maxInterval == 3) {
7263 btdm_2AntPsTdma(padapter, true, 11);
7264 pBtdm8723->psTdmaDuAdjType = 11;
7266 btdm_2AntPsTdma(padapter, true, 11);
7267 pBtdm8723->psTdmaDuAdjType = 11;
7272 if (maxInterval == 1) {
7273 btdm_2AntPsTdma(padapter, true, 7);
7274 pBtdm8723->psTdmaDuAdjType = 7;
7275 } else if (maxInterval == 2) {
7276 btdm_2AntPsTdma(padapter, true, 7);
7277 pBtdm8723->psTdmaDuAdjType = 7;
7278 } else if (maxInterval == 3) {
7279 btdm_2AntPsTdma(padapter, true, 7);
7280 pBtdm8723->psTdmaDuAdjType = 7;
7282 btdm_2AntPsTdma(padapter, true, 7);
7283 pBtdm8723->psTdmaDuAdjType = 7;
7286 if (maxInterval == 1) {
7287 btdm_2AntPsTdma(padapter, true, 3);
7288 pBtdm8723->psTdmaDuAdjType = 3;
7289 } else if (maxInterval == 2) {
7290 btdm_2AntPsTdma(padapter, true, 3);
7291 pBtdm8723->psTdmaDuAdjType = 3;
7292 } else if (maxInterval == 3) {
7293 btdm_2AntPsTdma(padapter, true, 3);
7294 pBtdm8723->psTdmaDuAdjType = 3;
7296 btdm_2AntPsTdma(padapter, true, 3);
7297 pBtdm8723->psTdmaDuAdjType = 3;
7308 /* accquire the BT TRx retry count from BT_Info byte2 */
7309 retryCount = pHalData->bt_coexist.halCoex8723.btRetryCnt;
7310 RTPRINT(FBT, BT_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));
7314 if (retryCount == 0) { /* no retry in the last 2-second duration */
7321 if (up >= n) { /* if ³sÄò n Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration */
7327 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
7329 } else if (retryCount <= 3) { /* <= 3 retry in the last 2-second duration */
7336 if (dn == 2) { /* if ³sÄò 2 Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration */
7338 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7342 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7350 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
7352 } else { /* retry count > 3, ¥un1¦¸ retry count > 3, «h½Õ¯¶WiFi duration */
7354 m++; /* ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^ */
7358 if (m >= 20) /* m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration. */
7365 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
7368 RTPRINT(FBT, BT_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));
7369 if (maxInterval == 1) {
7371 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7372 if (pBtdm8723->curPsTdma == 1) {
7373 btdm_2AntPsTdma(padapter, true, 5);
7374 pBtdm8723->psTdmaDuAdjType = 5;
7375 } else if (pBtdm8723->curPsTdma == 2) {
7376 btdm_2AntPsTdma(padapter, true, 6);
7377 pBtdm8723->psTdmaDuAdjType = 6;
7378 } else if (pBtdm8723->curPsTdma == 3) {
7379 btdm_2AntPsTdma(padapter, true, 7);
7380 pBtdm8723->psTdmaDuAdjType = 7;
7381 } else if (pBtdm8723->curPsTdma == 4) {
7382 btdm_2AntPsTdma(padapter, true, 8);
7383 pBtdm8723->psTdmaDuAdjType = 8;
7385 if (pBtdm8723->curPsTdma == 9) {
7386 btdm_2AntPsTdma(padapter, true, 13);
7387 pBtdm8723->psTdmaDuAdjType = 13;
7388 } else if (pBtdm8723->curPsTdma == 10) {
7389 btdm_2AntPsTdma(padapter, true, 14);
7390 pBtdm8723->psTdmaDuAdjType = 14;
7391 } else if (pBtdm8723->curPsTdma == 11) {
7392 btdm_2AntPsTdma(padapter, true, 15);
7393 pBtdm8723->psTdmaDuAdjType = 15;
7394 } else if (pBtdm8723->curPsTdma == 12) {
7395 btdm_2AntPsTdma(padapter, true, 16);
7396 pBtdm8723->psTdmaDuAdjType = 16;
7400 if (pBtdm8723->curPsTdma == 5) {
7401 btdm_2AntPsTdma(padapter, true, 6);
7402 pBtdm8723->psTdmaDuAdjType = 6;
7403 } else if (pBtdm8723->curPsTdma == 6) {
7404 btdm_2AntPsTdma(padapter, true, 7);
7405 pBtdm8723->psTdmaDuAdjType = 7;
7406 } else if (pBtdm8723->curPsTdma == 7) {
7407 btdm_2AntPsTdma(padapter, true, 8);
7408 pBtdm8723->psTdmaDuAdjType = 8;
7409 } else if (pBtdm8723->curPsTdma == 13) {
7410 btdm_2AntPsTdma(padapter, true, 14);
7411 pBtdm8723->psTdmaDuAdjType = 14;
7412 } else if (pBtdm8723->curPsTdma == 14) {
7413 btdm_2AntPsTdma(padapter, true, 15);
7414 pBtdm8723->psTdmaDuAdjType = 15;
7415 } else if (pBtdm8723->curPsTdma == 15) {
7416 btdm_2AntPsTdma(padapter, true, 16);
7417 pBtdm8723->psTdmaDuAdjType = 16;
7419 } else if (result == 1) {
7420 if (pBtdm8723->curPsTdma == 8) {
7421 btdm_2AntPsTdma(padapter, true, 7);
7422 pBtdm8723->psTdmaDuAdjType = 7;
7423 } else if (pBtdm8723->curPsTdma == 7) {
7424 btdm_2AntPsTdma(padapter, true, 6);
7425 pBtdm8723->psTdmaDuAdjType = 6;
7426 } else if (pBtdm8723->curPsTdma == 6) {
7427 btdm_2AntPsTdma(padapter, true, 5);
7428 pBtdm8723->psTdmaDuAdjType = 5;
7429 } else if (pBtdm8723->curPsTdma == 16) {
7430 btdm_2AntPsTdma(padapter, true, 15);
7431 pBtdm8723->psTdmaDuAdjType = 15;
7432 } else if (pBtdm8723->curPsTdma == 15) {
7433 btdm_2AntPsTdma(padapter, true, 14);
7434 pBtdm8723->psTdmaDuAdjType = 14;
7435 } else if (pBtdm8723->curPsTdma == 14) {
7436 btdm_2AntPsTdma(padapter, true, 13);
7437 pBtdm8723->psTdmaDuAdjType = 13;
7441 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7442 if (pBtdm8723->curPsTdma == 5) {
7443 btdm_2AntPsTdma(padapter, true, 1);
7444 pBtdm8723->psTdmaDuAdjType = 1;
7445 } else if (pBtdm8723->curPsTdma == 6) {
7446 btdm_2AntPsTdma(padapter, true, 2);
7447 pBtdm8723->psTdmaDuAdjType = 2;
7448 } else if (pBtdm8723->curPsTdma == 7) {
7449 btdm_2AntPsTdma(padapter, true, 3);
7450 pBtdm8723->psTdmaDuAdjType = 3;
7451 } else if (pBtdm8723->curPsTdma == 8) {
7452 btdm_2AntPsTdma(padapter, true, 4);
7453 pBtdm8723->psTdmaDuAdjType = 4;
7455 if (pBtdm8723->curPsTdma == 13) {
7456 btdm_2AntPsTdma(padapter, true, 9);
7457 pBtdm8723->psTdmaDuAdjType = 9;
7458 } else if (pBtdm8723->curPsTdma == 14) {
7459 btdm_2AntPsTdma(padapter, true, 10);
7460 pBtdm8723->psTdmaDuAdjType = 10;
7461 } else if (pBtdm8723->curPsTdma == 15) {
7462 btdm_2AntPsTdma(padapter, true, 11);
7463 pBtdm8723->psTdmaDuAdjType = 11;
7464 } else if (pBtdm8723->curPsTdma == 16) {
7465 btdm_2AntPsTdma(padapter, true, 12);
7466 pBtdm8723->psTdmaDuAdjType = 12;
7470 if (pBtdm8723->curPsTdma == 1) {
7471 btdm_2AntPsTdma(padapter, true, 2);
7472 pBtdm8723->psTdmaDuAdjType = 2;
7473 } else if (pBtdm8723->curPsTdma == 2) {
7474 btdm_2AntPsTdma(padapter, true, 3);
7475 pBtdm8723->psTdmaDuAdjType = 3;
7476 } else if (pBtdm8723->curPsTdma == 3) {
7477 btdm_2AntPsTdma(padapter, true, 4);
7478 pBtdm8723->psTdmaDuAdjType = 4;
7479 } else if (pBtdm8723->curPsTdma == 9) {
7480 btdm_2AntPsTdma(padapter, true, 10);
7481 pBtdm8723->psTdmaDuAdjType = 10;
7482 } else if (pBtdm8723->curPsTdma == 10) {
7483 btdm_2AntPsTdma(padapter, true, 11);
7484 pBtdm8723->psTdmaDuAdjType = 11;
7485 } else if (pBtdm8723->curPsTdma == 11) {
7486 btdm_2AntPsTdma(padapter, true, 12);
7487 pBtdm8723->psTdmaDuAdjType = 12;
7489 } else if (result == 1) {
7490 if (pBtdm8723->curPsTdma == 4) {
7491 btdm_2AntPsTdma(padapter, true, 3);
7492 pBtdm8723->psTdmaDuAdjType = 3;
7493 } else if (pBtdm8723->curPsTdma == 3) {
7494 btdm_2AntPsTdma(padapter, true, 2);
7495 pBtdm8723->psTdmaDuAdjType = 2;
7496 } else if (pBtdm8723->curPsTdma == 2) {
7497 btdm_2AntPsTdma(padapter, true, 1);
7498 pBtdm8723->psTdmaDuAdjType = 1;
7499 } else if (pBtdm8723->curPsTdma == 12) {
7500 btdm_2AntPsTdma(padapter, true, 11);
7501 pBtdm8723->psTdmaDuAdjType = 11;
7502 } else if (pBtdm8723->curPsTdma == 11) {
7503 btdm_2AntPsTdma(padapter, true, 10);
7504 pBtdm8723->psTdmaDuAdjType = 10;
7505 } else if (pBtdm8723->curPsTdma == 10) {
7506 btdm_2AntPsTdma(padapter, true, 9);
7507 pBtdm8723->psTdmaDuAdjType = 9;
7511 } else if (maxInterval == 2) {
7513 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7514 if (pBtdm8723->curPsTdma == 1) {
7515 btdm_2AntPsTdma(padapter, true, 6);
7516 pBtdm8723->psTdmaDuAdjType = 6;
7517 } else if (pBtdm8723->curPsTdma == 2) {
7518 btdm_2AntPsTdma(padapter, true, 6);
7519 pBtdm8723->psTdmaDuAdjType = 6;
7520 } else if (pBtdm8723->curPsTdma == 3) {
7521 btdm_2AntPsTdma(padapter, true, 7);
7522 pBtdm8723->psTdmaDuAdjType = 7;
7523 } else if (pBtdm8723->curPsTdma == 4) {
7524 btdm_2AntPsTdma(padapter, true, 8);
7525 pBtdm8723->psTdmaDuAdjType = 8;
7527 if (pBtdm8723->curPsTdma == 9) {
7528 btdm_2AntPsTdma(padapter, true, 14);
7529 pBtdm8723->psTdmaDuAdjType = 14;
7530 } else if (pBtdm8723->curPsTdma == 10) {
7531 btdm_2AntPsTdma(padapter, true, 14);
7532 pBtdm8723->psTdmaDuAdjType = 14;
7533 } else if (pBtdm8723->curPsTdma == 11) {
7534 btdm_2AntPsTdma(padapter, true, 15);
7535 pBtdm8723->psTdmaDuAdjType = 15;
7536 } else if (pBtdm8723->curPsTdma == 12) {
7537 btdm_2AntPsTdma(padapter, true, 16);
7538 pBtdm8723->psTdmaDuAdjType = 16;
7541 if (pBtdm8723->curPsTdma == 5) {
7542 btdm_2AntPsTdma(padapter, true, 6);
7543 pBtdm8723->psTdmaDuAdjType = 6;
7544 } else if (pBtdm8723->curPsTdma == 6) {
7545 btdm_2AntPsTdma(padapter, true, 7);
7546 pBtdm8723->psTdmaDuAdjType = 7;
7547 } else if (pBtdm8723->curPsTdma == 7) {
7548 btdm_2AntPsTdma(padapter, true, 8);
7549 pBtdm8723->psTdmaDuAdjType = 8;
7550 } else if (pBtdm8723->curPsTdma == 13) {
7551 btdm_2AntPsTdma(padapter, true, 14);
7552 pBtdm8723->psTdmaDuAdjType = 14;
7553 } else if (pBtdm8723->curPsTdma == 14) {
7554 btdm_2AntPsTdma(padapter, true, 15);
7555 pBtdm8723->psTdmaDuAdjType = 15;
7556 } else if (pBtdm8723->curPsTdma == 15) {
7557 btdm_2AntPsTdma(padapter, true, 16);
7558 pBtdm8723->psTdmaDuAdjType = 16;
7560 } else if (result == 1) {
7561 if (pBtdm8723->curPsTdma == 8) {
7562 btdm_2AntPsTdma(padapter, true, 7);
7563 pBtdm8723->psTdmaDuAdjType = 7;
7564 } else if (pBtdm8723->curPsTdma == 7) {
7565 btdm_2AntPsTdma(padapter, true, 6);
7566 pBtdm8723->psTdmaDuAdjType = 6;
7567 } else if (pBtdm8723->curPsTdma == 6) {
7568 btdm_2AntPsTdma(padapter, true, 6);
7569 pBtdm8723->psTdmaDuAdjType = 6;
7570 } else if (pBtdm8723->curPsTdma == 16) {
7571 btdm_2AntPsTdma(padapter, true, 15);
7572 pBtdm8723->psTdmaDuAdjType = 15;
7573 } else if (pBtdm8723->curPsTdma == 15) {
7574 btdm_2AntPsTdma(padapter, true, 14);
7575 pBtdm8723->psTdmaDuAdjType = 14;
7576 } else if (pBtdm8723->curPsTdma == 14) {
7577 btdm_2AntPsTdma(padapter, true, 14);
7578 pBtdm8723->psTdmaDuAdjType = 14;
7582 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7583 if (pBtdm8723->curPsTdma == 5) {
7584 btdm_2AntPsTdma(padapter, true, 2);
7585 pBtdm8723->psTdmaDuAdjType = 2;
7586 } else if (pBtdm8723->curPsTdma == 6) {
7587 btdm_2AntPsTdma(padapter, true, 2);
7588 pBtdm8723->psTdmaDuAdjType = 2;
7589 } else if (pBtdm8723->curPsTdma == 7) {
7590 btdm_2AntPsTdma(padapter, true, 3);
7591 pBtdm8723->psTdmaDuAdjType = 3;
7592 } else if (pBtdm8723->curPsTdma == 8) {
7593 btdm_2AntPsTdma(padapter, true, 4);
7594 pBtdm8723->psTdmaDuAdjType = 4;
7596 if (pBtdm8723->curPsTdma == 13) {
7597 btdm_2AntPsTdma(padapter, true, 10);
7598 pBtdm8723->psTdmaDuAdjType = 10;
7599 } else if (pBtdm8723->curPsTdma == 14) {
7600 btdm_2AntPsTdma(padapter, true, 10);
7601 pBtdm8723->psTdmaDuAdjType = 10;
7602 } else if (pBtdm8723->curPsTdma == 15) {
7603 btdm_2AntPsTdma(padapter, true, 11);
7604 pBtdm8723->psTdmaDuAdjType = 11;
7605 } else if (pBtdm8723->curPsTdma == 16) {
7606 btdm_2AntPsTdma(padapter, true, 12);
7607 pBtdm8723->psTdmaDuAdjType = 12;
7610 if (pBtdm8723->curPsTdma == 1) {
7611 btdm_2AntPsTdma(padapter, true, 2);
7612 pBtdm8723->psTdmaDuAdjType = 2;
7613 } else if (pBtdm8723->curPsTdma == 2) {
7614 btdm_2AntPsTdma(padapter, true, 3);
7615 pBtdm8723->psTdmaDuAdjType = 3;
7616 } else if (pBtdm8723->curPsTdma == 3) {
7617 btdm_2AntPsTdma(padapter, true, 4);
7618 pBtdm8723->psTdmaDuAdjType = 4;
7619 } else if (pBtdm8723->curPsTdma == 9) {
7620 btdm_2AntPsTdma(padapter, true, 10);
7621 pBtdm8723->psTdmaDuAdjType = 10;
7622 } else if (pBtdm8723->curPsTdma == 10) {
7623 btdm_2AntPsTdma(padapter, true, 11);
7624 pBtdm8723->psTdmaDuAdjType = 11;
7625 } else if (pBtdm8723->curPsTdma == 11) {
7626 btdm_2AntPsTdma(padapter, true, 12);
7627 pBtdm8723->psTdmaDuAdjType = 12;
7629 } else if (result == 1) {
7630 if (pBtdm8723->curPsTdma == 4) {
7631 btdm_2AntPsTdma(padapter, true, 3);
7632 pBtdm8723->psTdmaDuAdjType = 3;
7633 } else if (pBtdm8723->curPsTdma == 3) {
7634 btdm_2AntPsTdma(padapter, true, 2);
7635 pBtdm8723->psTdmaDuAdjType = 2;
7636 } else if (pBtdm8723->curPsTdma == 2) {
7637 btdm_2AntPsTdma(padapter, true, 2);
7638 pBtdm8723->psTdmaDuAdjType = 2;
7639 } else if (pBtdm8723->curPsTdma == 12) {
7640 btdm_2AntPsTdma(padapter, true, 11);
7641 pBtdm8723->psTdmaDuAdjType = 11;
7642 } else if (pBtdm8723->curPsTdma == 11) {
7643 btdm_2AntPsTdma(padapter, true, 10);
7644 pBtdm8723->psTdmaDuAdjType = 10;
7645 } else if (pBtdm8723->curPsTdma == 10) {
7646 btdm_2AntPsTdma(padapter, true, 10);
7647 pBtdm8723->psTdmaDuAdjType = 10;
7651 } else if (maxInterval == 3) {
7653 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 1\n"));
7654 if (pBtdm8723->curPsTdma == 1) {
7655 btdm_2AntPsTdma(padapter, true, 7);
7656 pBtdm8723->psTdmaDuAdjType = 7;
7657 } else if (pBtdm8723->curPsTdma == 2) {
7658 btdm_2AntPsTdma(padapter, true, 7);
7659 pBtdm8723->psTdmaDuAdjType = 7;
7660 } else if (pBtdm8723->curPsTdma == 3) {
7661 btdm_2AntPsTdma(padapter, true, 7);
7662 pBtdm8723->psTdmaDuAdjType = 7;
7663 } else if (pBtdm8723->curPsTdma == 4) {
7664 btdm_2AntPsTdma(padapter, true, 8);
7665 pBtdm8723->psTdmaDuAdjType = 8;
7667 if (pBtdm8723->curPsTdma == 9) {
7668 btdm_2AntPsTdma(padapter, true, 15);
7669 pBtdm8723->psTdmaDuAdjType = 15;
7670 } else if (pBtdm8723->curPsTdma == 10) {
7671 btdm_2AntPsTdma(padapter, true, 15);
7672 pBtdm8723->psTdmaDuAdjType = 15;
7673 } else if (pBtdm8723->curPsTdma == 11) {
7674 btdm_2AntPsTdma(padapter, true, 15);
7675 pBtdm8723->psTdmaDuAdjType = 15;
7676 } else if (pBtdm8723->curPsTdma == 12) {
7677 btdm_2AntPsTdma(padapter, true, 16);
7678 pBtdm8723->psTdmaDuAdjType = 16;
7681 if (pBtdm8723->curPsTdma == 5) {
7682 btdm_2AntPsTdma(padapter, true, 7);
7683 pBtdm8723->psTdmaDuAdjType = 7;
7684 } else if (pBtdm8723->curPsTdma == 6) {
7685 btdm_2AntPsTdma(padapter, true, 7);
7686 pBtdm8723->psTdmaDuAdjType = 7;
7687 } else if (pBtdm8723->curPsTdma == 7) {
7688 btdm_2AntPsTdma(padapter, true, 8);
7689 pBtdm8723->psTdmaDuAdjType = 8;
7690 } else if (pBtdm8723->curPsTdma == 13) {
7691 btdm_2AntPsTdma(padapter, true, 15);
7692 pBtdm8723->psTdmaDuAdjType = 15;
7693 } else if (pBtdm8723->curPsTdma == 14) {
7694 btdm_2AntPsTdma(padapter, true, 15);
7695 pBtdm8723->psTdmaDuAdjType = 15;
7696 } else if (pBtdm8723->curPsTdma == 15) {
7697 btdm_2AntPsTdma(padapter, true, 16);
7698 pBtdm8723->psTdmaDuAdjType = 16;
7700 } else if (result == 1) {
7701 if (pBtdm8723->curPsTdma == 8) {
7702 btdm_2AntPsTdma(padapter, true, 7);
7703 pBtdm8723->psTdmaDuAdjType = 7;
7704 } else if (pBtdm8723->curPsTdma == 7) {
7705 btdm_2AntPsTdma(padapter, true, 7);
7706 pBtdm8723->psTdmaDuAdjType = 7;
7707 } else if (pBtdm8723->curPsTdma == 6) {
7708 btdm_2AntPsTdma(padapter, true, 7);
7709 pBtdm8723->psTdmaDuAdjType = 7;
7710 } else if (pBtdm8723->curPsTdma == 16) {
7711 btdm_2AntPsTdma(padapter, true, 15);
7712 pBtdm8723->psTdmaDuAdjType = 15;
7713 } else if (pBtdm8723->curPsTdma == 15) {
7714 btdm_2AntPsTdma(padapter, true, 15);
7715 pBtdm8723->psTdmaDuAdjType = 15;
7716 } else if (pBtdm8723->curPsTdma == 14) {
7717 btdm_2AntPsTdma(padapter, true, 15);
7718 pBtdm8723->psTdmaDuAdjType = 15;
7722 RTPRINT(FBT, BT_TRACE, ("[BTCoex], TxPause = 0\n"));
7723 if (pBtdm8723->curPsTdma == 5) {
7724 btdm_2AntPsTdma(padapter, true, 3);
7725 pBtdm8723->psTdmaDuAdjType = 3;
7726 } else if (pBtdm8723->curPsTdma == 6) {
7727 btdm_2AntPsTdma(padapter, true, 3);
7728 pBtdm8723->psTdmaDuAdjType = 3;
7729 } else if (pBtdm8723->curPsTdma == 7) {
7730 btdm_2AntPsTdma(padapter, true, 3);
7731 pBtdm8723->psTdmaDuAdjType = 3;
7732 } else if (pBtdm8723->curPsTdma == 8) {
7733 btdm_2AntPsTdma(padapter, true, 4);
7734 pBtdm8723->psTdmaDuAdjType = 4;
7736 if (pBtdm8723->curPsTdma == 13) {
7737 btdm_2AntPsTdma(padapter, true, 11);
7738 pBtdm8723->psTdmaDuAdjType = 11;
7739 } else if (pBtdm8723->curPsTdma == 14) {
7740 btdm_2AntPsTdma(padapter, true, 11);
7741 pBtdm8723->psTdmaDuAdjType = 11;
7742 } else if (pBtdm8723->curPsTdma == 15) {
7743 btdm_2AntPsTdma(padapter, true, 11);
7744 pBtdm8723->psTdmaDuAdjType = 11;
7745 } else if (pBtdm8723->curPsTdma == 16) {
7746 btdm_2AntPsTdma(padapter, true, 12);
7747 pBtdm8723->psTdmaDuAdjType = 12;
7750 if (pBtdm8723->curPsTdma == 1) {
7751 btdm_2AntPsTdma(padapter, true, 3);
7752 pBtdm8723->psTdmaDuAdjType = 3;
7753 } else if (pBtdm8723->curPsTdma == 2) {
7754 btdm_2AntPsTdma(padapter, true, 3);
7755 pBtdm8723->psTdmaDuAdjType = 3;
7756 } else if (pBtdm8723->curPsTdma == 3) {
7757 btdm_2AntPsTdma(padapter, true, 4);
7758 pBtdm8723->psTdmaDuAdjType = 4;
7759 } else if (pBtdm8723->curPsTdma == 9) {
7760 btdm_2AntPsTdma(padapter, true, 11);
7761 pBtdm8723->psTdmaDuAdjType = 11;
7762 } else if (pBtdm8723->curPsTdma == 10) {
7763 btdm_2AntPsTdma(padapter, true, 11);
7764 pBtdm8723->psTdmaDuAdjType = 11;
7765 } else if (pBtdm8723->curPsTdma == 11) {
7766 btdm_2AntPsTdma(padapter, true, 12);
7767 pBtdm8723->psTdmaDuAdjType = 12;
7769 } else if (result == 1) {
7770 if (pBtdm8723->curPsTdma == 4) {
7771 btdm_2AntPsTdma(padapter, true, 3);
7772 pBtdm8723->psTdmaDuAdjType = 3;
7773 } else if (pBtdm8723->curPsTdma == 3) {
7774 btdm_2AntPsTdma(padapter, true, 3);
7775 pBtdm8723->psTdmaDuAdjType = 3;
7776 } else if (pBtdm8723->curPsTdma == 2) {
7777 btdm_2AntPsTdma(padapter, true, 3);
7778 pBtdm8723->psTdmaDuAdjType = 3;
7779 } else if (pBtdm8723->curPsTdma == 12) {
7780 btdm_2AntPsTdma(padapter, true, 11);
7781 pBtdm8723->psTdmaDuAdjType = 11;
7782 } else if (pBtdm8723->curPsTdma == 11) {
7783 btdm_2AntPsTdma(padapter, true, 11);
7784 pBtdm8723->psTdmaDuAdjType = 11;
7785 } else if (pBtdm8723->curPsTdma == 10) {
7786 btdm_2AntPsTdma(padapter, true, 11);
7787 pBtdm8723->psTdmaDuAdjType = 11;
7793 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type : recordPsTdma =%d\n", pBtdm8723->psTdmaDuAdjType));
7794 /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
7795 /* then we have to adjust it back to the previous record one. */
7796 if (pBtdm8723->curPsTdma != pBtdm8723->psTdmaDuAdjType) {
7797 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma =%d, recordPsTdma =%d\n",
7798 pBtdm8723->curPsTdma, pBtdm8723->psTdmaDuAdjType));
7800 if (!check_fwstate(&padapter->mlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
7801 btdm_2AntPsTdma(padapter, true, pBtdm8723->psTdmaDuAdjType);
7803 RTPRINT(FBT, BT_TRACE, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
7807 /* default Action */
7808 /* SCO only or SCO+PAN(HS) */
7809 static void btdm_2Ant8723ASCOAction(struct rtw_adapter *padapter)
7811 u8 btRssiState, btRssiState1;
7813 if (btdm_NeedToDecBtPwr(padapter))
7814 btdm_2AntDecBtPwr(padapter, true);
7816 btdm_2AntDecBtPwr(padapter, false);
7818 if (BTDM_IsHT40(padapter)) {
7819 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7820 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7822 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7823 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7824 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7825 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7826 btdm_2AntPsTdma(padapter, true, 11);
7828 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7829 btdm_2AntPsTdma(padapter, true, 15);
7833 btdm_2AntAgcTable(padapter, false);
7834 btdm_2AntAdcBackOff(padapter, true);
7835 btdm_2AntDacSwing(padapter, false, 0xc0);
7837 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7838 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7839 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7842 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7843 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7844 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7845 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7846 btdm_2AntPsTdma(padapter, true, 11);
7848 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7849 btdm_2AntPsTdma(padapter, true, 15);
7853 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7854 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7855 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7856 btdm_2AntAgcTable(padapter, true);
7857 btdm_2AntAdcBackOff(padapter, true);
7858 btdm_2AntDacSwing(padapter, false, 0xc0);
7860 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7861 btdm_2AntAgcTable(padapter, false);
7862 btdm_2AntAdcBackOff(padapter, false);
7863 btdm_2AntDacSwing(padapter, false, 0xc0);
7868 static void btdm_2Ant8723AHIDAction(struct rtw_adapter *padapter)
7870 u8 btRssiState, btRssiState1;
7872 if (btdm_NeedToDecBtPwr(padapter))
7873 btdm_2AntDecBtPwr(padapter, true);
7875 btdm_2AntDecBtPwr(padapter, false);
7877 if (BTDM_IsHT40(padapter)) {
7878 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7879 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7881 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7882 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7883 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7884 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7885 btdm_2AntPsTdma(padapter, true, 9);
7887 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7888 btdm_2AntPsTdma(padapter, true, 13);
7892 btdm_2AntAgcTable(padapter, false);
7893 btdm_2AntAdcBackOff(padapter, false);
7894 btdm_2AntDacSwing(padapter, false, 0xc0);
7896 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7897 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7898 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7901 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7902 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7903 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7904 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7905 btdm_2AntPsTdma(padapter, true, 9);
7907 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7908 btdm_2AntPsTdma(padapter, true, 13);
7912 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7913 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7914 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7915 btdm_2AntAgcTable(padapter, true);
7916 btdm_2AntAdcBackOff(padapter, true);
7917 btdm_2AntDacSwing(padapter, false, 0xc0);
7919 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7920 btdm_2AntAgcTable(padapter, false);
7921 btdm_2AntAdcBackOff(padapter, false);
7922 btdm_2AntDacSwing(padapter, false, 0xc0);
7927 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
7928 static void btdm_2Ant8723AA2DPAction(struct rtw_adapter *padapter)
7930 u8 btRssiState, btRssiState1;
7931 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
7932 u8 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
7934 if (btdm_NeedToDecBtPwr(padapter))
7935 btdm_2AntDecBtPwr(padapter, true);
7937 btdm_2AntDecBtPwr(padapter, false);
7939 if (BTDM_IsHT40(padapter)) {
7940 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
7941 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7944 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
7945 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
7946 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
7947 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7949 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7950 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7951 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
7953 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7954 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
7957 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
7958 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7959 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7960 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
7962 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7963 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
7968 btdm_2AntAgcTable(padapter, false);
7969 btdm_2AntAdcBackOff(padapter, true);
7970 btdm_2AntDacSwing(padapter, false, 0xc0);
7972 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
7973 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
7974 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
7977 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
7978 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
7979 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
7980 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
7981 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7982 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7983 btdm_2AntTdmaDurationAdjust(padapter, false, false, 3);
7985 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7986 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
7989 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
7990 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
7991 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
7992 btdm_2AntTdmaDurationAdjust(padapter, false, true, 3);
7994 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
7995 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8000 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8001 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8002 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8003 btdm_2AntAgcTable(padapter, true);
8004 btdm_2AntAdcBackOff(padapter, true);
8005 btdm_2AntDacSwing(padapter, false, 0xc0);
8007 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8008 btdm_2AntAgcTable(padapter, false);
8009 btdm_2AntAdcBackOff(padapter, false);
8010 btdm_2AntDacSwing(padapter, false, 0xc0);
8015 static void btdm_2Ant8723APANEDRAction(struct rtw_adapter *padapter)
8017 u8 btRssiState, btRssiState1;
8019 if (btdm_NeedToDecBtPwr(padapter))
8020 btdm_2AntDecBtPwr(padapter, true);
8022 btdm_2AntDecBtPwr(padapter, false);
8024 if (BTDM_IsHT40(padapter)) {
8025 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8026 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8029 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8030 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8031 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8032 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8033 btdm_2AntPsTdma(padapter, true, 2);
8035 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8036 btdm_2AntPsTdma(padapter, true, 6);
8040 btdm_2AntAgcTable(padapter, false);
8041 btdm_2AntAdcBackOff(padapter, true);
8042 btdm_2AntDacSwing(padapter, false, 0xc0);
8044 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8045 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8046 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8049 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8050 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8051 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8052 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8053 btdm_2AntPsTdma(padapter, true, 2);
8055 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8056 btdm_2AntPsTdma(padapter, true, 6);
8060 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8061 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8062 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8063 btdm_2AntAgcTable(padapter, true);
8064 btdm_2AntAdcBackOff(padapter, true);
8065 btdm_2AntDacSwing(padapter, false, 0xc0);
8067 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8068 btdm_2AntAgcTable(padapter, false);
8069 btdm_2AntAdcBackOff(padapter, false);
8070 btdm_2AntDacSwing(padapter, false, 0xc0);
8076 static void btdm_2Ant8723APANHSAction(struct rtw_adapter *padapter)
8080 if (BTDM_IsHT40(padapter)) {
8081 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8082 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8084 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8085 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8086 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8087 btdm_2AntDecBtPwr(padapter, true);
8089 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8090 btdm_2AntDecBtPwr(padapter, false);
8092 btdm_2AntPsTdma(padapter, false, 0);
8095 btdm_2AntAgcTable(padapter, false);
8096 btdm_2AntAdcBackOff(padapter, true);
8097 btdm_2AntDacSwing(padapter, false, 0xc0);
8099 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8100 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8102 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8103 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8104 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high\n"));
8106 btdm_2AntDecBtPwr(padapter, true);
8107 btdm_2AntPsTdma(padapter, false, 0);
8110 btdm_2AntAgcTable(padapter, true);
8111 btdm_2AntAdcBackOff(padapter, true);
8112 btdm_2AntDacSwing(padapter, false, 0xc0);
8114 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low\n"));
8116 btdm_2AntDecBtPwr(padapter, false);
8117 btdm_2AntPsTdma(padapter, false, 0);
8120 btdm_2AntAgcTable(padapter, false);
8121 btdm_2AntAdcBackOff(padapter, false);
8122 btdm_2AntDacSwing(padapter, false, 0xc0);
8128 static void btdm_2Ant8723APANEDRA2DPAction(struct rtw_adapter *padapter)
8130 u8 btRssiState, btRssiState1, btInfoExt;
8131 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8133 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8135 if (btdm_NeedToDecBtPwr(padapter))
8136 btdm_2AntDecBtPwr(padapter, true);
8138 btdm_2AntDecBtPwr(padapter, false);
8140 if (BTDM_IsHT40(padapter)) {
8141 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8142 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8144 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8145 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8146 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8148 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8150 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8151 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8152 btdm_2AntPsTdma(padapter, true, 4);
8154 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8155 btdm_2AntPsTdma(padapter, true, 2);
8158 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8160 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8161 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8162 btdm_2AntPsTdma(padapter, true, 8);
8164 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8165 btdm_2AntPsTdma(padapter, true, 6);
8170 btdm_2AntAgcTable(padapter, false);
8171 btdm_2AntAdcBackOff(padapter, true);
8172 btdm_2AntDacSwing(padapter, false, 0xc0);
8174 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8175 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8176 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8178 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8179 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8180 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8181 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8183 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8184 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8185 btdm_2AntPsTdma(padapter, true, 4);
8187 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8188 btdm_2AntPsTdma(padapter, true, 2);
8191 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8193 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8194 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8195 btdm_2AntPsTdma(padapter, true, 8);
8197 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8198 btdm_2AntPsTdma(padapter, true, 6);
8203 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8204 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8205 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8206 btdm_2AntAgcTable(padapter, true);
8207 btdm_2AntAdcBackOff(padapter, true);
8208 btdm_2AntDacSwing(padapter, false, 0xc0);
8210 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8211 btdm_2AntAgcTable(padapter, false);
8212 btdm_2AntAdcBackOff(padapter, false);
8213 btdm_2AntDacSwing(padapter, false, 0xc0);
8218 static void btdm_2Ant8723APANEDRHIDAction(struct rtw_adapter *padapter)
8220 u8 btRssiState, btRssiState1;
8222 if (btdm_NeedToDecBtPwr(padapter))
8223 btdm_2AntDecBtPwr(padapter, true);
8225 btdm_2AntDecBtPwr(padapter, false);
8227 if (BTDM_IsHT40(padapter)) {
8228 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8229 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8231 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8232 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8233 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8234 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8235 btdm_2AntPsTdma(padapter, true, 10);
8237 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8238 btdm_2AntPsTdma(padapter, true, 14);
8242 btdm_2AntAgcTable(padapter, false);
8243 btdm_2AntAdcBackOff(padapter, true);
8244 btdm_2AntDacSwing(padapter, false, 0xc0);
8246 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8247 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8248 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8251 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8252 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8253 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8254 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8255 btdm_2AntPsTdma(padapter, true, 10);
8257 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8258 btdm_2AntPsTdma(padapter, true, 14);
8262 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8263 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8264 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8265 btdm_2AntAgcTable(padapter, true);
8266 btdm_2AntAdcBackOff(padapter, true);
8267 btdm_2AntDacSwing(padapter, false, 0xc0);
8269 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8270 btdm_2AntAgcTable(padapter, false);
8271 btdm_2AntAdcBackOff(padapter, false);
8272 btdm_2AntDacSwing(padapter, false, 0xc0);
8277 /* HID+A2DP+PAN(EDR) */
8278 static void btdm_2Ant8723AHIDA2DPPANEDRAction(struct rtw_adapter *padapter)
8280 u8 btRssiState, btRssiState1, btInfoExt;
8281 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8283 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8285 if (btdm_NeedToDecBtPwr(padapter))
8286 btdm_2AntDecBtPwr(padapter, true);
8288 btdm_2AntDecBtPwr(padapter, false);
8290 if (BTDM_IsHT40(padapter)) {
8291 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8292 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8293 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8294 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8295 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8296 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8298 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8299 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8300 btdm_2AntPsTdma(padapter, true, 12);
8302 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8303 btdm_2AntPsTdma(padapter, true, 10);
8306 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8307 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8308 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8309 btdm_2AntPsTdma(padapter, true, 16);
8311 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8312 btdm_2AntPsTdma(padapter, true, 14);
8317 btdm_2AntAgcTable(padapter, false);
8318 btdm_2AntAdcBackOff(padapter, true);
8319 btdm_2AntDacSwing(padapter, false, 0xc0);
8321 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8322 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 37, 0);
8323 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8324 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8325 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8326 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8327 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8329 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8330 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8331 btdm_2AntPsTdma(padapter, true, 12);
8333 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8334 btdm_2AntPsTdma(padapter, true, 10);
8337 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8338 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8339 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8340 btdm_2AntPsTdma(padapter, true, 16);
8342 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8343 btdm_2AntPsTdma(padapter, true, 14);
8348 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8349 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8350 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8351 btdm_2AntAgcTable(padapter, true);
8352 btdm_2AntAdcBackOff(padapter, true);
8353 btdm_2AntDacSwing(padapter, false, 0xc0);
8355 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8356 btdm_2AntAgcTable(padapter, false);
8357 btdm_2AntAdcBackOff(padapter, false);
8358 btdm_2AntDacSwing(padapter, false, 0xc0);
8363 static void btdm_2Ant8723AHIDA2DPAction(struct rtw_adapter *padapter)
8365 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8366 u8 btRssiState, btRssiState1, btInfoExt;
8368 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8370 if (btdm_NeedToDecBtPwr(padapter))
8371 btdm_2AntDecBtPwr(padapter, true);
8373 btdm_2AntDecBtPwr(padapter, false);
8375 if (BTDM_IsHT40(padapter)) {
8376 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8377 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8378 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8379 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8380 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8381 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8383 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8384 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8385 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8387 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8388 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8391 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8392 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8393 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8394 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8396 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8397 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8401 btdm_2AntAgcTable(padapter, false);
8402 btdm_2AntAdcBackOff(padapter, true);
8403 btdm_2AntDacSwing(padapter, false, 0xc0);
8405 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8406 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8407 btRssiState1 = BTDM_CheckCoexRSSIState(padapter, 2, 27, 0);
8409 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8410 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8411 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8412 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8414 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8415 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8416 btdm_2AntTdmaDurationAdjust(padapter, true, false, 3);
8418 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8419 btdm_2AntTdmaDurationAdjust(padapter, true, false, 1);
8422 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8423 if (btInfoExt&BIT(0)) { /* a2dp rate, 1:basic /0:edr */
8424 RTPRINT(FBT, BT_TRACE, ("a2dp basic rate \n"));
8425 btdm_2AntTdmaDurationAdjust(padapter, true, true, 3);
8427 RTPRINT(FBT, BT_TRACE, ("a2dp edr rate \n"));
8428 btdm_2AntTdmaDurationAdjust(padapter, true, true, 1);
8431 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8432 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8433 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8435 btdm_2AntAgcTable(padapter, true);
8436 btdm_2AntAdcBackOff(padapter, true);
8437 btdm_2AntDacSwing(padapter, false, 0xc0);
8439 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8441 btdm_2AntAgcTable(padapter, false);
8442 btdm_2AntAdcBackOff(padapter, false);
8443 btdm_2AntDacSwing(padapter, false, 0xc0);
8448 static void btdm_2Ant8723AA2dp(struct rtw_adapter *padapter)
8450 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8451 u8 btRssiState, btRssiState1, btInfoExt;
8453 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
8455 if (btdm_NeedToDecBtPwr(padapter))
8456 btdm_2AntDecBtPwr(padapter, true);
8458 btdm_2AntDecBtPwr(padapter, false);
8460 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8461 btdm_2AntIgnoreWlanAct(padapter, false);
8463 if (BTDM_IsHT40(padapter)) {
8464 RTPRINT(FBT, BT_TRACE, ("HT40\n"));
8465 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 37, 0);
8467 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8468 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8469 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8470 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8471 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8473 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8474 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8478 btdm_2AntAgcTable(padapter, false);
8479 btdm_2AntAdcBackOff(padapter, true);
8480 btdm_2AntDacSwing(padapter, false, 0xc0);
8482 RTPRINT(FBT, BT_TRACE, ("HT20 or Legacy\n"));
8483 btRssiState = BTDM_CheckCoexRSSIState(padapter, 2, 47, 0);
8484 btRssiState1 = BTDM_CheckCoexRSSIState1(padapter, 2, 27, 0);
8487 if ((btRssiState1 == BT_RSSI_STATE_HIGH) ||
8488 (btRssiState1 == BT_RSSI_STATE_STAY_HIGH)) {
8489 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 high \n"));
8490 PlatformEFIOWrite1Byte(padapter, 0x883, 0x40);
8491 btdm_2AntTdmaDurationAdjust(padapter, false, false, 1);
8493 RTPRINT(FBT, BT_TRACE, ("Wifi rssi-1 low \n"));
8494 btdm_2AntTdmaDurationAdjust(padapter, false, true, 1);
8498 if ((btRssiState == BT_RSSI_STATE_HIGH) ||
8499 (btRssiState == BT_RSSI_STATE_STAY_HIGH)) {
8500 RTPRINT(FBT, BT_TRACE, ("Wifi rssi high \n"));
8501 btdm_2AntAgcTable(padapter, true);
8502 btdm_2AntAdcBackOff(padapter, true);
8503 btdm_2AntDacSwing(padapter, false, 0xc0);
8505 RTPRINT(FBT, BT_TRACE, ("Wifi rssi low \n"));
8506 btdm_2AntAgcTable(padapter, false);
8507 btdm_2AntAdcBackOff(padapter, false);
8508 btdm_2AntDacSwing(padapter, false, 0xc0);
8513 /* extern function start with BTDM_ */
8514 static void BTDM_2AntParaInit(struct rtw_adapter *padapter)
8517 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8518 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8520 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2Ant Parameter Init!!\n"));
8522 /* Enable counter statistics */
8523 rtw_write8(padapter, 0x76e, 0x4);
8524 rtw_write8(padapter, 0x778, 0x3);
8525 rtw_write8(padapter, 0x40, 0x20);
8527 /* force to reset coex mechanism */
8528 pBtdm8723->preVal0x6c0 = 0x0;
8529 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8531 pBtdm8723->bPrePsTdmaOn = true;
8532 btdm_2AntPsTdma(padapter, false, 0);
8534 pBtdm8723->preFwDacSwingLvl = 0x10;
8535 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8537 pBtdm8723->bPreDecBtPwr = true;
8538 btdm_2AntDecBtPwr(padapter, false);
8540 pBtdm8723->bPreAgcTableEn = true;
8541 btdm_2AntAgcTable(padapter, false);
8543 pBtdm8723->bPreAdcBackOff = true;
8544 btdm_2AntAdcBackOff(padapter, false);
8546 pBtdm8723->bPreLowPenaltyRa = true;
8547 btdm_2AntLowPenaltyRa(padapter, false);
8549 pBtdm8723->bPreRfRxLpfShrink = true;
8550 btdm_2AntRfShrink(padapter, false);
8552 pBtdm8723->bPreDacSwingOn = true;
8553 btdm_2AntDacSwing(padapter, false, 0xc0);
8555 pBtdm8723->bPreIgnoreWlanAct = true;
8556 btdm_2AntIgnoreWlanAct(padapter, false);
8559 static void BTDM_2AntHwCoexAllOff8723A(struct rtw_adapter *padapter)
8561 btdm_2AntCoexTable(padapter, 0x55555555, 0xffff, 0x3);
8564 static void BTDM_2AntFwCoexAllOff8723A(struct rtw_adapter *padapter)
8566 btdm_2AntIgnoreWlanAct(padapter, false);
8567 btdm_2AntPsTdma(padapter, false, 0);
8568 btdm_2AntFwDacSwingLvl(padapter, 0x20);
8569 btdm_2AntDecBtPwr(padapter, false);
8572 static void BTDM_2AntSwCoexAllOff8723A(struct rtw_adapter *padapter)
8574 btdm_2AntAgcTable(padapter, false);
8575 btdm_2AntAdcBackOff(padapter, false);
8576 btdm_2AntLowPenaltyRa(padapter, false);
8577 btdm_2AntRfShrink(padapter, false);
8578 btdm_2AntDacSwing(padapter, false, 0xc0);
8581 static void BTDM_2AntFwC2hBtInfo8723A(struct rtw_adapter *padapter)
8583 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8584 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8585 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8586 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8588 u8 algorithm = BT_2ANT_COEX_ALGO_UNDEFINED;
8589 u8 bBtLinkExist = false, bBtHsModeExist = false;
8591 btInfo = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8592 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8594 /* check BIT2 first ==> check if bt is under inquiry or page scan */
8595 if (btInfo & BIT(2)) {
8596 if (!pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage) {
8597 pBtMgnt->ExtConfig.bHoldForBtOperation = true;
8598 pBtMgnt->ExtConfig.bHoldPeriodCnt = 1;
8599 btdm_2AntBtInquiryPage(padapter);
8601 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8602 btdm_HoldForBtInqPage(padapter);
8604 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = true;
8607 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage = false;
8608 pBtMgnt->ExtConfig.bHoldForBtOperation = false;
8609 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8612 RTPRINT(FBT, BT_TRACE,
8613 ("[BTC2H], pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage =%x pBtMgnt->ExtConfig.bHoldPeriodCnt =%x pBtMgnt->ExtConfig.bHoldForBtOperation =%x\n",
8614 pHalData->bt_coexist.halCoex8723.bC2hBtInquiryPage,
8615 pBtMgnt->ExtConfig.bHoldPeriodCnt,
8616 pBtMgnt->ExtConfig.bHoldForBtOperation));
8618 RTPRINT(FBT, BT_TRACE,
8619 ("[BTC2H], btInfo =%x pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal =%x\n",
8620 btInfo, pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal));
8621 if (btInfo&BT_INFO_ACL) {
8622 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = true btInfo =%x\n", btInfo));
8623 bBtLinkExist = true;
8624 if (((btInfo&(BT_INFO_FTP|BT_INFO_A2DP|BT_INFO_HID|BT_INFO_SCO_BUSY)) != 0) ||
8625 pHalData->bt_coexist.halCoex8723.btRetryCnt > 0) {
8626 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_NON_IDLE;
8628 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_CONNECTED_IDLE;
8631 if (btInfo&BT_INFO_SCO || btInfo&BT_INFO_SCO_BUSY) {
8632 if (btInfo&BT_INFO_FTP || btInfo&BT_INFO_A2DP || btInfo&BT_INFO_HID) {
8633 switch (btInfo&0xe0) {
8635 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + HID\n"));
8636 algorithm = BT_2ANT_COEX_ALGO_HID;
8639 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Error!!! SCO + A2DP\n"));
8642 if (bBtHsModeExist) {
8643 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
8644 algorithm = BT_2ANT_COEX_ALGO_SCO;
8646 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
8647 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8650 case (BT_INFO_HID | BT_INFO_A2DP):
8651 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8652 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8654 case (BT_INFO_HID | BT_INFO_FTP):
8655 if (bBtHsModeExist) {
8656 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8657 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8659 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8660 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8663 case (BT_INFO_A2DP | BT_INFO_FTP):
8664 if (bBtHsModeExist) {
8665 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8666 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8668 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8669 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8672 case (BT_INFO_HID | BT_INFO_A2DP | BT_INFO_FTP):
8673 if (bBtHsModeExist) {
8674 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8675 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8677 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8678 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8683 RTPRINT(FBT, BT_TRACE, ("[BTCoex], SCO only\n"));
8684 algorithm = BT_2ANT_COEX_ALGO_SCO;
8687 RTPRINT(FBT, BT_TRACE, ("[BTCoex], non SCO\n"));
8688 switch (btInfo&0xe0) {
8690 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID\n"));
8691 algorithm = BT_2ANT_COEX_ALGO_HID;
8694 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP\n"));
8695 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8698 RTPRINT(FBT, BT_TRACE, ("[BTCoex], PAN(EDR)\n"));
8699 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8701 case (BT_INFO_HID | BT_INFO_A2DP):
8702 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP\n"));
8703 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8705 case (BT_INFO_HID|BT_INFO_FTP):
8706 if (bBtHsModeExist) {
8707 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
8708 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8710 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
8711 algorithm = BT_2ANT_COEX_ALGO_PANEDR_HID;
8714 case (BT_INFO_A2DP|BT_INFO_FTP):
8715 if (bBtHsModeExist) {
8716 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
8717 algorithm = BT_2ANT_COEX_ALGO_A2DP;
8719 RTPRINT(FBT, BT_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
8720 algorithm = BT_2ANT_COEX_ALGO_PANEDR_A2DP;
8723 case (BT_INFO_HID|BT_INFO_A2DP|BT_INFO_FTP):
8724 if (bBtHsModeExist) {
8725 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
8726 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP;
8728 RTPRINT(FBT, BT_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
8729 algorithm = BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
8736 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BTInfo: bConnect = false\n"));
8737 pBtdm8723->btStatus = BT_2ANT_BT_STATUS_IDLE;
8740 pBtdm8723->curAlgorithm = algorithm;
8741 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8744 BTDM_CheckWiFiState(padapter);
8745 if (pBtMgnt->ExtConfig.bManualControl) {
8746 RTPRINT(FBT, BT_TRACE, ("Action Manual control, won't execute bt coexist mechanism!!\n"));
8751 void BTDM_2AntBtCoexist8723A(struct rtw_adapter *padapter)
8753 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
8754 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
8755 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
8756 u8 btInfoOriginal = 0;
8757 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8758 struct btdm_8723a_2ant *pBtdm8723 = &pHalData->bt_coexist.halCoex8723.btdm2Ant;
8760 if (BTDM_BtProfileSupport(padapter)) {
8761 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8762 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8765 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8766 RTPRINT(FBT, BT_TRACE, ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8767 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8768 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8769 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8770 /* next time the coexist parameters should be reset again. */
8772 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8777 if (pBtDbg->dbgCtrl)
8778 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8780 pBtdm8723->curAlgorithm = btdm_ActionAlgorithm(padapter);
8781 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Algorithm = %d \n", pBtdm8723->curAlgorithm));
8783 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8784 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8785 pBtdm8723->bResetTdmaAdjust = true;
8787 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8788 RTPRINT(FBT, BT_TRACE, ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8789 pBtdm8723->preAlgorithm, pBtdm8723->curAlgorithm));
8790 pBtdm8723->bResetTdmaAdjust = true;
8792 switch (pBtdm8723->curAlgorithm) {
8793 case BT_2ANT_COEX_ALGO_SCO:
8794 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8795 btdm_2Ant8723ASCOAction(padapter);
8797 case BT_2ANT_COEX_ALGO_HID:
8798 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8799 btdm_2Ant8723AHIDAction(padapter);
8801 case BT_2ANT_COEX_ALGO_A2DP:
8802 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8803 btdm_2Ant8723AA2DPAction(padapter);
8805 case BT_2ANT_COEX_ALGO_PANEDR:
8806 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8807 btdm_2Ant8723APANEDRAction(padapter);
8809 case BT_2ANT_COEX_ALGO_PANHS:
8810 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8811 btdm_2Ant8723APANHSAction(padapter);
8813 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8814 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8815 btdm_2Ant8723APANEDRA2DPAction(padapter);
8817 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8818 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8819 btdm_2Ant8723APANEDRHIDAction(padapter);
8821 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8822 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8823 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8825 case BT_2ANT_COEX_ALGO_HID_A2DP:
8826 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8827 btdm_2Ant8723AHIDA2DPAction(padapter);
8830 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8831 btdm_2Ant8723AA2DPAction(padapter);
8834 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8837 RTPRINT(FBT, BT_TRACE, ("[BTCoex] Get bt info by fw!!\n"));
8838 /* msg shows c2h rsp for bt_info is received or not. */
8839 if (pHalData->bt_coexist.halCoex8723.bC2hBtInfoReqSent)
8840 RTPRINT(FBT, BT_TRACE, ("[BTCoex] c2h for btInfo not rcvd yet!!\n"));
8842 btInfoOriginal = pHalData->bt_coexist.halCoex8723.c2hBtInfoOriginal;
8844 if (pBtMgnt->ExtConfig.bHoldForBtOperation) {
8845 RTPRINT(FBT, BT_TRACE, ("Action for BT Operation adjust!!\n"));
8848 if (pBtMgnt->ExtConfig.bHoldPeriodCnt) {
8849 RTPRINT(FBT, BT_TRACE,
8850 ("Hold BT inquiry/page scan setting (cnt = %d)!!\n",
8851 pBtMgnt->ExtConfig.bHoldPeriodCnt));
8852 if (pBtMgnt->ExtConfig.bHoldPeriodCnt >= 11) {
8853 pBtMgnt->ExtConfig.bHoldPeriodCnt = 0;
8854 /* next time the coexist parameters should be reset again. */
8856 pBtMgnt->ExtConfig.bHoldPeriodCnt++;
8861 if (pBtDbg->dbgCtrl)
8862 RTPRINT(FBT, BT_TRACE, ("[Dbg control], "));
8863 if (btdm_Is2Ant8723ACommonAction(padapter)) {
8864 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant common.\n"));
8865 pBtdm8723->bResetTdmaAdjust = true;
8867 if (pBtdm8723->curAlgorithm != pBtdm8723->preAlgorithm) {
8868 RTPRINT(FBT, BT_TRACE,
8869 ("[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
8870 pBtdm8723->preAlgorithm,
8871 pBtdm8723->curAlgorithm));
8872 pBtdm8723->bResetTdmaAdjust = true;
8874 switch (pBtdm8723->curAlgorithm) {
8875 case BT_2ANT_COEX_ALGO_SCO:
8876 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = SCO.\n"));
8877 btdm_2Ant8723ASCOAction(padapter);
8879 case BT_2ANT_COEX_ALGO_HID:
8880 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID.\n"));
8881 btdm_2Ant8723AHIDAction(padapter);
8883 case BT_2ANT_COEX_ALGO_A2DP:
8884 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = A2DP.\n"));
8885 btdm_2Ant8723AA2dp(padapter);
8887 case BT_2ANT_COEX_ALGO_PANEDR:
8888 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR).\n"));
8889 btdm_2Ant8723APANEDRAction(padapter);
8891 case BT_2ANT_COEX_ALGO_PANHS:
8892 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HS mode.\n"));
8893 btdm_2Ant8723APANHSAction(padapter);
8895 case BT_2ANT_COEX_ALGO_PANEDR_A2DP:
8896 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN+A2DP.\n"));
8897 btdm_2Ant8723APANEDRA2DPAction(padapter);
8899 case BT_2ANT_COEX_ALGO_PANEDR_HID:
8900 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
8901 btdm_2Ant8723APANEDRHIDAction(padapter);
8903 case BT_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
8904 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
8905 btdm_2Ant8723AHIDA2DPPANEDRAction(padapter);
8907 case BT_2ANT_COEX_ALGO_HID_A2DP:
8908 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = HID+A2DP.\n"));
8909 btdm_2Ant8723AHIDA2DPAction(padapter);
8912 RTPRINT(FBT, BT_TRACE, ("Action 2-Ant, algorithm = 0.\n"));
8913 btdm_2Ant8723AA2DPAction(padapter);
8916 pBtdm8723->preAlgorithm = pBtdm8723->curAlgorithm;
8921 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc87232Ant.c ===== */
8924 #ifdef __HALBTC8723_C__ /* HAL/BTCoexist/HalBtc8723.c */
8925 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
8927 static u8 btCoexDbgBuf[BT_TMP_BUF_SIZE];
8929 static const char *const BtProfileString[] = {
8937 static const char *const BtSpecString[] = {
8947 static const char *const BtLinkRoleString[] = {
8952 static u8 btdm_BtWifiAntNum(struct rtw_adapter *padapter)
8954 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8955 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
8957 if (Ant_x2 == pHalData->bt_coexist.BT_Ant_Num) {
8958 if (Ant_x2 == pBtCoex->TotalAntNum)
8968 static void btdm_BtHwCountersMonitor(struct rtw_adapter *padapter)
8970 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
8971 u32 regHPTxRx, regLPTxRx, u4Tmp;
8972 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
8974 regHPTxRx = REG_HIGH_PRIORITY_TXRX;
8975 regLPTxRx = REG_LOW_PRIORITY_TXRX;
8977 u4Tmp = rtw_read32(padapter, regHPTxRx);
8978 regHPTx = u4Tmp & bMaskLWord;
8979 regHPRx = (u4Tmp & bMaskHWord)>>16;
8981 u4Tmp = rtw_read32(padapter, regLPTxRx);
8982 regLPTx = u4Tmp & bMaskLWord;
8983 regLPRx = (u4Tmp & bMaskHWord)>>16;
8985 pHalData->bt_coexist.halCoex8723.highPriorityTx = regHPTx;
8986 pHalData->bt_coexist.halCoex8723.highPriorityRx = regHPRx;
8987 pHalData->bt_coexist.halCoex8723.lowPriorityTx = regLPTx;
8988 pHalData->bt_coexist.halCoex8723.lowPriorityRx = regLPRx;
8990 RTPRINT(FBT, BT_TRACE, ("High Priority Tx/Rx = %d / %d\n", regHPTx, regHPRx));
8991 RTPRINT(FBT, BT_TRACE, ("Low Priority Tx/Rx = %d / %d\n", regLPTx, regLPRx));
8994 rtw_write8(padapter, 0x76e, 0xc);
8997 /* This function check if 8723 bt is disabled */
8998 static void btdm_BtEnableDisableCheck8723A(struct rtw_adapter *padapter)
9001 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9003 #ifdef CHECK_BT_EXIST_FROM_REG
9006 /* ox68[28]= 1 => BT enable; otherwise disable */
9007 val8 = rtw_read8(padapter, 0x6B);
9008 if (!(val8 & BIT(4)))
9012 pHalData->bt_coexist.bCurBtDisabled = false;
9014 pHalData->bt_coexist.bCurBtDisabled = true;
9016 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0 &&
9017 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0 &&
9018 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0 &&
9019 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0)
9021 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xeaea &&
9022 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xeaea &&
9023 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xeaea &&
9024 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xeaea)
9026 if (pHalData->bt_coexist.halCoex8723.highPriorityTx == 0xffff &&
9027 pHalData->bt_coexist.halCoex8723.highPriorityRx == 0xffff &&
9028 pHalData->bt_coexist.halCoex8723.lowPriorityTx == 0xffff &&
9029 pHalData->bt_coexist.halCoex8723.lowPriorityRx == 0xffff)
9032 pHalData->bt_coexist.btActiveZeroCnt = 0;
9033 pHalData->bt_coexist.bCurBtDisabled = false;
9034 RTPRINT(FBT, BT_TRACE, ("8723A BT is enabled !!\n"));
9036 pHalData->bt_coexist.btActiveZeroCnt++;
9037 RTPRINT(FBT, BT_TRACE, ("8723A bt all counters = 0, %d times!!\n",
9038 pHalData->bt_coexist.btActiveZeroCnt));
9039 if (pHalData->bt_coexist.btActiveZeroCnt >= 2) {
9040 pHalData->bt_coexist.bCurBtDisabled = true;
9041 RTPRINT(FBT, BT_TRACE, ("8723A BT is disabled !!\n"));
9046 if (!pHalData->bt_coexist.bCurBtDisabled) {
9047 if (BTDM_IsWifiConnectionExist(padapter))
9048 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_CONNECT);
9050 BTDM_SetFwChnlInfo(padapter, RT_MEDIA_DISCONNECT);
9053 if (pHalData->bt_coexist.bPreBtDisabled !=
9054 pHalData->bt_coexist.bCurBtDisabled) {
9055 RTPRINT(FBT, BT_TRACE, ("8723A BT is from %s to %s!!\n",
9056 (pHalData->bt_coexist.bPreBtDisabled ? "disabled":"enabled"),
9057 (pHalData->bt_coexist.bCurBtDisabled ? "disabled":"enabled")));
9058 pHalData->bt_coexist.bPreBtDisabled = pHalData->bt_coexist.bCurBtDisabled;
9062 static void btdm_BTCoexist8723AHandler(struct rtw_adapter *padapter)
9064 struct hal_data_8723a *pHalData;
9066 pHalData = GET_HAL_DATA(padapter);
9068 if (btdm_BtWifiAntNum(padapter) == Ant_x2) {
9069 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 2 Ant mechanism\n"));
9070 BTDM_2AntBtCoexist8723A(padapter);
9072 RTPRINT(FBT, BT_TRACE, ("[BTCoex], 1 Ant mechanism\n"));
9073 BTDM_1AntBtCoexist8723A(padapter);
9076 if (!BTDM_IsSameCoexistState(padapter)) {
9077 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x\n",
9078 pHalData->bt_coexist.PreviousState,
9079 pHalData->bt_coexist.CurrentState));
9080 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
9082 RTPRINT(FBT, BT_TRACE, ("["));
9083 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT30)
9084 RTPRINT(FBT, BT_TRACE, ("BT 3.0, "));
9085 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT20)
9086 RTPRINT(FBT, BT_TRACE, ("HT20, "));
9087 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_HT40)
9088 RTPRINT(FBT, BT_TRACE, ("HT40, "));
9089 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_LEGACY)
9090 RTPRINT(FBT, BT_TRACE, ("Legacy, "));
9091 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_LOW)
9092 RTPRINT(FBT, BT_TRACE, ("Rssi_Low, "));
9093 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_MEDIUM)
9094 RTPRINT(FBT, BT_TRACE, ("Rssi_Mid, "));
9095 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_RSSI_HIGH)
9096 RTPRINT(FBT, BT_TRACE, ("Rssi_High, "));
9097 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_IDLE)
9098 RTPRINT(FBT, BT_TRACE, ("Wifi_Idle, "));
9099 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_UPLINK)
9100 RTPRINT(FBT, BT_TRACE, ("Wifi_Uplink, "));
9101 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_WIFI_DOWNLINK)
9102 RTPRINT(FBT, BT_TRACE, ("Wifi_Downlink, "));
9103 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)
9104 RTPRINT(FBT, BT_TRACE, ("BT_idle, "));
9105 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_HID)
9106 RTPRINT(FBT, BT_TRACE, ("PRO_HID, "));
9107 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_A2DP)
9108 RTPRINT(FBT, BT_TRACE, ("PRO_A2DP, "));
9109 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_PAN)
9110 RTPRINT(FBT, BT_TRACE, ("PRO_PAN, "));
9111 if (pHalData->bt_coexist.CurrentState & BT_COEX_STATE_PROFILE_SCO)
9112 RTPRINT(FBT, BT_TRACE, ("PRO_SCO, "));
9113 RTPRINT(FBT, BT_TRACE, ("]\n"));
9117 /* extern function start with BTDM_ */
9118 u32 BTDM_BtTxRxCounterH(struct rtw_adapter *padapter)
9120 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9123 counters = pHalData->bt_coexist.halCoex8723.highPriorityTx+
9124 pHalData->bt_coexist.halCoex8723.highPriorityRx;
9128 u32 BTDM_BtTxRxCounterL(struct rtw_adapter *padapter)
9130 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9133 counters = pHalData->bt_coexist.halCoex8723.lowPriorityTx+
9134 pHalData->bt_coexist.halCoex8723.lowPriorityRx ;
9138 void BTDM_SetFwChnlInfo(struct rtw_adapter *padapter, enum rt_media_status mstatus)
9140 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
9141 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9142 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9143 u8 H2C_Parameter[3] = {0};
9147 if (RT_MEDIA_CONNECT == mstatus)
9148 H2C_Parameter[0] = 0x1; /* 0: disconnected, 1:connected */
9150 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE)) {
9152 chnl = pmlmeext->cur_channel;
9153 if (BTDM_IsHT40(padapter)) {
9154 if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_UPPER)
9156 else if (pmlmeext->cur_ch_offset == HAL_PRIME_CHNL_OFFSET_LOWER)
9159 H2C_Parameter[1] = chnl;
9160 } else { /* check if HS link is exists */
9162 if (BT_Operation(padapter))
9163 H2C_Parameter[1] = pBtMgnt->BTChannel;
9165 H2C_Parameter[1] = pmlmeext->cur_channel;
9168 if (BTDM_IsHT40(padapter))
9169 H2C_Parameter[2] = 0x30;
9171 H2C_Parameter[2] = 0x20;
9173 FillH2CCmd(padapter, 0x19, 3, H2C_Parameter);
9176 u8 BTDM_IsWifiConnectionExist(struct rtw_adapter *padapter)
9180 if (BTHCI_HsConnectionEstablished(padapter))
9183 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true)
9190 struct rtw_adapter *padapter,
9198 u8 H2C_Parameter[5] = {0};
9200 if (BTDM_1Ant8723A(padapter)) {
9201 if ((!check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE)) &&
9202 (get_fwstate(&padapter->mlmepriv) != WIFI_NULL_STATE)) {
9203 /* for softap mode */
9204 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9205 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9206 u8 BtState = pBtCoex->c2hBtInfo;
9208 if ((BtState != BT_INFO_STATE_NO_CONNECTION) &&
9209 (BtState != BT_INFO_STATE_CONNECT_IDLE)) {
9210 if (byte1 & BIT(4)) {
9222 H2C_Parameter[0] = byte1;
9223 H2C_Parameter[1] = byte2;
9224 H2C_Parameter[2] = byte3;
9225 H2C_Parameter[3] = byte4;
9226 H2C_Parameter[4] = byte5;
9228 RTPRINT(FBT, BT_TRACE, ("[BTCoex], FW write 0x3a(5bytes) = 0x%02x%08x\n",
9230 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
9232 FillH2CCmd(padapter, 0x3a, 5, H2C_Parameter);
9235 void BTDM_QueryBtInformation(struct rtw_adapter *padapter)
9237 u8 H2C_Parameter[1] = {0};
9238 struct hal_data_8723a *pHalData;
9239 struct bt_coexist_8723a *pBtCoex;
9241 pHalData = GET_HAL_DATA(padapter);
9242 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9244 if (BT_IsBtDisabled(padapter)) {
9245 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9246 pBtCoex->bC2hBtInfoReqSent = false;
9250 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9251 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9253 if (pBtCoex->bC2hBtInfoReqSent == true)
9254 RTPRINT(FBT, BT_TRACE, ("[BTCoex], didn't recv previous BtInfo report!\n"));
9256 pBtCoex->bC2hBtInfoReqSent = true;
9258 H2C_Parameter[0] |= BIT(0); /* trigger */
9260 /*RTPRINT(FBT, BT_TRACE, ("[BTCoex], Query Bt information, write 0x38 = 0x%x\n", */
9261 /*H2C_Parameter[0])); */
9263 FillH2CCmd(padapter, 0x38, 1, H2C_Parameter);
9266 void BTDM_SetSwRfRxLpfCorner(struct rtw_adapter *padapter, u8 type)
9268 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9270 if (BT_RF_RX_LPF_CORNER_SHRINK == type) {
9271 /* Shrink RF Rx LPF corner */
9272 RTPRINT(FBT, BT_TRACE, ("Shrink RF Rx LPF corner!!\n"));
9273 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, 0xf0ff7);
9274 pHalData->bt_coexist.bSWCoexistAllOff = false;
9275 } else if (BT_RF_RX_LPF_CORNER_RESUME == type) {
9276 /* Resume RF Rx LPF corner */
9277 RTPRINT(FBT, BT_TRACE, ("Resume RF Rx LPF corner!!\n"));
9278 PHY_SetRFReg(padapter, PathA, 0x1e, bRFRegOffsetMask, pHalData->bt_coexist.BtRfRegOrigin1E);
9283 BTDM_SetSwPenaltyTxRateAdaptive(
9284 struct rtw_adapter *padapter,
9288 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9291 tmpU1 = rtw_read8(padapter, 0x4fd);
9293 if (BT_TX_RATE_ADAPTIVE_LOW_PENALTY == raType) {
9295 pHalData->bt_coexist.bSWCoexistAllOff = false;
9296 } else if (BT_TX_RATE_ADAPTIVE_NORMAL == raType) {
9300 rtw_write8(padapter, 0x4fd, tmpU1);
9303 void BTDM_SetFwDecBtPwr(struct rtw_adapter *padapter, u8 bDecBtPwr)
9305 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9306 u8 H2C_Parameter[1] = {0};
9308 H2C_Parameter[0] = 0;
9311 H2C_Parameter[0] |= BIT(1);
9312 pHalData->bt_coexist.bFWCoexistAllOff = false;
9315 RTPRINT(FBT, BT_TRACE, ("[BTCoex], decrease Bt Power : %s, write 0x21 = 0x%x\n",
9316 (bDecBtPwr ? "Yes!!" : "No!!"), H2C_Parameter[0]));
9318 FillH2CCmd(padapter, 0x21, 1, H2C_Parameter);
9321 u8 BTDM_BtProfileSupport(struct rtw_adapter *padapter)
9324 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9325 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9326 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9328 if (pBtMgnt->bSupportProfile &&
9329 !pHalData->bt_coexist.halCoex8723.bForceFwBtInfo)
9335 static void BTDM_AdjustForBtOperation8723A(struct rtw_adapter *padapter)
9337 /* BTDM_2AntAdjustForBtOperation8723(padapter); */
9340 static void BTDM_FwC2hBtRssi8723A(struct rtw_adapter *padapter, u8 *tmpBuf)
9342 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9343 u8 percent = 0, u1tmp = 0;
9346 percent = u1tmp*2+10;
9348 pHalData->bt_coexist.halCoex8723.btRssi = percent;
9349 /*RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", percent)); */
9353 BTDM_FwC2hBtInfo8723A(struct rtw_adapter *padapter, u8 *tmpBuf, u8 length)
9355 struct hal_data_8723a *pHalData;
9356 struct bt_30info *pBTInfo;
9357 struct bt_mgnt *pBtMgnt;
9358 struct bt_coexist_8723a *pBtCoex;
9361 pHalData = GET_HAL_DATA(padapter);
9362 pBTInfo = GET_BT_INFO(padapter);
9363 pBtMgnt = &pBTInfo->BtMgnt;
9364 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9366 pBtCoex->bC2hBtInfoReqSent = false;
9368 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT info[%d]=[", length));
9370 pBtCoex->btRetryCnt = 0;
9371 for (i = 0; i < length; i++) {
9374 pBtCoex->c2hBtInfoOriginal = tmpBuf[i];
9377 pBtCoex->btRetryCnt = tmpBuf[i];
9380 BTDM_FwC2hBtRssi8723A(padapter, &tmpBuf[i]);
9383 pBtCoex->btInfoExt = tmpBuf[i]&BIT(0);
9388 RTPRINT(FBT, BT_TRACE, ("0x%02x]\n", tmpBuf[i]));
9390 RTPRINT(FBT, BT_TRACE, ("0x%02x, ", tmpBuf[i]));
9392 RTPRINT(FBT, BT_TRACE, ("[BTC2H], BT RSSI =%d\n", pBtCoex->btRssi));
9393 if (pBtCoex->btInfoExt)
9394 RTPRINT(FBT, BT_TRACE, ("[BTC2H], pBtCoex->btInfoExt =%x\n", pBtCoex->btInfoExt));
9396 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9397 BTDM_1AntFwC2hBtInfo8723A(padapter);
9399 BTDM_2AntFwC2hBtInfo8723A(padapter);
9401 if (pBtMgnt->ExtConfig.bManualControl) {
9402 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9406 btdm_BTCoexist8723AHandler(padapter);
9409 static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
9411 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9412 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9413 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9414 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9415 u8 u1Tmp, u1Tmp1, u1Tmp2, i, btInfoExt, psTdmaCase = 0;
9419 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
9420 DCMD_Printf(btCoexDbgBuf);
9422 if (!pHalData->bt_coexist.BluetoothCoexist) {
9423 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");
9424 DCMD_Printf(btCoexDbgBuf);
9428 antNum = btdm_BtWifiAntNum(padapter);
9429 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/%d ", "Ant mechanism PG/Now run :", \
9430 ((pHalData->bt_coexist.BT_Ant_Num == Ant_x2) ? 2 : 1), ((antNum == Ant_x2) ? 2 : 1));
9431 DCMD_Printf(btCoexDbgBuf);
9433 if (pBtMgnt->ExtConfig.bManualControl) {
9434 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
9435 DCMD_Printf(btCoexDbgBuf);
9437 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
9438 ((pBtMgnt->bSupportProfile) ? "Yes" : "No"), pBtMgnt->ExtConfig.HCIExtensionVer);
9439 DCMD_Printf(btCoexDbgBuf);
9442 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = / %d", "Dot11 channel / BT channel", \
9443 pBtMgnt->BTChannel);
9444 DCMD_Printf(btCoexDbgBuf);
9446 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %d / %d / %d", "Wifi/BT/HS rssi", \
9447 BTDM_GetRxSS(padapter),
9448 pHalData->bt_coexist.halCoex8723.btRssi,
9449 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB);
9450 DCMD_Printf(btCoexDbgBuf);
9452 if (!pBtMgnt->ExtConfig.bManualControl) {
9453 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %s / %s ", "WIfi status",
9454 ((BTDM_Legacy(padapter)) ? "Legacy" : (((BTDM_IsHT40(padapter)) ? "HT40" : "HT20"))),
9455 ((!BTDM_IsWifiBusy(padapter)) ? "idle" : ((BTDM_IsWifiUplink(padapter)) ? "uplink" : "downlink")));
9456 DCMD_Printf(btCoexDbgBuf);
9458 if (pBtMgnt->bSupportProfile) {
9459 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
9460 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_SCO)) ? 1 : 0),
9461 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) ? 1 : 0),
9462 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) ? 1 : 0),
9463 ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) ? 1 : 0));
9464 DCMD_Printf(btCoexDbgBuf);
9466 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
9467 if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
9468 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role",
9469 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9470 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec],
9471 BtLinkRoleString[pBtMgnt->ExtConfig.linkInfo[i].linkRole]);
9472 DCMD_Printf(btCoexDbgBuf);
9474 btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
9475 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "A2DP rate", \
9476 (btInfoExt&BIT0) ? "Basic rate" : "EDR rate");
9477 DCMD_Printf(btCoexDbgBuf);
9479 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
9480 BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
9481 BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec]);
9482 DCMD_Printf(btCoexDbgBuf);
9489 if (!pBtMgnt->ExtConfig.bManualControl) {
9490 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw BT Coex mechanism]============");
9491 DCMD_Printf(btCoexDbgBuf);
9492 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "AGC Table", \
9493 pBtCoex->btdm2Ant.bCurAgcTableEn);
9494 DCMD_Printf(btCoexDbgBuf);
9495 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "ADC Backoff", \
9496 pBtCoex->btdm2Ant.bCurAdcBackOff);
9497 DCMD_Printf(btCoexDbgBuf);
9498 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Low penalty RA", \
9499 pBtCoex->btdm2Ant.bCurLowPenaltyRa);
9500 DCMD_Printf(btCoexDbgBuf);
9501 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "RF Rx LPF Shrink", \
9502 pBtCoex->btdm2Ant.bCurRfRxLpfShrink);
9503 DCMD_Printf(btCoexDbgBuf);
9505 u4Tmp[0] = PHY_QueryRFReg(padapter, PathA, 0x1e, 0xff0);
9506 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "RF-A, 0x1e[11:4]/original val", \
9507 u4Tmp[0], pHalData->bt_coexist.BtRfRegOrigin1E);
9508 DCMD_Printf(btCoexDbgBuf);
9511 if (!pBtMgnt->ExtConfig.bManualControl) {
9512 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw BT Coex mechanism]============");
9513 DCMD_Printf(btCoexDbgBuf);
9515 if (!pBtMgnt->ExtConfig.bManualControl) {
9516 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9517 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm1Ant.curPsTdma;
9519 psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm2Ant.curPsTdma;
9520 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA(0x3a)", \
9521 pHalData->bt_coexist.fw3aVal[0], pHalData->bt_coexist.fw3aVal[1],
9522 pHalData->bt_coexist.fw3aVal[2], pHalData->bt_coexist.fw3aVal[3],
9523 pHalData->bt_coexist.fw3aVal[4], psTdmaCase);
9524 DCMD_Printf(btCoexDbgBuf);
9526 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Decrease Bt Power", \
9527 pBtCoex->btdm2Ant.bCurDecBtPwr);
9528 DCMD_Printf(btCoexDbgBuf);
9530 u1Tmp = rtw_read8(padapter, 0x778);
9531 u1Tmp1 = rtw_read8(padapter, 0x783);
9532 u1Tmp2 = rtw_read8(padapter, 0x796);
9533 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
9534 u1Tmp, u1Tmp1, u1Tmp2);
9535 DCMD_Printf(btCoexDbgBuf);
9537 if (!pBtMgnt->ExtConfig.bManualControl) {
9538 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "Sw DacSwing Ctrl/Val", \
9539 pBtCoex->btdm2Ant.bCurDacSwingOn, pBtCoex->btdm2Ant.curDacSwingLvl);
9540 DCMD_Printf(btCoexDbgBuf);
9542 u4Tmp[0] = rtw_read32(padapter, 0x880);
9543 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \
9545 DCMD_Printf(btCoexDbgBuf);
9548 if (!pBtMgnt->ExtConfig.bManualControl) {
9549 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw BT Coex mechanism]============");
9550 DCMD_Printf(btCoexDbgBuf);
9553 u1Tmp = rtw_read8(padapter, 0x40);
9554 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
9556 DCMD_Printf(btCoexDbgBuf);
9558 u4Tmp[0] = rtw_read32(padapter, 0x550);
9559 u1Tmp = rtw_read8(padapter, 0x522);
9560 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x", "0x550(bcn contrl)/0x522", \
9562 DCMD_Printf(btCoexDbgBuf);
9564 u4Tmp[0] = rtw_read32(padapter, 0x484);
9565 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
9567 DCMD_Printf(btCoexDbgBuf);
9569 u4Tmp[0] = rtw_read32(padapter, 0x50);
9570 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
9572 DCMD_Printf(btCoexDbgBuf);
9574 u4Tmp[0] = rtw_read32(padapter, 0xda0);
9575 u4Tmp[1] = rtw_read32(padapter, 0xda4);
9576 u4Tmp[2] = rtw_read32(padapter, 0xda8);
9577 u4Tmp[3] = rtw_read32(padapter, 0xdac);
9578 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
9579 u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);
9580 DCMD_Printf(btCoexDbgBuf);
9582 u4Tmp[0] = rtw_read32(padapter, 0x6c0);
9583 u4Tmp[1] = rtw_read32(padapter, 0x6c4);
9584 u4Tmp[2] = rtw_read32(padapter, 0x6c8);
9585 u1Tmp = rtw_read8(padapter, 0x6cc);
9586 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
9587 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp);
9588 DCMD_Printf(btCoexDbgBuf);
9590 /* u4Tmp = rtw_read32(padapter, 0x770); */
9591 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x770(Hi pri Rx[31:16]/Tx[15:0])", \
9592 pHalData->bt_coexist.halCoex8723.highPriorityRx,
9593 pHalData->bt_coexist.halCoex8723.highPriorityTx);
9594 DCMD_Printf(btCoexDbgBuf);
9595 /* u4Tmp = rtw_read32(padapter, 0x774); */
9596 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x774(Lo pri Rx[31:16]/Tx[15:0])", \
9597 pHalData->bt_coexist.halCoex8723.lowPriorityRx,
9598 pHalData->bt_coexist.halCoex8723.lowPriorityTx);
9599 DCMD_Printf(btCoexDbgBuf);
9601 /* Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang */
9602 u1Tmp = rtw_read8(padapter, 0x41b);
9603 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x41b (hang chk == 0xf)", \
9605 DCMD_Printf(btCoexDbgBuf);
9606 rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
9607 pHalData->LastHMEBoxNum);
9608 DCMD_Printf(btCoexDbgBuf);
9612 BTDM_8723ASignalCompensation(struct rtw_adapter *padapter,
9613 u8 *rssi_wifi, u8 *rssi_bt)
9615 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9616 BTDM_1AntSignalCompensation(padapter, rssi_wifi, rssi_bt);
9619 static void BTDM_8723AInit(struct rtw_adapter *padapter)
9621 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9622 BTDM_2AntParaInit(padapter);
9624 BTDM_1AntParaInit(padapter);
9627 static void BTDM_HWCoexAllOff8723A(struct rtw_adapter *padapter)
9629 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9630 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9632 if (pBtMgnt->ExtConfig.bManualControl)
9635 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9636 BTDM_2AntHwCoexAllOff8723A(padapter);
9639 static void BTDM_FWCoexAllOff8723A(struct rtw_adapter *padapter)
9641 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9642 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9644 if (pBtMgnt->ExtConfig.bManualControl)
9647 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9648 BTDM_2AntFwCoexAllOff8723A(padapter);
9651 static void BTDM_SWCoexAllOff8723A(struct rtw_adapter *padapter)
9653 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9654 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9656 if (pBtMgnt->ExtConfig.bManualControl)
9659 if (btdm_BtWifiAntNum(padapter) == Ant_x2)
9660 BTDM_2AntSwCoexAllOff8723A(padapter);
9664 BTDM_Set8723ABtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
9666 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9667 struct bt_coexist_8723a *pBtCoex = &pHalData->bt_coexist.halCoex8723;
9670 pBtCoex->TotalAntNum = Ant_x1;
9671 else if (antNum == 2)
9672 pBtCoex->TotalAntNum = Ant_x2;
9675 void BTDM_LpsLeave(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_x1)
9684 BTDM_1AntLpsLeave(padapter);
9687 static void BTDM_ForHalt8723A(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_x1)
9696 BTDM_1AntForHalt(padapter);
9699 static void BTDM_WifiScanNotify8723A(struct rtw_adapter *padapter, u8 scanType)
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_x1)
9708 BTDM_1AntWifiScanNotify(padapter, scanType);
9712 BTDM_WifiAssociateNotify8723A(struct rtw_adapter *padapter, u8 action)
9714 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9715 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9717 if (pBtMgnt->ExtConfig.bManualControl)
9720 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9721 BTDM_1AntWifiAssociateNotify(padapter, action);
9725 BTDM_MediaStatusNotify8723A(struct rtw_adapter *padapter,
9726 enum rt_media_status mstatus)
9728 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9729 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9731 RTPRINT(FBT, BT_TRACE, ("[BTCoex], MediaStatusNotify, %s\n",
9732 mstatus?"connect":"disconnect"));
9734 BTDM_SetFwChnlInfo(padapter, mstatus);
9736 if (pBtMgnt->ExtConfig.bManualControl)
9739 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9740 BTDM_1AntMediaStatusNotify(padapter, mstatus);
9743 static void BTDM_ForDhcp8723A(struct rtw_adapter *padapter)
9745 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9746 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9748 if (pBtMgnt->ExtConfig.bManualControl)
9751 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9752 BTDM_1AntForDhcp(padapter);
9755 u8 BTDM_1Ant8723A(struct rtw_adapter *padapter)
9757 if (btdm_BtWifiAntNum(padapter) == Ant_x1)
9763 static void BTDM_BTCoexist8723A(struct rtw_adapter *padapter)
9765 struct hal_data_8723a *pHalData;
9766 struct bt_30info *pBTInfo;
9767 struct bt_mgnt *pBtMgnt;
9768 struct bt_coexist_8723a *pBtCoex;
9770 pHalData = GET_HAL_DATA(padapter);
9771 pBTInfo = GET_BT_INFO(padapter);
9772 pBtMgnt = &pBTInfo->BtMgnt;
9773 pBtCoex = &pHalData->bt_coexist.halCoex8723;
9775 RTPRINT(FBT, BT_TRACE, ("[BTCoex], beacon RSSI = 0x%x(%d)\n",
9776 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB,
9777 pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB));
9779 btdm_BtHwCountersMonitor(padapter);
9780 btdm_BtEnableDisableCheck8723A(padapter);
9782 if (pBtMgnt->ExtConfig.bManualControl) {
9783 RTPRINT(FBT, BT_TRACE, ("%s: Action Manual control!!\n", __func__));
9787 if (pBtCoex->bC2hBtInfoReqSent) {
9788 if (BT_IsBtDisabled(padapter)) {
9789 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9791 if (pBtCoex->c2hBtInfo == BT_INFO_STATE_DISABLED)
9792 pBtCoex->c2hBtInfo = BT_INFO_STATE_NO_CONNECTION;
9795 btdm_BTCoexist8723AHandler(padapter);
9796 } else if (BT_IsBtDisabled(padapter) == true) {
9797 pBtCoex->c2hBtInfo = BT_INFO_STATE_DISABLED;
9798 btdm_BTCoexist8723AHandler(padapter);
9801 BTDM_QueryBtInformation(padapter);
9804 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtc8723.c ===== */
9807 #ifdef __HALBTCCSR1ANT_C__ /* HAL/BTCoexist/HalBtcCsr1Ant.c */
9808 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
9810 /* local function start with btdm_ */
9811 /* extern function start with BTDM_ */
9813 static void BTDM_SetAntenna(struct rtw_adapter *padapter, u8 who)
9819 struct rtw_adapter *padapter,
9825 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9826 u8 H2C_Parameter[3] = {0};
9828 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9831 H2C_Parameter[2] = 0;
9832 H2C_Parameter[1] = 0;
9833 H2C_Parameter[0] = 0;
9836 H2C_Parameter[2] |= 0x02; /* BIT1 */
9837 pHalData->bt_coexist.bFWCoexistAllOff = false;
9839 pHalData->bt_coexist.bInterruptOn = bInterruptOn;
9842 H2C_Parameter[2] |= 0x10; /* BIT4 */
9843 pHalData->bt_coexist.bFWCoexistAllOff = false;
9845 pHalData->bt_coexist.bSingleAntOn = bSingleAntOn;
9848 H2C_Parameter[2] |= 0x20; /* BIT5 */
9849 pHalData->bt_coexist.bFWCoexistAllOff = false;
9851 pHalData->bt_coexist.bMultiNAVOn = bMultiNAVOn;
9853 RTPRINT(FBT, BT_TRACE, ("[DM][BT], SingleAntenna =[%s:%s:%s], write 0xe = 0x%x\n",
9854 bSingleAntOn?"ON":"OFF", bInterruptOn?"ON":"OFF", bMultiNAVOn?"ON":"OFF",
9855 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
9858 void BTDM_CheckBTIdleChange1Ant(struct rtw_adapter *padapter)
9860 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
9861 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
9862 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
9863 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
9864 u8 stateChange = false;
9865 u32 BT_Polling, Ratio_Act, Ratio_STA;
9866 u32 BT_Active, BT_State;
9867 u32 regBTActive = 0, regBTState = 0, regBTPolling = 0;
9869 if (!pHalData->bt_coexist.BluetoothCoexist)
9871 if (pBtMgnt->ExtConfig.bManualControl)
9873 if (pHalData->bt_coexist.BT_CoexistType != BT_CSR_BC8)
9875 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x1)
9878 /* The following we only consider CSR BC8 and fw version should be >= 62 */
9879 RTPRINT(FBT, BT_TRACE, ("[DM][BT], FirmwareVersion = 0x%x(%d)\n",
9880 pHalData->FirmwareVersion, pHalData->FirmwareVersion));
9881 regBTActive = REG_BT_ACTIVE;
9882 regBTState = REG_BT_STATE;
9883 if (pHalData->FirmwareVersion >= FW_VER_BT_REG1)
9884 regBTPolling = REG_BT_POLLING1;
9886 regBTPolling = REG_BT_POLLING;
9888 BT_Active = rtw_read32(padapter, regBTActive);
9889 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Active(0x%x) =%x\n", regBTActive, BT_Active));
9890 BT_Active = BT_Active & 0x00ffffff;
9892 BT_State = rtw_read32(padapter, regBTState);
9893 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_State(0x%x) =%x\n", regBTState, BT_State));
9894 BT_State = BT_State & 0x00ffffff;
9896 BT_Polling = rtw_read32(padapter, regBTPolling);
9897 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT_Polling(0x%x) =%x\n", regBTPolling, BT_Polling));
9899 if (BT_Active == 0xffffffff && BT_State == 0xffffffff && BT_Polling == 0xffffffff)
9901 if (BT_Polling == 0)
9904 Ratio_Act = BT_Active*1000/BT_Polling;
9905 Ratio_STA = BT_State*1000/BT_Polling;
9907 pHalData->bt_coexist.Ratio_Tx = Ratio_Act;
9908 pHalData->bt_coexist.Ratio_PRI = Ratio_STA;
9910 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_Act =%d\n", Ratio_Act));
9911 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Ratio_STA =%d\n", Ratio_STA));
9913 if (Ratio_STA < 60 && Ratio_Act < 500) { /* BT PAN idle */
9914 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_IDLE;
9915 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9916 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9918 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_IDLE;
9921 /* Check if BT PAN (under BT 2.1) is uplink or downlink */
9922 if ((Ratio_Act/Ratio_STA) < 2) {
9924 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = true;
9925 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_UPLINK;
9926 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = false;
9927 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_DOWNLINK;
9929 /* BT PAN downlink */
9930 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9931 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9932 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9933 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9936 /* BT PAN downlink */
9937 pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic = false;
9938 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_PAN_UPLINK;
9939 pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic = true;
9940 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_PAN_DOWNLINK;
9944 /* Check BT is idle or not */
9945 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9946 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9947 pBtMgnt->ExtConfig.bBTBusy = false;
9948 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9950 if (Ratio_STA < 60) {
9951 pBtMgnt->ExtConfig.bBTBusy = false;
9952 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_IDLE;
9954 pBtMgnt->ExtConfig.bBTBusy = true;
9955 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_IDLE;
9959 if (pBtMgnt->ExtConfig.NumberOfHandle == 0 &&
9960 pBtMgnt->ExtConfig.NumberOfSCO == 0) {
9961 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
9962 pBtMgnt->ExtConfig.MIN_BT_RSSI = 0;
9963 BTDM_SetAntenna(padapter, BTDM_ANT_BT_IDLE);
9965 if (pBtMgnt->ExtConfig.MIN_BT_RSSI <= -5) {
9966 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT_RSSI_LOW;
9967 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Low\n"));
9969 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT_RSSI_LOW;
9970 RTPRINT(FBT, BT_TRACE, ("[DM][BT], core stack notify bt rssi Normal\n"));
9974 if (pHalData->bt_coexist.bBTBusyTraffic != pBtMgnt->ExtConfig.bBTBusy) {
9975 /* BT idle or BT non-idle */
9976 pHalData->bt_coexist.bBTBusyTraffic = pBtMgnt->ExtConfig.bBTBusy;
9981 if (!pBtMgnt->ExtConfig.bBTBusy)
9982 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
9984 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is non-idle\n"));
9986 if (!pBtMgnt->ExtConfig.bBTBusy) {
9987 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT is idle or disable\n"));
9988 if (check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING|WIFI_SITE_MONITOR) == true)
9989 BTDM_SetAntenna(padapter, BTDM_ANT_WIFI);
9993 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr1Ant.c ===== */
9996 #ifdef __HALBTCCSR2ANT_C__ /* HAL/BTCoexist/HalBtcCsr2Ant.c */
9997 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
9999 /* local function start with btdm_ */
10002 /* In the following, FW should be done before SW mechanism. */
10003 /* BTDM_Balance(), BTDM_DiminishWiFi(), BT_NAV() should be done */
10004 /* before BTDM_AGCTable(), BTDM_BBBackOffLevel(), btdm_DacSwing(). */
10006 /* extern function start with BTDM_ */
10010 struct rtw_adapter *padapter,
10017 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10018 u8 H2C_Parameter[3] = {0};
10020 if (pHalData->bt_coexist.BT_Ant_Num != Ant_x2)
10023 if ((pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_RSSI_LOW) &&
10024 (DACSwingLevel == 0x20)) {
10025 RTPRINT(FBT, BT_TRACE, ("[BT]DiminishWiFi 0x20 original, but set 0x18 for Low RSSI!\n"));
10026 DACSwingLevel = 0x18;
10029 H2C_Parameter[2] = 0;
10030 H2C_Parameter[1] = DACSwingLevel;
10031 H2C_Parameter[0] = 0;
10033 H2C_Parameter[2] |= 0x01; /* BIT0 */
10035 H2C_Parameter[2] |= 0x02; /* BIT1 */
10036 pHalData->bt_coexist.bFWCoexistAllOff = false;
10039 H2C_Parameter[2] |= 0x08; /* BIT3 */
10040 pHalData->bt_coexist.bFWCoexistAllOff = false;
10043 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bDACOn = %s, bInterruptOn = %s, write 0xe = 0x%x\n",
10044 bDACOn?"ON":"OFF", bInterruptOn?"ON":"OFF",
10045 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10046 RTPRINT(FBT, BT_TRACE, ("[DM][BT], bNAVOn = %s\n",
10047 bNAVOn?"ON":"OFF"));
10050 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtcCsr2Ant.c ===== */
10053 #ifdef __HALBTCOEXIST_C__ /* HAL/BTCoexist/HalBtCoexist.c */
10054 /* ===== Below this line is sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
10056 /* local function */
10057 static void btdm_ResetFWCoexState(struct rtw_adapter *padapter)
10059 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10061 pHalData->bt_coexist.CurrentState = 0;
10062 pHalData->bt_coexist.PreviousState = 0;
10065 static void btdm_InitBtCoexistDM(struct rtw_adapter *padapter)
10067 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10069 /* 20100415 Joseph: Restore RF register 0x1E and 0x1F value for further usage. */
10070 pHalData->bt_coexist.BtRfRegOrigin1E = PHY_QueryRFReg(padapter, PathA, RF_RCK1, bRFRegOffsetMask);
10071 pHalData->bt_coexist.BtRfRegOrigin1F = PHY_QueryRFReg(padapter, PathA, RF_RCK2, 0xf0);
10073 pHalData->bt_coexist.CurrentState = 0;
10074 pHalData->bt_coexist.PreviousState = 0;
10076 BTDM_8723AInit(padapter);
10077 pHalData->bt_coexist.bInitlized = true;
10081 /* extern function */
10083 void BTDM_CheckAntSelMode(struct rtw_adapter *padapter)
10087 void BTDM_FwC2hBtRssi(struct rtw_adapter *padapter, u8 *tmpBuf)
10089 BTDM_FwC2hBtRssi8723A(padapter, tmpBuf);
10092 void BTDM_FwC2hBtInfo(struct rtw_adapter *padapter, u8 *tmpBuf, u8 length)
10094 BTDM_FwC2hBtInfo8723A(padapter, tmpBuf, length);
10097 void BTDM_DisplayBtCoexInfo(struct rtw_adapter *padapter)
10099 BTDM_Display8723ABtCoexInfo(padapter);
10102 void BTDM_RejectAPAggregatedPacket(struct rtw_adapter *padapter, u8 bReject)
10106 u8 BTDM_IsHT40(struct rtw_adapter *padapter)
10109 enum ht_channel_width bw;
10111 bw = padapter->mlmeextpriv.cur_bwmode;
10113 if (bw == HT_CHANNEL_WIDTH_20)
10115 else if (bw == HT_CHANNEL_WIDTH_40)
10121 u8 BTDM_Legacy(struct rtw_adapter *padapter)
10123 struct mlme_ext_priv *pmlmeext;
10124 u8 isLegacy = false;
10126 pmlmeext = &padapter->mlmeextpriv;
10127 if ((pmlmeext->cur_wireless_mode == WIRELESS_11B) ||
10128 (pmlmeext->cur_wireless_mode == WIRELESS_11G) ||
10129 (pmlmeext->cur_wireless_mode == WIRELESS_11BG))
10135 void BTDM_CheckWiFiState(struct rtw_adapter *padapter)
10137 struct hal_data_8723a *pHalData;
10138 struct mlme_priv *pmlmepriv;
10139 struct bt_30info *pBTInfo;
10140 struct bt_mgnt *pBtMgnt;
10142 pHalData = GET_HAL_DATA(padapter);
10143 pmlmepriv = &padapter->mlmepriv;
10144 pBTInfo = GET_BT_INFO(padapter);
10145 pBtMgnt = &pBTInfo->BtMgnt;
10147 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) {
10148 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_IDLE;
10150 if (pmlmepriv->LinkDetectInfo.bTxBusyTraffic)
10151 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_UPLINK;
10153 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10155 if (pmlmepriv->LinkDetectInfo.bRxBusyTraffic)
10156 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_DOWNLINK;
10158 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10160 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_IDLE;
10161 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_UPLINK;
10162 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_DOWNLINK;
10165 if (BTDM_Legacy(padapter)) {
10166 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_LEGACY;
10167 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10168 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10170 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_LEGACY;
10171 if (BTDM_IsHT40(padapter)) {
10172 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT40;
10173 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT20;
10175 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_HT20;
10176 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_HT40;
10180 if (pBtMgnt->BtOperationOn)
10181 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_BT30;
10183 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_BT30;
10186 s32 BTDM_GetRxSS(struct rtw_adapter *padapter)
10188 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10189 struct mlme_priv *pmlmepriv;
10190 struct hal_data_8723a *pHalData;
10191 s32 UndecoratedSmoothedPWDB = 0;
10193 pmlmepriv = &padapter->mlmepriv;
10194 pHalData = GET_HAL_DATA(padapter);
10196 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10197 UndecoratedSmoothedPWDB = GET_UNDECORATED_AVERAGE_RSSI(padapter);
10198 } else { /* associated entry pwdb */
10199 UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10200 /* pHalData->BT_EntryMinUndecoratedSmoothedPWDB */
10202 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxSS() = %d\n", UndecoratedSmoothedPWDB));
10203 return UndecoratedSmoothedPWDB;
10206 static s32 BTDM_GetRxBeaconSS(struct rtw_adapter *padapter)
10208 /*PMGNT_INFO pMgntInfo = &padapter->MgntInfo; */
10209 struct mlme_priv *pmlmepriv;
10210 struct hal_data_8723a *pHalData;
10211 s32 pwdbBeacon = 0;
10213 pmlmepriv = &padapter->mlmepriv;
10214 pHalData = GET_HAL_DATA(padapter);
10216 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
10217 /* pwdbBeacon = pHalData->dmpriv.UndecoratedSmoothedBeacon; */
10218 pwdbBeacon = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
10220 RTPRINT(FBT, BT_TRACE, ("BTDM_GetRxBeaconSS() = %d\n", pwdbBeacon));
10224 /* Get beacon rssi state */
10225 u8 BTDM_CheckCoexBcnRssiState(struct rtw_adapter *padapter, u8 levelNum,
10226 u8 RssiThresh, u8 RssiThresh1)
10228 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10229 s32 pwdbBeacon = 0;
10230 u8 bcnRssiState = 0;
10232 pwdbBeacon = BTDM_GetRxBeaconSS(padapter);
10234 if (levelNum == 2) {
10235 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10237 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10238 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10239 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10240 bcnRssiState = BT_RSSI_STATE_HIGH;
10241 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10242 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10243 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10245 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10246 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10249 if (pwdbBeacon < RssiThresh) {
10250 bcnRssiState = BT_RSSI_STATE_LOW;
10251 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10252 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10253 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10255 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10256 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10259 } else if (levelNum == 3) {
10260 if (RssiThresh > RssiThresh1) {
10261 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON thresh error!!\n"));
10262 return pHalData->bt_coexist.preRssiStateBeacon;
10265 if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_LOW) ||
10266 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_LOW)) {
10267 if (pwdbBeacon >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10268 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10269 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10270 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10271 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10272 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10274 bcnRssiState = BT_RSSI_STATE_STAY_LOW;
10275 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Low\n"));
10277 } else if ((pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_MEDIUM) ||
10278 (pHalData->bt_coexist.preRssiStateBeacon == BT_RSSI_STATE_STAY_MEDIUM)) {
10279 if (pwdbBeacon >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10280 bcnRssiState = BT_RSSI_STATE_HIGH;
10281 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10282 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10283 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10284 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to High\n"));
10285 } else if (pwdbBeacon < RssiThresh) {
10286 bcnRssiState = BT_RSSI_STATE_LOW;
10287 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10288 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10289 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10290 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Low\n"));
10292 bcnRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10293 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at Medium\n"));
10296 if (pwdbBeacon < RssiThresh1) {
10297 bcnRssiState = BT_RSSI_STATE_MEDIUM;
10298 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_BEACON_MEDIUM;
10299 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_HIGH;
10300 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_BEACON_LOW;
10301 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state switch to Medium\n"));
10303 bcnRssiState = BT_RSSI_STATE_STAY_HIGH;
10304 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_BEACON state stay at High\n"));
10309 pHalData->bt_coexist.preRssiStateBeacon = bcnRssiState;
10311 return bcnRssiState;
10314 u8 BTDM_CheckCoexRSSIState1(struct rtw_adapter *padapter, u8 levelNum,
10315 u8 RssiThresh, u8 RssiThresh1)
10317 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10318 s32 UndecoratedSmoothedPWDB = 0;
10319 u8 btRssiState = 0;
10321 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10323 if (levelNum == 2) {
10324 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10326 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10327 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10328 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10329 btRssiState = BT_RSSI_STATE_HIGH;
10330 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10331 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10332 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10334 btRssiState = BT_RSSI_STATE_STAY_LOW;
10335 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10338 if (UndecoratedSmoothedPWDB < RssiThresh) {
10339 btRssiState = BT_RSSI_STATE_LOW;
10340 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10341 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10342 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10344 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10345 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10348 } else if (levelNum == 3) {
10349 if (RssiThresh > RssiThresh1) {
10350 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 thresh error!!\n"));
10351 return pHalData->bt_coexist.preRssiState1;
10354 if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_LOW) ||
10355 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_LOW)) {
10356 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10357 btRssiState = BT_RSSI_STATE_MEDIUM;
10358 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10359 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10360 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10361 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10363 btRssiState = BT_RSSI_STATE_STAY_LOW;
10364 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Low\n"));
10366 } else if ((pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_MEDIUM) ||
10367 (pHalData->bt_coexist.preRssiState1 == BT_RSSI_STATE_STAY_MEDIUM)) {
10368 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10369 btRssiState = BT_RSSI_STATE_HIGH;
10370 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10371 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10372 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10373 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to High\n"));
10374 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10375 btRssiState = BT_RSSI_STATE_LOW;
10376 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_LOW;
10377 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10378 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10379 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Low\n"));
10381 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10382 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at Medium\n"));
10385 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10386 btRssiState = BT_RSSI_STATE_MEDIUM;
10387 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_1_MEDIUM;
10388 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_HIGH;
10389 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_1_LOW;
10390 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state switch to Medium\n"));
10392 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10393 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI_1 state stay at High\n"));
10398 pHalData->bt_coexist.preRssiState1 = btRssiState;
10400 return btRssiState;
10403 u8 BTDM_CheckCoexRSSIState(struct rtw_adapter *padapter, u8 levelNum,
10404 u8 RssiThresh, u8 RssiThresh1)
10406 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10407 s32 UndecoratedSmoothedPWDB = 0;
10408 u8 btRssiState = 0;
10410 UndecoratedSmoothedPWDB = BTDM_GetRxSS(padapter);
10412 if (levelNum == 2) {
10413 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10415 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10416 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10417 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10418 btRssiState = BT_RSSI_STATE_HIGH;
10419 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10420 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10421 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10423 btRssiState = BT_RSSI_STATE_STAY_LOW;
10424 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10427 if (UndecoratedSmoothedPWDB < RssiThresh) {
10428 btRssiState = BT_RSSI_STATE_LOW;
10429 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10430 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10431 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10433 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10434 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10437 } else if (levelNum == 3) {
10438 if (RssiThresh > RssiThresh1) {
10439 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI thresh error!!\n"));
10440 return pHalData->bt_coexist.preRssiState;
10443 if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_LOW) ||
10444 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_LOW)) {
10445 if (UndecoratedSmoothedPWDB >= (RssiThresh+BT_FW_COEX_THRESH_TOL)) {
10446 btRssiState = BT_RSSI_STATE_MEDIUM;
10447 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10448 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10449 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10450 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10452 btRssiState = BT_RSSI_STATE_STAY_LOW;
10453 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Low\n"));
10455 } else if ((pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_MEDIUM) ||
10456 (pHalData->bt_coexist.preRssiState == BT_RSSI_STATE_STAY_MEDIUM)) {
10457 if (UndecoratedSmoothedPWDB >= (RssiThresh1+BT_FW_COEX_THRESH_TOL)) {
10458 btRssiState = BT_RSSI_STATE_HIGH;
10459 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_HIGH;
10460 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10461 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10462 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to High\n"));
10463 } else if (UndecoratedSmoothedPWDB < RssiThresh) {
10464 btRssiState = BT_RSSI_STATE_LOW;
10465 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_LOW;
10466 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10467 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10468 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Low\n"));
10470 btRssiState = BT_RSSI_STATE_STAY_MEDIUM;
10471 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at Medium\n"));
10474 if (UndecoratedSmoothedPWDB < RssiThresh1) {
10475 btRssiState = BT_RSSI_STATE_MEDIUM;
10476 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_WIFI_RSSI_MEDIUM;
10477 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_HIGH;
10478 pHalData->bt_coexist.CurrentState &= ~BT_COEX_STATE_WIFI_RSSI_LOW;
10479 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state switch to Medium\n"));
10481 btRssiState = BT_RSSI_STATE_STAY_HIGH;
10482 RTPRINT(FBT, BT_TRACE, ("[DM][BT], RSSI state stay at High\n"));
10487 pHalData->bt_coexist.preRssiState = btRssiState;
10489 return btRssiState;
10492 u8 BTDM_DisableEDCATurbo(struct rtw_adapter *padapter)
10494 struct bt_mgnt *pBtMgnt;
10495 struct hal_data_8723a *pHalData;
10496 u8 bBtChangeEDCA = false;
10497 u32 EDCA_BT_BE = 0x5ea42b, cur_EDCA_reg;
10500 pHalData = GET_HAL_DATA(padapter);
10501 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10503 if (!pHalData->bt_coexist.BluetoothCoexist) {
10505 pHalData->bt_coexist.lastBtEdca = 0;
10508 if (!((pBtMgnt->bSupportProfile) ||
10509 (pHalData->bt_coexist.BT_CoexistType == BT_CSR_BC8))) {
10511 pHalData->bt_coexist.lastBtEdca = 0;
10515 if (BT_1Ant(padapter)) {
10517 pHalData->bt_coexist.lastBtEdca = 0;
10521 if (pHalData->bt_coexist.exec_cnt < 3)
10522 pHalData->bt_coexist.exec_cnt++;
10524 pHalData->bt_coexist.bEDCAInitialized = true;
10526 /* When BT is non idle */
10527 if (!(pHalData->bt_coexist.CurrentState & BT_COEX_STATE_BT_IDLE)) {
10528 RTPRINT(FBT, BT_TRACE, ("BT state non idle, set bt EDCA\n"));
10530 /* aggr_num = 0x0909; */
10531 if (pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA) {
10532 bBtChangeEDCA = true;
10533 pHalData->odmpriv.DM_EDCA_Table.bCurrentTurboEDCA = false;
10534 pHalData->dmpriv.prv_traffic_idx = 3;
10536 cur_EDCA_reg = rtw_read32(padapter, REG_EDCA_BE_PARAM);
10538 if (cur_EDCA_reg != EDCA_BT_BE)
10539 bBtChangeEDCA = true;
10540 if (bBtChangeEDCA || !pHalData->bt_coexist.bEDCAInitialized) {
10541 rtw_write32(padapter, REG_EDCA_BE_PARAM, EDCA_BT_BE);
10542 pHalData->bt_coexist.lastBtEdca = EDCA_BT_BE;
10546 RTPRINT(FBT, BT_TRACE, ("BT state idle, set original EDCA\n"));
10547 pHalData->bt_coexist.lastBtEdca = 0;
10555 struct rtw_adapter *padapter,
10561 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10562 u8 H2C_Parameter[3] = {0};
10565 H2C_Parameter[2] = 1;
10566 H2C_Parameter[1] = ms1;
10567 H2C_Parameter[0] = ms0;
10568 pHalData->bt_coexist.bFWCoexistAllOff = false;
10570 H2C_Parameter[2] = 0;
10571 H2C_Parameter[1] = 0;
10572 H2C_Parameter[0] = 0;
10574 pHalData->bt_coexist.bBalanceOn = bBalanceOn;
10576 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Balance =[%s:%dms:%dms], write 0xc = 0x%x\n",
10577 bBalanceOn?"ON":"OFF", ms0, ms1,
10578 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
10580 FillH2CCmd(padapter, 0xc, 3, H2C_Parameter);
10583 void BTDM_AGCTable(struct rtw_adapter *padapter, u8 type)
10585 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10586 if (type == BT_AGCTABLE_OFF) {
10587 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable Off!\n"));
10588 rtw_write32(padapter, 0xc78, 0x641c0001);
10589 rtw_write32(padapter, 0xc78, 0x631d0001);
10590 rtw_write32(padapter, 0xc78, 0x621e0001);
10591 rtw_write32(padapter, 0xc78, 0x611f0001);
10592 rtw_write32(padapter, 0xc78, 0x60200001);
10594 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x32000);
10595 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x71000);
10596 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xb0000);
10597 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xfc000);
10598 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x30355);
10600 pHalData->bt_coexist.b8723aAgcTableOn = false;
10601 } else if (type == BT_AGCTABLE_ON) {
10602 RTPRINT(FBT, BT_TRACE, ("[BT]AGCTable On!\n"));
10603 rtw_write32(padapter, 0xc78, 0x4e1c0001);
10604 rtw_write32(padapter, 0xc78, 0x4d1d0001);
10605 rtw_write32(padapter, 0xc78, 0x4c1e0001);
10606 rtw_write32(padapter, 0xc78, 0x4b1f0001);
10607 rtw_write32(padapter, 0xc78, 0x4a200001);
10609 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0xdc000);
10610 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x90000);
10611 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x51000);
10612 PHY_SetRFReg(padapter, PathA, RF_RX_AGC_HP, bRFRegOffsetMask, 0x12000);
10613 PHY_SetRFReg(padapter, PathA, RF_RX_G1, bRFRegOffsetMask, 0x00355);
10615 pHalData->bt_coexist.b8723aAgcTableOn = true;
10617 pHalData->bt_coexist.bSWCoexistAllOff = false;
10621 void BTDM_BBBackOffLevel(struct rtw_adapter *padapter, u8 type)
10623 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10625 if (type == BT_BB_BACKOFF_OFF) {
10626 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel Off!\n"));
10627 rtw_write32(padapter, 0xc04, 0x3a05611);
10628 } else if (type == BT_BB_BACKOFF_ON) {
10629 RTPRINT(FBT, BT_TRACE, ("[BT]BBBackOffLevel On!\n"));
10630 rtw_write32(padapter, 0xc04, 0x3a07611);
10631 pHalData->bt_coexist.bSWCoexistAllOff = false;
10635 void BTDM_FWCoexAllOff(struct rtw_adapter *padapter)
10637 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10639 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff()\n"));
10640 if (pHalData->bt_coexist.bFWCoexistAllOff)
10642 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff(), real Do\n"));
10644 BTDM_FWCoexAllOff8723A(padapter);
10646 pHalData->bt_coexist.bFWCoexistAllOff = true;
10649 void BTDM_SWCoexAllOff(struct rtw_adapter *padapter)
10651 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10653 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff()\n"));
10654 if (pHalData->bt_coexist.bSWCoexistAllOff)
10656 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff(), real Do\n"));
10657 BTDM_SWCoexAllOff8723A(padapter);
10659 pHalData->bt_coexist.bSWCoexistAllOff = true;
10662 void BTDM_HWCoexAllOff(struct rtw_adapter *padapter)
10664 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);;
10666 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff()\n"));
10667 if (pHalData->bt_coexist.bHWCoexistAllOff)
10669 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff(), real Do\n"));
10671 BTDM_HWCoexAllOff8723A(padapter);
10673 pHalData->bt_coexist.bHWCoexistAllOff = true;
10676 void BTDM_CoexAllOff(struct rtw_adapter *padapter)
10678 BTDM_FWCoexAllOff(padapter);
10679 BTDM_SWCoexAllOff(padapter);
10680 BTDM_HWCoexAllOff(padapter);
10683 void BTDM_TurnOffBtCoexistBeforeEnterIPS(struct rtw_adapter *padapter)
10685 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10686 struct pwrctrl_priv *ppwrctrl = &padapter->pwrctrlpriv;
10688 if (!pHalData->bt_coexist.BluetoothCoexist)
10691 /* 8723 1Ant doesn't need to turn off bt coexist mechanism. */
10692 if (BTDM_1Ant8723A(padapter))
10695 /* Before enter IPS, turn off FW BT Co-exist mechanism */
10696 if (ppwrctrl->reg_rfoff == rf_on) {
10697 RTPRINT(FBT, BT_TRACE, ("[BT][DM], Before enter IPS, turn off all Coexist DM\n"));
10698 btdm_ResetFWCoexState(padapter);
10699 BTDM_CoexAllOff(padapter);
10700 BTDM_SetAntenna(padapter, BTDM_ANT_BT);
10704 void BTDM_SignalCompensation(struct rtw_adapter *padapter, u8 *rssi_wifi, u8 *rssi_bt)
10706 BTDM_8723ASignalCompensation(padapter, rssi_wifi, rssi_bt);
10709 void BTDM_Coexist(struct rtw_adapter *padapter)
10711 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10713 if (!pHalData->bt_coexist.BluetoothCoexist) {
10714 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BT not exists!!\n"));
10718 if (!pHalData->bt_coexist.bInitlized) {
10719 RTPRINT(FBT, BT_TRACE, ("[DM][BT], btdm_InitBtCoexistDM()\n"));
10720 btdm_InitBtCoexistDM(padapter);
10723 RTPRINT(FBT, BT_TRACE, ("\n\n[DM][BT], BTDM start!!\n"));
10725 BTDM_PWDBMonitor(padapter);
10727 RTPRINT(FBT, BT_TRACE, ("[DM][BT], HW type is 8723\n"));
10728 BTDM_BTCoexist8723A(padapter);
10729 RTPRINT(FBT, BT_TRACE, ("[DM][BT], BTDM end!!\n\n"));
10732 void BTDM_UpdateCoexState(struct rtw_adapter *padapter)
10734 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10736 if (!BTDM_IsSameCoexistState(padapter)) {
10737 RTPRINT(FBT, BT_TRACE, ("[BTCoex], Coexist State[bitMap] change from 0x%"i64fmt"x to 0x%"i64fmt"x, changeBits = 0x%"i64fmt"x\n",
10738 pHalData->bt_coexist.PreviousState,
10739 pHalData->bt_coexist.CurrentState,
10740 (pHalData->bt_coexist.PreviousState^pHalData->bt_coexist.CurrentState)));
10741 pHalData->bt_coexist.PreviousState = pHalData->bt_coexist.CurrentState;
10745 u8 BTDM_IsSameCoexistState(struct rtw_adapter *padapter)
10747 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10749 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState) {
10752 RTPRINT(FBT, BT_TRACE, ("[DM][BT], Coexist state changed!!\n"));
10757 void BTDM_PWDBMonitor(struct rtw_adapter *padapter)
10759 struct bt_30info *pBTInfo = GET_BT_INFO(GetDefaultAdapter(padapter));
10760 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10761 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10762 u8 H2C_Parameter[3] = {0};
10763 s32 tmpBTEntryMaxPWDB = 0, tmpBTEntryMinPWDB = 0xff;
10766 if (pBtMgnt->BtOperationOn) {
10767 for (i = 0; i < MAX_BT_ASOC_ENTRY_NUM; i++) {
10768 if (pBTInfo->BtAsocEntry[i].bUsed) {
10769 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB < tmpBTEntryMinPWDB)
10770 tmpBTEntryMinPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10771 if (pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB > tmpBTEntryMaxPWDB)
10772 tmpBTEntryMaxPWDB = pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB;
10773 /* Report every BT connection (HS mode) RSSI to FW */
10774 H2C_Parameter[2] = (u8)(pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB & 0xFF);
10775 H2C_Parameter[0] = (MAX_FW_SUPPORT_MACID_NUM-1-i);
10776 RTPRINT(FDM, DM_BT30, ("RSSI report for BT[%d], H2C_Par = 0x%x\n", i, H2C_Parameter[0]));
10777 FillH2CCmd(padapter, RSSI_SETTING_EID, 3, H2C_Parameter);
10778 RTPRINT_ADDR(FDM, (DM_PWDB|DM_BT30), ("BT_Entry Mac :"),
10779 pBTInfo->BtAsocEntry[i].BTRemoteMACAddr)
10780 RTPRINT(FDM, (DM_PWDB|DM_BT30),
10781 ("BT rx pwdb[%d] = 0x%x(%d)\n", i,
10782 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB,
10783 pBTInfo->BtAsocEntry[i].UndecoratedSmoothedPWDB));
10786 if (tmpBTEntryMaxPWDB != 0) { /* If associated entry is found */
10787 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = tmpBTEntryMaxPWDB;
10788 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMaxPWDB = 0x%x(%d)\n",
10789 tmpBTEntryMaxPWDB, tmpBTEntryMaxPWDB));
10791 pHalData->dmpriv.BT_EntryMaxUndecoratedSmoothedPWDB = 0;
10793 if (tmpBTEntryMinPWDB != 0xff) { /* If associated entry is found */
10794 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = tmpBTEntryMinPWDB;
10795 RTPRINT(FDM, (DM_PWDB|DM_BT30), ("BT_EntryMinPWDB = 0x%x(%d)\n",
10796 tmpBTEntryMinPWDB, tmpBTEntryMinPWDB));
10798 pHalData->dmpriv.BT_EntryMinUndecoratedSmoothedPWDB = 0;
10803 u8 BTDM_IsBTBusy(struct rtw_adapter *padapter)
10805 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10806 struct bt_mgnt *pBtMgnt = &pBTInfo->BtMgnt;
10808 if (pBtMgnt->ExtConfig.bBTBusy)
10814 u8 BTDM_IsWifiBusy(struct rtw_adapter *padapter)
10816 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10817 struct mlme_priv *pmlmepriv = &GetDefaultAdapter(padapter)->mlmepriv;
10818 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
10819 struct bt_traffic *pBtTraffic = &pBTInfo->BtTraffic;
10821 if (pmlmepriv->LinkDetectInfo.bBusyTraffic ||
10822 pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic ||
10823 pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic)
10829 u8 BTDM_IsCoexistStateChanged(struct rtw_adapter *padapter)
10831 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10833 if (pHalData->bt_coexist.PreviousState == pHalData->bt_coexist.CurrentState)
10839 u8 BTDM_IsWifiUplink(struct rtw_adapter *padapter)
10841 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10842 struct mlme_priv *pmlmepriv;
10843 struct bt_30info *pBTInfo;
10844 struct bt_traffic *pBtTraffic;
10846 pmlmepriv = &padapter->mlmepriv;
10847 pBTInfo = GET_BT_INFO(padapter);
10848 pBtTraffic = &pBTInfo->BtTraffic;
10850 if ((pmlmepriv->LinkDetectInfo.bTxBusyTraffic) ||
10851 (pBtTraffic->Bt30TrafficStatistics.bTxBusyTraffic))
10857 u8 BTDM_IsWifiDownlink(struct rtw_adapter *padapter)
10859 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10860 struct mlme_priv *pmlmepriv;
10861 struct bt_30info *pBTInfo;
10862 struct bt_traffic *pBtTraffic;
10864 pmlmepriv = &padapter->mlmepriv;
10865 pBTInfo = GET_BT_INFO(padapter);
10866 pBtTraffic = &pBTInfo->BtTraffic;
10868 if ((pmlmepriv->LinkDetectInfo.bRxBusyTraffic) ||
10869 (pBtTraffic->Bt30TrafficStatistics.bRxBusyTraffic))
10875 u8 BTDM_IsBTHSMode(struct rtw_adapter *padapter)
10877 /*PMGNT_INFO pMgntInfo = &GetDefaultAdapter(padapter)->MgntInfo; */
10878 struct hal_data_8723a *pHalData;
10879 struct bt_mgnt *pBtMgnt;
10881 pHalData = GET_HAL_DATA(padapter);
10882 pBtMgnt = &pHalData->BtInfo.BtMgnt;
10884 if (pBtMgnt->BtOperationOn)
10890 u8 BTDM_IsBTUplink(struct rtw_adapter *padapter)
10892 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10894 if (pHalData->bt_coexist.BT21TrafficStatistics.bTxBusyTraffic)
10900 u8 BTDM_IsBTDownlink(struct rtw_adapter *padapter)
10902 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10904 if (pHalData->bt_coexist.BT21TrafficStatistics.bRxBusyTraffic)
10910 void BTDM_AdjustForBtOperation(struct rtw_adapter *padapter)
10912 RTPRINT(FBT, BT_TRACE, ("[BT][DM], BTDM_AdjustForBtOperation()\n"));
10913 BTDM_AdjustForBtOperation8723A(padapter);
10916 void BTDM_SetBtCoexCurrAntNum(struct rtw_adapter *padapter, u8 antNum)
10918 BTDM_Set8723ABtCoexCurrAntNum(padapter, antNum);
10921 void BTDM_ForHalt(struct rtw_adapter *padapter)
10923 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10925 if (!pHalData->bt_coexist.BluetoothCoexist)
10928 BTDM_ForHalt8723A(padapter);
10929 GET_HAL_DATA(padapter)->bt_coexist.bInitlized = false;
10932 void BTDM_WifiScanNotify(struct rtw_adapter *padapter, u8 scanType)
10934 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10936 if (!pHalData->bt_coexist.BluetoothCoexist)
10939 BTDM_WifiScanNotify8723A(padapter, scanType);
10942 void BTDM_WifiAssociateNotify(struct rtw_adapter *padapter, u8 action)
10944 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10946 if (!pHalData->bt_coexist.BluetoothCoexist)
10949 BTDM_WifiAssociateNotify8723A(padapter, action);
10952 void BTDM_MediaStatusNotify(struct rtw_adapter *padapter, enum rt_media_status mstatus)
10954 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10956 if (!pHalData->bt_coexist.BluetoothCoexist)
10959 BTDM_MediaStatusNotify8723A(padapter, mstatus);
10962 void BTDM_ForDhcp(struct rtw_adapter *padapter)
10964 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10966 if (!pHalData->bt_coexist.BluetoothCoexist)
10969 BTDM_ForDhcp8723A(padapter);
10972 void BTDM_ResetActionProfileState(struct rtw_adapter *padapter)
10974 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10976 pHalData->bt_coexist.CurrentState &= ~\
10977 (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP|
10978 BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_SCO);
10981 u8 BTDM_IsActionSCO(struct rtw_adapter *padapter)
10983 struct hal_data_8723a *pHalData;
10984 struct bt_30info *pBTInfo;
10985 struct bt_mgnt *pBtMgnt;
10986 struct bt_dgb *pBtDbg;
10989 pHalData = GET_HAL_DATA(padapter);
10990 pBTInfo = GET_BT_INFO(padapter);
10991 pBtMgnt = &pBTInfo->BtMgnt;
10992 pBtDbg = &pBTInfo->BtDbg;
10995 if (pBtDbg->dbgCtrl) {
10996 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_SCO) {
10997 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
11001 if (pBtMgnt->ExtConfig.NumberOfSCO > 0) {
11002 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_SCO;
11009 u8 BTDM_IsActionHID(struct rtw_adapter *padapter)
11011 struct bt_30info *pBTInfo;
11012 struct hal_data_8723a *pHalData;
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_HID) {
11025 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11029 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11030 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11031 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_HID;
11038 u8 BTDM_IsActionA2DP(struct rtw_adapter *padapter)
11040 struct hal_data_8723a *pHalData;
11041 struct bt_30info *pBTInfo;
11042 struct bt_mgnt *pBtMgnt;
11043 struct bt_dgb *pBtDbg;
11046 pHalData = GET_HAL_DATA(padapter);
11047 pBTInfo = GET_BT_INFO(padapter);
11048 pBtMgnt = &pBTInfo->BtMgnt;
11049 pBtDbg = &pBTInfo->BtDbg;
11052 if (pBtDbg->dbgCtrl) {
11053 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_A2DP) {
11054 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11058 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP) &&
11059 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11060 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_A2DP;
11067 u8 BTDM_IsActionPAN(struct rtw_adapter *padapter)
11069 struct hal_data_8723a *pHalData;
11070 struct bt_30info *pBTInfo;
11071 struct bt_mgnt *pBtMgnt;
11072 struct bt_dgb *pBtDbg;
11075 pHalData = GET_HAL_DATA(padapter);
11076 pBTInfo = GET_BT_INFO(padapter);
11077 pBtMgnt = &pBTInfo->BtMgnt;
11078 pBtDbg = &pBTInfo->BtDbg;
11081 if (pBtDbg->dbgCtrl) {
11082 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN) {
11083 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11087 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) &&
11088 pBtMgnt->ExtConfig.NumberOfHandle == 1) {
11089 pHalData->bt_coexist.CurrentState |= BT_COEX_STATE_PROFILE_PAN;
11096 u8 BTDM_IsActionHIDA2DP(struct rtw_adapter *padapter)
11098 struct hal_data_8723a *pHalData;
11099 struct bt_30info *pBTInfo;
11100 struct bt_mgnt *pBtMgnt;
11101 struct bt_dgb *pBtDbg;
11104 pHalData = GET_HAL_DATA(padapter);
11105 pBTInfo = GET_BT_INFO(padapter);
11106 pBtMgnt = &pBTInfo->BtMgnt;
11107 pBtDbg = &pBTInfo->BtDbg;
11110 if (pBtDbg->dbgCtrl) {
11111 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_A2DP) {
11112 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11116 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11117 BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11118 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_A2DP);
11125 u8 BTDM_IsActionHIDPAN(struct rtw_adapter *padapter)
11127 struct hal_data_8723a *pHalData;
11128 struct bt_30info *pBTInfo;
11129 struct bt_dgb *pBtDbg;
11132 pHalData = GET_HAL_DATA(padapter);
11133 pBTInfo = GET_BT_INFO(padapter);
11134 pBtDbg = &pBTInfo->BtDbg;
11137 if (pBtDbg->dbgCtrl) {
11138 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_HID_PAN) {
11139 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11143 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID) &&
11144 BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) {
11145 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_HID|BT_COEX_STATE_PROFILE_PAN);
11152 u8 BTDM_IsActionPANA2DP(struct rtw_adapter *padapter)
11154 struct hal_data_8723a *pHalData;
11155 struct bt_30info *pBTInfo;
11156 struct bt_dgb *pBtDbg;
11159 pHalData = GET_HAL_DATA(padapter);
11160 pBTInfo = GET_BT_INFO(padapter);
11161 pBtDbg = &pBTInfo->BtDbg;
11164 if (pBtDbg->dbgCtrl) {
11165 if (pBtDbg->dbgProfile == BT_DBG_PROFILE_PAN_A2DP) {
11166 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11170 if (BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN) && BTHCI_CheckProfileExist(padapter, BT_PROFILE_A2DP)) {
11171 pHalData->bt_coexist.CurrentState |= (BT_COEX_STATE_PROFILE_PAN|BT_COEX_STATE_PROFILE_A2DP);
11178 u8 BTDM_IsBtDisabled(struct rtw_adapter *padapter)
11180 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11182 if (pHalData->bt_coexist.bCurBtDisabled)
11188 /* ===== End of sync from SD7 driver HAL/BTCoexist/HalBtCoexist.c ===== */
11191 #ifdef __HALBT_C__ /* HAL/HalBT.c */
11192 /* ===== Below this line is sync from SD7 driver HAL/HalBT.c ===== */
11195 /*local function */
11198 static void halbt_InitHwConfig8723A(struct rtw_adapter *padapter)
11203 /*extern function */
11205 u8 HALBT_GetPGAntNum(struct rtw_adapter *padapter)
11207 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11209 return pHalData->bt_coexist.BT_Ant_Num;
11212 void HALBT_SetKey(struct rtw_adapter *padapter, u8 EntryNum)
11214 struct bt_30info *pBTinfo;
11215 struct bt_asoc_entry *pBtAssocEntry;
11218 pBTinfo = GET_BT_INFO(padapter);
11219 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11221 pBtAssocEntry->HwCAMIndex = BT_HWCAM_STAR + EntryNum;
11223 usConfig = CAM_VALID | (CAM_AES << 2);
11224 write_cam23a(padapter, pBtAssocEntry->HwCAMIndex, usConfig, pBtAssocEntry->BTRemoteMACAddr, pBtAssocEntry->PTK + TKIP_ENC_KEY_POS);
11227 void HALBT_RemoveKey(struct rtw_adapter *padapter, u8 EntryNum)
11229 struct bt_30info *pBTinfo;
11230 struct bt_asoc_entry *pBtAssocEntry;
11232 pBTinfo = GET_BT_INFO(padapter);
11233 pBtAssocEntry = &pBTinfo->BtAsocEntry[EntryNum];
11235 if (pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex != 0) {
11236 /* ToDo : add New HALBT_RemoveKey function !! */
11237 if (pBtAssocEntry->HwCAMIndex >= BT_HWCAM_STAR && pBtAssocEntry->HwCAMIndex < HALF_CAM_ENTRY)
11238 CAM_empty_entry23a(padapter, pBtAssocEntry->HwCAMIndex);
11239 pBTinfo->BtAsocEntry[EntryNum].HwCAMIndex = 0;
11243 void HALBT_InitBTVars8723A(struct rtw_adapter *padapter)
11245 struct hal_data_8723a *pHalData;
11247 pHalData = GET_HAL_DATA(padapter);
11249 pHalData->bt_coexist.BluetoothCoexist = pHalData->EEPROMBluetoothCoexist;
11250 pHalData->bt_coexist.BT_Ant_Num = pHalData->EEPROMBluetoothAntNum;
11251 pHalData->bt_coexist.BT_CoexistType = pHalData->EEPROMBluetoothType;
11252 pHalData->bt_coexist.BT_Ant_isolation = pHalData->EEPROMBluetoothAntIsolation;
11253 pHalData->bt_coexist.bt_radiosharedtype = pHalData->EEPROMBluetoothRadioShared;
11255 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BT Coexistance = 0x%x\n", pHalData->bt_coexist.BluetoothCoexist));
11256 if (pHalData->bt_coexist.BluetoothCoexist) {
11257 if (pHalData->bt_coexist.BT_Ant_Num == Ant_x2) {
11258 BTDM_SetBtCoexCurrAntNum(padapter, 2);
11259 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx2\n"));
11260 } else if (pHalData->bt_coexist.BT_Ant_Num == Ant_x1) {
11261 BTDM_SetBtCoexCurrAntNum(padapter, 1);
11262 RT_TRACE(_module_hal_init_c_, _drv_info_, ("BlueTooth BT_Ant_Num = Antx1\n"));
11264 pHalData->bt_coexist.bBTBusyTraffic = false;
11265 pHalData->bt_coexist.bBTTrafficModeSet = false;
11266 pHalData->bt_coexist.bBTNonTrafficModeSet = false;
11267 pHalData->bt_coexist.CurrentState = 0;
11268 pHalData->bt_coexist.PreviousState = 0;
11270 RT_TRACE(_module_hal_init_c_, _drv_info_,
11271 ("bt_radiosharedType = 0x%x\n",
11272 pHalData->bt_coexist.bt_radiosharedtype));
11276 u8 HALBT_IsBTExist(struct rtw_adapter *padapter)
11278 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11280 if (pHalData->bt_coexist.BluetoothCoexist)
11286 u8 HALBT_BTChipType(struct rtw_adapter *padapter)
11288 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
11290 return pHalData->bt_coexist.BT_CoexistType;
11293 void HALBT_InitHwConfig(struct rtw_adapter *padapter)
11295 halbt_InitHwConfig8723A(padapter);
11296 BTDM_Coexist(padapter);
11299 void HALBT_SetRtsCtsNoLenLimit(struct rtw_adapter *padapter)
11303 /* ===== End of sync from SD7 driver HAL/HalBT.c ===== */