rtw_bt_mp.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  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.
  8. *
  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
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #include <drv_types.h>
  21. #include <rtw_bt_mp.h>
  22. #if defined(CONFIG_RTL8723B)
  23. #include <rtl8723b_hal.h>
  24. #endif
  25. #if defined(CONFIG_RTL8723B) || defined(CONFIG_RTL8821A)
  26. void MPh2c_timeout_handle(void *FunctionContext)
  27. {
  28. PADAPTER pAdapter;
  29. PMPT_CONTEXT pMptCtx;
  30. RTW_INFO("[MPT], MPh2c_timeout_handle\n");
  31. pAdapter = (PADAPTER)FunctionContext;
  32. pMptCtx = &pAdapter->mppriv.mpt_ctx;
  33. pMptCtx->bMPh2c_timeout = _TRUE;
  34. if ((_FALSE == pMptCtx->MptH2cRspEvent)
  35. || ((_TRUE == pMptCtx->MptH2cRspEvent)
  36. && (_FALSE == pMptCtx->MptBtC2hEvent)))
  37. _rtw_up_sema(&pMptCtx->MPh2c_Sema);
  38. }
  39. u32 WaitC2Hevent(PADAPTER pAdapter, u8 *C2H_event, u32 delay_time)
  40. {
  41. PMPT_CONTEXT pMptCtx = &(pAdapter->mppriv.mpt_ctx);
  42. pMptCtx->bMPh2c_timeout = _FALSE;
  43. if (pAdapter->registrypriv.mp_mode == 0) {
  44. RTW_INFO("[MPT], Error!! WaitC2Hevent mp_mode == 0!!\n");
  45. return _FALSE;
  46. }
  47. _set_timer(&pMptCtx->MPh2c_timeout_timer, delay_time);
  48. _rtw_down_sema(&pMptCtx->MPh2c_Sema);
  49. if (pMptCtx->bMPh2c_timeout == _TRUE) {
  50. *C2H_event = _FALSE;
  51. return _FALSE;
  52. }
  53. /* for safty, cancel timer here again */
  54. _cancel_timer_ex(&pMptCtx->MPh2c_timeout_timer);
  55. return _TRUE;
  56. }
  57. BT_CTRL_STATUS
  58. mptbt_CheckC2hFrame(
  59. PADAPTER Adapter,
  60. PBT_H2C pH2c,
  61. PBT_EXT_C2H pExtC2h
  62. )
  63. {
  64. BT_CTRL_STATUS c2hStatus = BT_STATUS_C2H_SUCCESS;
  65. /* RTW_INFO("[MPT], MPT rsp C2H hex: %x %x %x %x %x %x\n"), pExtC2h , pExtC2h+1 ,pExtC2h+2 ,pExtC2h+3 ,pExtC2h+4 ,pExtC2h+5); */
  66. RTW_INFO("[MPT], statusCode = 0x%x\n", pExtC2h->statusCode);
  67. RTW_INFO("[MPT], retLen = %d\n", pExtC2h->retLen);
  68. RTW_INFO("[MPT], opCodeVer : req/rsp=%d/%d\n", pH2c->opCodeVer, pExtC2h->opCodeVer);
  69. RTW_INFO("[MPT], reqNum : req/rsp=%d/%d\n", pH2c->reqNum, pExtC2h->reqNum);
  70. if (pExtC2h->reqNum != pH2c->reqNum) {
  71. c2hStatus = BT_STATUS_C2H_REQNUM_MISMATCH;
  72. RTW_INFO("[MPT], Error!! C2H reqNum Mismatch!!\n");
  73. } else if (pExtC2h->opCodeVer != pH2c->opCodeVer) {
  74. c2hStatus = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
  75. RTW_INFO("[MPT], Error!! OPCode version L mismatch!!\n");
  76. }
  77. return c2hStatus;
  78. }
  79. BT_CTRL_STATUS
  80. mptbt_SendH2c(
  81. PADAPTER Adapter,
  82. PBT_H2C pH2c,
  83. u2Byte h2cCmdLen
  84. )
  85. {
  86. /* KIRQL OldIrql = KeGetCurrentIrql(); */
  87. BT_CTRL_STATUS h2cStatus = BT_STATUS_H2C_SUCCESS;
  88. PMPT_CONTEXT pMptCtx = &(Adapter->mppriv.mpt_ctx);
  89. u1Byte i;
  90. RTW_INFO("[MPT], mptbt_SendH2c()=========>\n");
  91. /* PlatformResetEvent(&pMptCtx->MptH2cRspEvent); */
  92. /* PlatformResetEvent(&pMptCtx->MptBtC2hEvent); */
  93. /* if(OldIrql == PASSIVE_LEVEL)
  94. * { */
  95. /* RTPRINT_DATA(FMPBT, FMPBT_H2C_CONTENT, ("[MPT], MPT H2C hex:\n"), pH2c, h2cCmdLen); */
  96. for (i = 0; i < BT_H2C_MAX_RETRY; i++) {
  97. RTW_INFO("[MPT], Send H2C command to wifi!!!\n");
  98. pMptCtx->MptH2cRspEvent = _FALSE;
  99. pMptCtx->MptBtC2hEvent = _FALSE;
  100. #if defined(CONFIG_RTL8723B)
  101. rtl8723b_set_FwBtMpOper_cmd(Adapter, pH2c->opCode, pH2c->opCodeVer, pH2c->reqNum, pH2c->buf);
  102. #endif
  103. pMptCtx->h2cReqNum++;
  104. pMptCtx->h2cReqNum %= 16;
  105. if (WaitC2Hevent(Adapter, &pMptCtx->MptH2cRspEvent, 100)) {
  106. RTW_INFO("[MPT], Received WiFi MptH2cRspEvent!!!\n");
  107. if (WaitC2Hevent(Adapter, &pMptCtx->MptBtC2hEvent, 400)) {
  108. RTW_INFO("[MPT], Received MptBtC2hEvent!!!\n");
  109. break;
  110. } else {
  111. RTW_INFO("[MPT], Error!!BT MptBtC2hEvent timeout!!\n");
  112. h2cStatus = BT_STATUS_H2C_BT_NO_RSP;
  113. }
  114. } else {
  115. RTW_INFO("[MPT], Error!!WiFi MptH2cRspEvent timeout!!\n");
  116. h2cStatus = BT_STATUS_H2C_TIMTOUT;
  117. }
  118. }
  119. /* }
  120. * else
  121. * {
  122. * RT_ASSERT(FALSE, ("[MPT], mptbt_SendH2c() can only run under PASSIVE_LEVEL!!\n"));
  123. * h2cStatus = BT_STATUS_WRONG_LEVEL;
  124. * } */
  125. RTW_INFO("[MPT], mptbt_SendH2c()<=========\n");
  126. return h2cStatus;
  127. }
  128. BT_CTRL_STATUS
  129. mptbt_CheckBtRspStatus(
  130. PADAPTER Adapter,
  131. PBT_EXT_C2H pExtC2h
  132. )
  133. {
  134. BT_CTRL_STATUS retStatus = BT_OP_STATUS_SUCCESS;
  135. switch (pExtC2h->statusCode) {
  136. case BT_OP_STATUS_SUCCESS:
  137. retStatus = BT_STATUS_BT_OP_SUCCESS;
  138. RTW_INFO("[MPT], BT status : BT_STATUS_SUCCESS\n");
  139. break;
  140. case BT_OP_STATUS_VERSION_MISMATCH:
  141. retStatus = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
  142. RTW_INFO("[MPT], BT status : BT_STATUS_OPCODE_L_VERSION_MISMATCH\n");
  143. break;
  144. case BT_OP_STATUS_UNKNOWN_OPCODE:
  145. retStatus = BT_STATUS_UNKNOWN_OPCODE_L;
  146. RTW_INFO("[MPT], BT status : BT_STATUS_UNKNOWN_OPCODE_L\n");
  147. break;
  148. case BT_OP_STATUS_ERROR_PARAMETER:
  149. retStatus = BT_STATUS_PARAMETER_FORMAT_ERROR_L;
  150. RTW_INFO("[MPT], BT status : BT_STATUS_PARAMETER_FORMAT_ERROR_L\n");
  151. break;
  152. default:
  153. retStatus = BT_STATUS_UNKNOWN_STATUS_L;
  154. RTW_INFO("[MPT], BT status : BT_STATUS_UNKNOWN_STATUS_L\n");
  155. break;
  156. }
  157. return retStatus;
  158. }
  159. BT_CTRL_STATUS
  160. mptbt_BtFwOpCodeProcess(
  161. PADAPTER Adapter,
  162. u1Byte btFwOpCode,
  163. u1Byte opCodeVer,
  164. pu1Byte pH2cPar,
  165. u1Byte h2cParaLen
  166. )
  167. {
  168. u1Byte H2C_Parameter[6] = {0};
  169. PBT_H2C pH2c = (PBT_H2C)&H2C_Parameter[0];
  170. PMPT_CONTEXT pMptCtx = &(Adapter->mppriv.mpt_ctx);
  171. PBT_EXT_C2H pExtC2h = (PBT_EXT_C2H)&pMptCtx->c2hBuf[0];
  172. u2Byte paraLen = 0, i;
  173. BT_CTRL_STATUS h2cStatus = BT_STATUS_H2C_SUCCESS, c2hStatus = BT_STATUS_C2H_SUCCESS;
  174. BT_CTRL_STATUS retStatus = BT_STATUS_H2C_BT_NO_RSP;
  175. if (Adapter->registrypriv.mp_mode == 0) {
  176. RTW_INFO("[MPT], Error!! mptbt_BtFwOpCodeProces mp_mode == 0!!\n");
  177. return _FALSE;
  178. }
  179. pH2c->opCode = btFwOpCode;
  180. pH2c->opCodeVer = opCodeVer;
  181. pH2c->reqNum = pMptCtx->h2cReqNum;
  182. /* PlatformMoveMemory(&pH2c->buf[0], pH2cPar, h2cParaLen); */
  183. /* _rtw_memcpy(&pH2c->buf[0], pH2cPar, h2cParaLen); */
  184. _rtw_memcpy(pH2c->buf, pH2cPar, h2cParaLen);
  185. RTW_INFO("[MPT], pH2c->opCode=%d\n", pH2c->opCode);
  186. RTW_INFO("[MPT], pH2c->opCodeVer=%d\n", pH2c->opCodeVer);
  187. RTW_INFO("[MPT], pH2c->reqNum=%d\n", pH2c->reqNum);
  188. RTW_INFO("[MPT], h2c parameter length=%d\n", h2cParaLen);
  189. for (i = 0; i < h2cParaLen; i++)
  190. RTW_INFO("[MPT], parameter[%d]=0x%02x\n", i, pH2c->buf[i]);
  191. h2cStatus = mptbt_SendH2c(Adapter, pH2c, h2cParaLen + 2);
  192. if (BT_STATUS_H2C_SUCCESS == h2cStatus) {
  193. /* if reach here, it means H2C get the correct c2h response, */
  194. c2hStatus = mptbt_CheckC2hFrame(Adapter, pH2c, pExtC2h);
  195. if (BT_STATUS_C2H_SUCCESS == c2hStatus)
  196. retStatus = mptbt_CheckBtRspStatus(Adapter, pExtC2h);
  197. else {
  198. RTW_INFO("[MPT], Error!! C2H failed for pH2c->opCode=%d\n", pH2c->opCode);
  199. /* check c2h status error, return error status code to upper layer. */
  200. retStatus = c2hStatus;
  201. }
  202. } else {
  203. RTW_INFO("[MPT], Error!! H2C failed for pH2c->opCode=%d\n", pH2c->opCode);
  204. /* check h2c status error, return error status code to upper layer. */
  205. retStatus = h2cStatus;
  206. }
  207. return retStatus;
  208. }
  209. u2Byte
  210. mptbt_BtReady(
  211. PADAPTER Adapter,
  212. PBT_REQ_CMD pBtReq,
  213. PBT_RSP_CMD pBtRsp
  214. )
  215. {
  216. u1Byte h2cParaBuf[6] = {0};
  217. u1Byte h2cParaLen = 0;
  218. u2Byte paraLen = 0;
  219. u1Byte retStatus = BT_STATUS_BT_OP_SUCCESS;
  220. u1Byte btOpcode;
  221. u1Byte btOpcodeVer = 0;
  222. PMPT_CONTEXT pMptCtx = &(Adapter->mppriv.mpt_ctx);
  223. PBT_EXT_C2H pExtC2h = (PBT_EXT_C2H)&pMptCtx->c2hBuf[0];
  224. u1Byte i;
  225. u1Byte btFwVer = 0, bdAddr[6] = {0};
  226. u2Byte btRealFwVer = 0;
  227. pu2Byte pu2Tmp = NULL;
  228. /* */
  229. /* check upper layer parameters */
  230. /* */
  231. /* 1. check upper layer opcode version */
  232. if (pBtReq->opCodeVer != 1) {
  233. RTW_INFO("[MPT], Error!! Upper OP code version not match!!!\n");
  234. pBtRsp->status = BT_STATUS_OPCODE_U_VERSION_MISMATCH;
  235. return paraLen;
  236. }
  237. pBtRsp->pParamStart[0] = MP_BT_NOT_READY;
  238. paraLen = 10;
  239. /* */
  240. /* execute lower layer opcodes */
  241. /* */
  242. /* Get BT FW version */
  243. /* fill h2c parameters */
  244. btOpcode = BT_LO_OP_GET_BT_VERSION;
  245. /* execute h2c and check respond c2h from bt fw is correct or not */
  246. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  247. /* ckeck bt return status. */
  248. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  249. pBtRsp->status = ((btOpcode << 8) | retStatus);
  250. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  251. return paraLen;
  252. } else {
  253. pu2Tmp = (pu2Byte)&pExtC2h->buf[0];
  254. btRealFwVer = *pu2Tmp;
  255. btFwVer = pExtC2h->buf[1];
  256. RTW_INFO("[MPT], btRealFwVer=0x%x, btFwVer=0x%x\n", btRealFwVer, btFwVer);
  257. }
  258. /* Get BD Address */
  259. /* fill h2c parameters */
  260. btOpcode = BT_LO_OP_GET_BD_ADDR_L;
  261. /* execute h2c and check respond c2h from bt fw is correct or not */
  262. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  263. /* ckeck bt return status. */
  264. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  265. pBtRsp->status = ((btOpcode << 8) | retStatus);
  266. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  267. return paraLen;
  268. } else {
  269. bdAddr[5] = pExtC2h->buf[0];
  270. bdAddr[4] = pExtC2h->buf[1];
  271. bdAddr[3] = pExtC2h->buf[2];
  272. }
  273. /* fill h2c parameters */
  274. btOpcode = BT_LO_OP_GET_BD_ADDR_H;
  275. /* execute h2c and check respond c2h from bt fw is correct or not */
  276. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  277. /* ckeck bt return status. */
  278. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  279. pBtRsp->status = ((btOpcode << 8) | retStatus);
  280. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  281. return paraLen;
  282. } else {
  283. bdAddr[2] = pExtC2h->buf[0];
  284. bdAddr[1] = pExtC2h->buf[1];
  285. bdAddr[0] = pExtC2h->buf[2];
  286. }
  287. RTW_INFO("[MPT], Local BDAddr:");
  288. for (i = 0; i < 6; i++)
  289. RTW_INFO(" 0x%x ", bdAddr[i]);
  290. pBtRsp->status = BT_STATUS_SUCCESS;
  291. pBtRsp->pParamStart[0] = MP_BT_READY;
  292. pu2Tmp = (pu2Byte)&pBtRsp->pParamStart[1];
  293. *pu2Tmp = btRealFwVer;
  294. pBtRsp->pParamStart[3] = btFwVer;
  295. for (i = 0; i < 6; i++)
  296. pBtRsp->pParamStart[4 + i] = bdAddr[5 - i];
  297. return paraLen;
  298. }
  299. void mptbt_close_WiFiRF(PADAPTER Adapter)
  300. {
  301. phy_set_bb_reg(Adapter, 0x824, 0xF, 0x0);
  302. phy_set_bb_reg(Adapter, 0x824, 0x700000, 0x0);
  303. phy_set_rf_reg(Adapter, RF_PATH_A, 0x0, 0xF0000, 0x0);
  304. }
  305. void mptbt_open_WiFiRF(PADAPTER Adapter)
  306. {
  307. phy_set_bb_reg(Adapter, 0x824, 0x700000, 0x3);
  308. phy_set_bb_reg(Adapter, 0x824, 0xF, 0x2);
  309. phy_set_rf_reg(Adapter, RF_PATH_A, 0x0, 0xF0000, 0x3);
  310. }
  311. u4Byte mptbt_switch_RF(PADAPTER Adapter, u1Byte Enter)
  312. {
  313. u2Byte tmp_2byte = 0;
  314. /* Enter test mode */
  315. if (Enter) {
  316. /* 1>. close WiFi RF */
  317. mptbt_close_WiFiRF(Adapter);
  318. /* 2>. change ant switch to BT */
  319. tmp_2byte = rtw_read16(Adapter, 0x860);
  320. tmp_2byte = tmp_2byte | BIT(9);
  321. tmp_2byte = tmp_2byte & (~BIT(8));
  322. rtw_write16(Adapter, 0x860, tmp_2byte);
  323. rtw_write16(Adapter, 0x870, 0x300);
  324. } else {
  325. /* 1>. Open WiFi RF */
  326. mptbt_open_WiFiRF(Adapter);
  327. /* 2>. change ant switch back */
  328. tmp_2byte = rtw_read16(Adapter, 0x860);
  329. tmp_2byte = tmp_2byte | BIT(8);
  330. tmp_2byte = tmp_2byte & (~BIT(9));
  331. rtw_write16(Adapter, 0x860, tmp_2byte);
  332. rtw_write16(Adapter, 0x870, 0x300);
  333. }
  334. return 0;
  335. }
  336. u2Byte
  337. mptbt_BtSetMode(
  338. PADAPTER Adapter,
  339. PBT_REQ_CMD pBtReq,
  340. PBT_RSP_CMD pBtRsp
  341. )
  342. {
  343. u1Byte h2cParaBuf[6] = {0};
  344. u1Byte h2cParaLen = 0;
  345. u2Byte paraLen = 0;
  346. u1Byte retStatus = BT_STATUS_BT_OP_SUCCESS;
  347. u1Byte btOpcode;
  348. u1Byte btOpcodeVer = 0;
  349. u1Byte btModeToSet = 0;
  350. /* */
  351. /* check upper layer parameters */
  352. /* */
  353. /* 1. check upper layer opcode version */
  354. if (pBtReq->opCodeVer != 1) {
  355. RTW_INFO("[MPT], Error!! Upper OP code version not match!!!\n");
  356. pBtRsp->status = BT_STATUS_OPCODE_U_VERSION_MISMATCH;
  357. return paraLen;
  358. }
  359. /* 2. check upper layer parameter length */
  360. if (1 == pBtReq->paraLength) {
  361. btModeToSet = pBtReq->pParamStart[0];
  362. RTW_INFO("[MPT], BtTestMode=%d\n", btModeToSet);
  363. } else {
  364. RTW_INFO("[MPT], Error!! wrong parameter length=%d (should be 1)\n", pBtReq->paraLength);
  365. pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U;
  366. return paraLen;
  367. }
  368. /* */
  369. /* execute lower layer opcodes */
  370. /* */
  371. /* 1. fill h2c parameters */
  372. /* check bt mode */
  373. btOpcode = BT_LO_OP_SET_BT_MODE;
  374. if (btModeToSet >= MP_BT_MODE_MAX) {
  375. pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  376. return paraLen;
  377. } else {
  378. mptbt_switch_RF(Adapter, 1);
  379. h2cParaBuf[0] = btModeToSet;
  380. h2cParaLen = 1;
  381. /* 2. execute h2c and check respond c2h from bt fw is correct or not */
  382. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  383. }
  384. /* 3. construct respond status code and data. */
  385. if (BT_STATUS_BT_OP_SUCCESS == retStatus)
  386. pBtRsp->status = BT_STATUS_SUCCESS;
  387. else {
  388. pBtRsp->status = ((btOpcode << 8) | retStatus);
  389. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  390. }
  391. return paraLen;
  392. }
  393. VOID
  394. MPTBT_FwC2hBtMpCtrl(
  395. PADAPTER Adapter,
  396. pu1Byte tmpBuf,
  397. u1Byte length
  398. )
  399. {
  400. u32 i;
  401. PMPT_CONTEXT pMptCtx = &(Adapter->mppriv.mpt_ctx);
  402. PBT_EXT_C2H pExtC2h = (PBT_EXT_C2H)tmpBuf;
  403. if (Adapter->bBTFWReady == _FALSE || Adapter->registrypriv.mp_mode == 0) {
  404. /* RTW_INFO("Ignore C2H BT MP Info since not in MP mode\n"); */
  405. return;
  406. }
  407. if (length > 32 || length < 3) {
  408. RTW_INFO("\n [MPT], pExtC2h->buf hex: length=%d > 32 || < 3\n", length);
  409. return;
  410. }
  411. /* cancel_timeout for h2c handle */
  412. _cancel_timer_ex(&pMptCtx->MPh2c_timeout_timer);
  413. for (i = 0; i < length; i++)
  414. RTW_INFO("[MPT], %s, buf[%d]=0x%02x ", __FUNCTION__, i, tmpBuf[i]);
  415. RTW_INFO("[MPT], pExtC2h->extendId=0x%x\n", pExtC2h->extendId);
  416. switch (pExtC2h->extendId) {
  417. case EXT_C2H_WIFI_FW_ACTIVE_RSP:
  418. RTW_INFO("[MPT], EXT_C2H_WIFI_FW_ACTIVE_RSP\n");
  419. #if 0
  420. RTW_INFO("[MPT], pExtC2h->buf hex:\n");
  421. for (i = 0; i < (length - 3); i++)
  422. RTW_INFO(" 0x%x ", pExtC2h->buf[i]);
  423. #endif
  424. if ((_FALSE == pMptCtx->bMPh2c_timeout)
  425. && (_FALSE == pMptCtx->MptH2cRspEvent)) {
  426. pMptCtx->MptH2cRspEvent = _TRUE;
  427. _rtw_up_sema(&pMptCtx->MPh2c_Sema);
  428. }
  429. break;
  430. case EXT_C2H_TRIG_BY_BT_FW:
  431. RTW_INFO("[MPT], EXT_C2H_TRIG_BY_BT_FW\n");
  432. _rtw_memcpy(&pMptCtx->c2hBuf[0], tmpBuf, length);
  433. RTW_INFO("[MPT], pExtC2h->statusCode=0x%x\n", pExtC2h->statusCode);
  434. RTW_INFO("[MPT], pExtC2h->retLen=0x%x\n", pExtC2h->retLen);
  435. RTW_INFO("[MPT], pExtC2h->opCodeVer=0x%x\n", pExtC2h->opCodeVer);
  436. RTW_INFO("[MPT], pExtC2h->reqNum=0x%x\n", pExtC2h->reqNum);
  437. for (i = 0; i < (length - 3); i++)
  438. RTW_INFO("[MPT], pExtC2h->buf[%d]=0x%02x\n", i, pExtC2h->buf[i]);
  439. if ((_FALSE == pMptCtx->bMPh2c_timeout)
  440. && (_TRUE == pMptCtx->MptH2cRspEvent)
  441. && (_FALSE == pMptCtx->MptBtC2hEvent)) {
  442. pMptCtx->MptBtC2hEvent = _TRUE;
  443. _rtw_up_sema(&pMptCtx->MPh2c_Sema);
  444. }
  445. break;
  446. default:
  447. RTW_INFO("[MPT], EXT_C2H Target not found,pExtC2h->extendId =%d ,pExtC2h->reqNum=%d\n", pExtC2h->extendId, pExtC2h->reqNum);
  448. break;
  449. }
  450. }
  451. u2Byte
  452. mptbt_BtGetGeneral(
  453. IN PADAPTER Adapter,
  454. IN PBT_REQ_CMD pBtReq,
  455. IN PBT_RSP_CMD pBtRsp
  456. )
  457. {
  458. PMPT_CONTEXT pMptCtx = &(Adapter->mppriv.mpt_ctx);
  459. PBT_EXT_C2H pExtC2h = (PBT_EXT_C2H)&pMptCtx->c2hBuf[0];
  460. u1Byte h2cParaBuf[6] = {0};
  461. u1Byte h2cParaLen = 0;
  462. u2Byte paraLen = 0;
  463. u1Byte retStatus = BT_STATUS_BT_OP_SUCCESS;
  464. u1Byte btOpcode, bdAddr[6] = {0};
  465. u1Byte btOpcodeVer = 0;
  466. u1Byte getType = 0, i;
  467. u2Byte getParaLen = 0, validParaLen = 0;
  468. u1Byte regType = 0, reportType = 0;
  469. u4Byte regAddr = 0, regValue = 0;
  470. pu4Byte pu4Tmp;
  471. pu2Byte pu2Tmp;
  472. pu1Byte pu1Tmp;
  473. /* */
  474. /* check upper layer parameters */
  475. /* */
  476. /* check upper layer opcode version */
  477. if (pBtReq->opCodeVer != 1) {
  478. RTW_INFO("[MPT], Error!! Upper OP code version not match!!!\n");
  479. pBtRsp->status = BT_STATUS_OPCODE_U_VERSION_MISMATCH;
  480. return paraLen;
  481. }
  482. /* check upper layer parameter length */
  483. if (pBtReq->paraLength < 1) {
  484. RTW_INFO("[MPT], Error!! wrong parameter length=%d (should larger than 1)\n", pBtReq->paraLength);
  485. pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U;
  486. return paraLen;
  487. }
  488. getParaLen = pBtReq->paraLength - 1;
  489. getType = pBtReq->pParamStart[0];
  490. RTW_INFO("[MPT], getType=%d, getParaLen=%d\n", getType, getParaLen);
  491. /* check parameter first */
  492. switch (getType) {
  493. case BT_GGET_REG:
  494. RTW_INFO("[MPT], [BT_GGET_REG]\n");
  495. validParaLen = 5;
  496. if (getParaLen == validParaLen) {
  497. btOpcode = BT_LO_OP_READ_REG;
  498. regType = pBtReq->pParamStart[1];
  499. pu4Tmp = (pu4Byte)&pBtReq->pParamStart[2];
  500. regAddr = *pu4Tmp;
  501. RTW_INFO("[MPT], BT_GGET_REG regType=0x%02x, regAddr=0x%08x!!\n",
  502. regType, regAddr);
  503. if (regType >= BT_REG_MAX) {
  504. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  505. return paraLen;
  506. } else {
  507. if (((BT_REG_RF == regType) && (regAddr > 0x7f)) ||
  508. ((BT_REG_MODEM == regType) && (regAddr > 0x1ff)) ||
  509. ((BT_REG_BLUEWIZE == regType) && (regAddr > 0xfff)) ||
  510. ((BT_REG_VENDOR == regType) && (regAddr > 0xfff)) ||
  511. ((BT_REG_LE == regType) && (regAddr > 0xfff))) {
  512. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  513. return paraLen;
  514. }
  515. }
  516. }
  517. break;
  518. case BT_GGET_STATUS:
  519. RTW_INFO("[MPT], [BT_GGET_STATUS]\n");
  520. validParaLen = 0;
  521. break;
  522. case BT_GGET_REPORT:
  523. RTW_INFO("[MPT], [BT_GGET_REPORT]\n");
  524. validParaLen = 1;
  525. if (getParaLen == validParaLen) {
  526. reportType = pBtReq->pParamStart[1];
  527. RTW_INFO("[MPT], BT_GGET_REPORT reportType=0x%x!!\n", reportType);
  528. if (reportType >= BT_REPORT_MAX) {
  529. pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  530. return paraLen;
  531. }
  532. }
  533. break;
  534. default: {
  535. RTW_INFO("[MPT], Error!! getType=%d, out of range\n", getType);
  536. pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  537. return paraLen;
  538. }
  539. break;
  540. }
  541. if (getParaLen != validParaLen) {
  542. RTW_INFO("[MPT], Error!! wrong parameter length=%d for BT_GET_GEN_CMD cmd id=0x%x, paraLen should=0x%x\n",
  543. getParaLen, getType, validParaLen);
  544. pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U;
  545. return paraLen;
  546. }
  547. /* */
  548. /* execute lower layer opcodes */
  549. /* */
  550. if (BT_GGET_REG == getType) {
  551. /* fill h2c parameters */
  552. /* here we should write reg value first then write the address, adviced by Austin */
  553. btOpcode = BT_LO_OP_READ_REG;
  554. h2cParaBuf[0] = regType;
  555. h2cParaBuf[1] = pBtReq->pParamStart[2];
  556. h2cParaBuf[2] = pBtReq->pParamStart[3];
  557. h2cParaLen = 3;
  558. /* execute h2c and check respond c2h from bt fw is correct or not */
  559. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  560. /* construct respond status code and data. */
  561. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  562. pBtRsp->status = ((btOpcode << 8) | retStatus);
  563. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  564. return paraLen;
  565. }
  566. pu2Tmp = (pu2Byte)&pExtC2h->buf[0];
  567. regValue = *pu2Tmp;
  568. RTW_INFO("[MPT], read reg regType=0x%02x, regAddr=0x%08x, regValue=0x%04x\n",
  569. regType, regAddr, regValue);
  570. pu4Tmp = (pu4Byte)&pBtRsp->pParamStart[0];
  571. *pu4Tmp = regValue;
  572. paraLen = 4;
  573. } else if (BT_GGET_STATUS == getType) {
  574. btOpcode = BT_LO_OP_GET_BT_STATUS;
  575. h2cParaLen = 0;
  576. /* execute h2c and check respond c2h from bt fw is correct or not */
  577. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  578. /* construct respond status code and data. */
  579. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  580. pBtRsp->status = ((btOpcode << 8) | retStatus);
  581. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  582. return paraLen;
  583. }
  584. pBtRsp->pParamStart[0] = pExtC2h->buf[0];
  585. pBtRsp->pParamStart[1] = pExtC2h->buf[1];
  586. RTW_INFO("[MPT], read bt status, testMode=0x%x, testStatus=0x%x\n",
  587. pBtRsp->pParamStart[0], pBtRsp->pParamStart[1]);
  588. paraLen = 2;
  589. } else if (BT_GGET_REPORT == getType) {
  590. switch (reportType) {
  591. case BT_REPORT_RX_PACKET_CNT: {
  592. RTW_INFO("[MPT], [Rx Packet Counts]\n");
  593. btOpcode = BT_LO_OP_GET_RX_PKT_CNT_L;
  594. h2cParaLen = 0;
  595. /* execute h2c and check respond c2h from bt fw is correct or not */
  596. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  597. /* construct respond status code and data. */
  598. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  599. pBtRsp->status = ((btOpcode << 8) | retStatus);
  600. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  601. return paraLen;
  602. }
  603. pBtRsp->pParamStart[0] = pExtC2h->buf[0];
  604. pBtRsp->pParamStart[1] = pExtC2h->buf[1];
  605. btOpcode = BT_LO_OP_GET_RX_PKT_CNT_H;
  606. h2cParaLen = 0;
  607. /* execute h2c and check respond c2h from bt fw is correct or not */
  608. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  609. /* construct respond status code and data. */
  610. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  611. pBtRsp->status = ((btOpcode << 8) | retStatus);
  612. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  613. return paraLen;
  614. }
  615. pBtRsp->pParamStart[2] = pExtC2h->buf[0];
  616. pBtRsp->pParamStart[3] = pExtC2h->buf[1];
  617. paraLen = 4;
  618. }
  619. break;
  620. case BT_REPORT_RX_ERROR_BITS: {
  621. RTW_INFO("[MPT], [Rx Error Bits]\n");
  622. btOpcode = BT_LO_OP_GET_RX_ERROR_BITS_L;
  623. h2cParaLen = 0;
  624. /* execute h2c and check respond c2h from bt fw is correct or not */
  625. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  626. /* construct respond status code and data. */
  627. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  628. pBtRsp->status = ((btOpcode << 8) | retStatus);
  629. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  630. return paraLen;
  631. }
  632. pBtRsp->pParamStart[0] = pExtC2h->buf[0];
  633. pBtRsp->pParamStart[1] = pExtC2h->buf[1];
  634. btOpcode = BT_LO_OP_GET_RX_ERROR_BITS_H;
  635. h2cParaLen = 0;
  636. /* execute h2c and check respond c2h from bt fw is correct or not */
  637. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  638. /* construct respond status code and data. */
  639. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  640. pBtRsp->status = ((btOpcode << 8) | retStatus);
  641. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  642. return paraLen;
  643. }
  644. pBtRsp->pParamStart[2] = pExtC2h->buf[0];
  645. pBtRsp->pParamStart[3] = pExtC2h->buf[1];
  646. paraLen = 4;
  647. }
  648. break;
  649. case BT_REPORT_RSSI: {
  650. RTW_INFO("[MPT], [RSSI]\n");
  651. btOpcode = BT_LO_OP_GET_RSSI;
  652. h2cParaLen = 0;
  653. /* execute h2c and check respond c2h from bt fw is correct or not */
  654. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  655. /* construct respond status code and data. */
  656. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  657. pBtRsp->status = ((btOpcode << 8) | retStatus);
  658. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  659. return paraLen;
  660. }
  661. pBtRsp->pParamStart[0] = pExtC2h->buf[0];
  662. pBtRsp->pParamStart[1] = pExtC2h->buf[1];
  663. paraLen = 2;
  664. }
  665. break;
  666. case BT_REPORT_CFO_HDR_QUALITY: {
  667. RTW_INFO("[MPT], [CFO & Header Quality]\n");
  668. btOpcode = BT_LO_OP_GET_CFO_HDR_QUALITY_L;
  669. h2cParaLen = 0;
  670. /* execute h2c and check respond c2h from bt fw is correct or not */
  671. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  672. /* construct respond status code and data. */
  673. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  674. pBtRsp->status = ((btOpcode << 8) | retStatus);
  675. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  676. return paraLen;
  677. }
  678. pBtRsp->pParamStart[0] = pExtC2h->buf[0];
  679. pBtRsp->pParamStart[1] = pExtC2h->buf[1];
  680. btOpcode = BT_LO_OP_GET_CFO_HDR_QUALITY_H;
  681. h2cParaLen = 0;
  682. /* execute h2c and check respond c2h from bt fw is correct or not */
  683. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  684. /* construct respond status code and data. */
  685. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  686. pBtRsp->status = ((btOpcode << 8) | retStatus);
  687. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  688. return paraLen;
  689. }
  690. pBtRsp->pParamStart[2] = pExtC2h->buf[0];
  691. pBtRsp->pParamStart[3] = pExtC2h->buf[1];
  692. paraLen = 4;
  693. }
  694. break;
  695. case BT_REPORT_CONNECT_TARGET_BD_ADDR: {
  696. RTW_INFO("[MPT], [Connected Target BD ADDR]\n");
  697. btOpcode = BT_LO_OP_GET_TARGET_BD_ADDR_L;
  698. h2cParaLen = 0;
  699. /* execute h2c and check respond c2h from bt fw is correct or not */
  700. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  701. /* construct respond status code and data. */
  702. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  703. pBtRsp->status = ((btOpcode << 8) | retStatus);
  704. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  705. return paraLen;
  706. }
  707. bdAddr[5] = pExtC2h->buf[0];
  708. bdAddr[4] = pExtC2h->buf[1];
  709. bdAddr[3] = pExtC2h->buf[2];
  710. btOpcode = BT_LO_OP_GET_TARGET_BD_ADDR_H;
  711. h2cParaLen = 0;
  712. /* execute h2c and check respond c2h from bt fw is correct or not */
  713. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  714. /* construct respond status code and data. */
  715. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  716. pBtRsp->status = ((btOpcode << 8) | retStatus);
  717. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  718. return paraLen;
  719. }
  720. bdAddr[2] = pExtC2h->buf[0];
  721. bdAddr[1] = pExtC2h->buf[1];
  722. bdAddr[0] = pExtC2h->buf[2];
  723. RTW_INFO("[MPT], Connected Target BDAddr:%s", bdAddr);
  724. for (i = 0; i < 6; i++)
  725. pBtRsp->pParamStart[i] = bdAddr[5 - i];
  726. paraLen = 6;
  727. }
  728. break;
  729. default:
  730. pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  731. return paraLen;
  732. break;
  733. }
  734. }
  735. pBtRsp->status = BT_STATUS_SUCCESS;
  736. return paraLen;
  737. }
  738. u2Byte
  739. mptbt_BtSetGeneral(
  740. IN PADAPTER Adapter,
  741. IN PBT_REQ_CMD pBtReq,
  742. IN PBT_RSP_CMD pBtRsp
  743. )
  744. {
  745. u1Byte h2cParaBuf[6] = {0};
  746. u1Byte h2cParaLen = 0;
  747. u2Byte paraLen = 0;
  748. u1Byte retStatus = BT_STATUS_BT_OP_SUCCESS;
  749. u1Byte btOpcode;
  750. u1Byte btOpcodeVer = 0;
  751. u1Byte setType = 0;
  752. u2Byte setParaLen = 0, validParaLen = 0;
  753. u1Byte regType = 0, bdAddr[6] = {0}, calVal = 0;
  754. u4Byte regAddr = 0, regValue = 0;
  755. pu4Byte pu4Tmp;
  756. pu2Byte pu2Tmp;
  757. pu1Byte pu1Tmp;
  758. /* */
  759. /* check upper layer parameters */
  760. /* */
  761. /* check upper layer opcode version */
  762. if (pBtReq->opCodeVer != 1) {
  763. RTW_INFO("[MPT], Error!! Upper OP code version not match!!!\n");
  764. pBtRsp->status = BT_STATUS_OPCODE_U_VERSION_MISMATCH;
  765. return paraLen;
  766. }
  767. /* check upper layer parameter length */
  768. if (pBtReq->paraLength < 1) {
  769. RTW_INFO("[MPT], Error!! wrong parameter length=%d (should larger than 1)\n", pBtReq->paraLength);
  770. pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U;
  771. return paraLen;
  772. }
  773. setParaLen = pBtReq->paraLength - 1;
  774. setType = pBtReq->pParamStart[0];
  775. RTW_INFO("[MPT], setType=%d, setParaLen=%d\n", setType, setParaLen);
  776. /* check parameter first */
  777. switch (setType) {
  778. case BT_GSET_REG:
  779. RTW_INFO("[MPT], [BT_GSET_REG]\n");
  780. validParaLen = 9;
  781. if (setParaLen == validParaLen) {
  782. btOpcode = BT_LO_OP_WRITE_REG_VALUE;
  783. regType = pBtReq->pParamStart[1];
  784. pu4Tmp = (pu4Byte)&pBtReq->pParamStart[2];
  785. regAddr = *pu4Tmp;
  786. pu4Tmp = (pu4Byte)&pBtReq->pParamStart[6];
  787. regValue = *pu4Tmp;
  788. RTW_INFO("[MPT], BT_GSET_REG regType=0x%x, regAddr=0x%x, regValue=0x%x!!\n",
  789. regType, regAddr, regValue);
  790. if (regType >= BT_REG_MAX) {
  791. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  792. return paraLen;
  793. } else {
  794. if (((BT_REG_RF == regType) && (regAddr > 0x7f)) ||
  795. ((BT_REG_MODEM == regType) && (regAddr > 0x1ff)) ||
  796. ((BT_REG_BLUEWIZE == regType) && (regAddr > 0xfff)) ||
  797. ((BT_REG_VENDOR == regType) && (regAddr > 0xfff)) ||
  798. ((BT_REG_LE == regType) && (regAddr > 0xfff))) {
  799. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  800. return paraLen;
  801. }
  802. }
  803. }
  804. break;
  805. case BT_GSET_RESET:
  806. RTW_INFO("[MPT], [BT_GSET_RESET]\n");
  807. validParaLen = 0;
  808. break;
  809. case BT_GSET_TARGET_BD_ADDR:
  810. RTW_INFO("[MPT], [BT_GSET_TARGET_BD_ADDR]\n");
  811. validParaLen = 6;
  812. if (setParaLen == validParaLen) {
  813. btOpcode = BT_LO_OP_SET_TARGET_BD_ADDR_H;
  814. if ((pBtReq->pParamStart[1] == 0) &&
  815. (pBtReq->pParamStart[2] == 0) &&
  816. (pBtReq->pParamStart[3] == 0) &&
  817. (pBtReq->pParamStart[4] == 0) &&
  818. (pBtReq->pParamStart[5] == 0) &&
  819. (pBtReq->pParamStart[6] == 0)) {
  820. RTW_INFO("[MPT], Error!! targetBDAddr=all zero\n");
  821. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  822. return paraLen;
  823. }
  824. if ((pBtReq->pParamStart[1] == 0xff) &&
  825. (pBtReq->pParamStart[2] == 0xff) &&
  826. (pBtReq->pParamStart[3] == 0xff) &&
  827. (pBtReq->pParamStart[4] == 0xff) &&
  828. (pBtReq->pParamStart[5] == 0xff) &&
  829. (pBtReq->pParamStart[6] == 0xff)) {
  830. RTW_INFO("[MPT], Error!! targetBDAddr=all 0xf\n");
  831. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  832. return paraLen;
  833. }
  834. bdAddr[0] = pBtReq->pParamStart[6];
  835. bdAddr[1] = pBtReq->pParamStart[5];
  836. bdAddr[2] = pBtReq->pParamStart[4];
  837. bdAddr[3] = pBtReq->pParamStart[3];
  838. bdAddr[4] = pBtReq->pParamStart[2];
  839. bdAddr[5] = pBtReq->pParamStart[1];
  840. RTW_INFO("[MPT], target BDAddr:%x,%x,%x,%x,%x,%x\n",
  841. bdAddr[0], bdAddr[1], bdAddr[2], bdAddr[3], bdAddr[4], bdAddr[5]);
  842. }
  843. break;
  844. case BT_GSET_TX_PWR_FINETUNE:
  845. RTW_INFO("[MPT], [BT_GSET_TX_PWR_FINETUNE]\n");
  846. validParaLen = 1;
  847. if (setParaLen == validParaLen) {
  848. btOpcode = BT_LO_OP_SET_TX_POWER_CALIBRATION;
  849. calVal = pBtReq->pParamStart[1];
  850. if ((calVal < 1) || (calVal > 9)) {
  851. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  852. return paraLen;
  853. }
  854. RTW_INFO("[MPT], calVal=%d\n", calVal);
  855. }
  856. break;
  857. case BT_SET_TRACKING_INTERVAL:
  858. RTW_INFO("[MPT], [BT_SET_TRACKING_INTERVAL] setParaLen =%d\n", setParaLen);
  859. validParaLen = 1;
  860. if (setParaLen == validParaLen)
  861. calVal = pBtReq->pParamStart[1];
  862. break;
  863. case BT_SET_THERMAL_METER:
  864. RTW_INFO("[MPT], [BT_SET_THERMAL_METER] setParaLen =%d\n", setParaLen);
  865. validParaLen = 1;
  866. if (setParaLen == validParaLen)
  867. calVal = pBtReq->pParamStart[1];
  868. break;
  869. case BT_ENABLE_CFO_TRACKING:
  870. RTW_INFO("[MPT], [BT_ENABLE_CFO_TRACKING] setParaLen =%d\n", setParaLen);
  871. validParaLen = 1;
  872. if (setParaLen == validParaLen)
  873. calVal = pBtReq->pParamStart[1];
  874. break;
  875. case BT_GSET_UPDATE_BT_PATCH:
  876. break;
  877. default: {
  878. RTW_INFO("[MPT], Error!! setType=%d, out of range\n", setType);
  879. pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  880. return paraLen;
  881. }
  882. break;
  883. }
  884. if (setParaLen != validParaLen) {
  885. RTW_INFO("[MPT], Error!! wrong parameter length=%d for BT_SET_GEN_CMD cmd id=0x%x, paraLen should=0x%x\n",
  886. setParaLen, setType, validParaLen);
  887. pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U;
  888. return paraLen;
  889. }
  890. /* */
  891. /* execute lower layer opcodes */
  892. /* */
  893. if (BT_GSET_REG == setType) {
  894. /* fill h2c parameters */
  895. /* here we should write reg value first then write the address, adviced by Austin */
  896. btOpcode = BT_LO_OP_WRITE_REG_VALUE;
  897. h2cParaBuf[0] = pBtReq->pParamStart[6];
  898. h2cParaBuf[1] = pBtReq->pParamStart[7];
  899. h2cParaBuf[2] = pBtReq->pParamStart[8];
  900. h2cParaLen = 3;
  901. /* execute h2c and check respond c2h from bt fw is correct or not */
  902. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  903. /* construct respond status code and data. */
  904. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  905. pBtRsp->status = ((btOpcode << 8) | retStatus);
  906. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  907. return paraLen;
  908. }
  909. /* write reg address */
  910. btOpcode = BT_LO_OP_WRITE_REG_ADDR;
  911. h2cParaBuf[0] = regType;
  912. h2cParaBuf[1] = pBtReq->pParamStart[2];
  913. h2cParaBuf[2] = pBtReq->pParamStart[3];
  914. h2cParaLen = 3;
  915. /* execute h2c and check respond c2h from bt fw is correct or not */
  916. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  917. /* construct respond status code and data. */
  918. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  919. pBtRsp->status = ((btOpcode << 8) | retStatus);
  920. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  921. return paraLen;
  922. }
  923. } else if (BT_GSET_RESET == setType) {
  924. btOpcode = BT_LO_OP_RESET;
  925. h2cParaLen = 0;
  926. /* execute h2c and check respond c2h from bt fw is correct or not */
  927. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  928. /* construct respond status code and data. */
  929. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  930. pBtRsp->status = ((btOpcode << 8) | retStatus);
  931. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  932. return paraLen;
  933. }
  934. } else if (BT_GSET_TARGET_BD_ADDR == setType) {
  935. /* fill h2c parameters */
  936. btOpcode = BT_LO_OP_SET_TARGET_BD_ADDR_L;
  937. h2cParaBuf[0] = pBtReq->pParamStart[1];
  938. h2cParaBuf[1] = pBtReq->pParamStart[2];
  939. h2cParaBuf[2] = pBtReq->pParamStart[3];
  940. h2cParaLen = 3;
  941. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  942. /* ckeck bt return status. */
  943. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  944. pBtRsp->status = ((btOpcode << 8) | retStatus);
  945. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  946. return paraLen;
  947. }
  948. btOpcode = BT_LO_OP_SET_TARGET_BD_ADDR_H;
  949. h2cParaBuf[0] = pBtReq->pParamStart[4];
  950. h2cParaBuf[1] = pBtReq->pParamStart[5];
  951. h2cParaBuf[2] = pBtReq->pParamStart[6];
  952. h2cParaLen = 3;
  953. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  954. /* ckeck bt return status. */
  955. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  956. pBtRsp->status = ((btOpcode << 8) | retStatus);
  957. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  958. return paraLen;
  959. }
  960. } else if (BT_GSET_TX_PWR_FINETUNE == setType) {
  961. /* fill h2c parameters */
  962. btOpcode = BT_LO_OP_SET_TX_POWER_CALIBRATION;
  963. h2cParaBuf[0] = calVal;
  964. h2cParaLen = 1;
  965. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  966. /* ckeck bt return status. */
  967. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  968. pBtRsp->status = ((btOpcode << 8) | retStatus);
  969. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  970. return paraLen;
  971. }
  972. } else if (BT_SET_TRACKING_INTERVAL == setType) {
  973. /* BT_LO_OP_SET_TRACKING_INTERVAL = 0x22, */
  974. /* BT_LO_OP_SET_THERMAL_METER = 0x23, */
  975. /* BT_LO_OP_ENABLE_CFO_TRACKING = 0x24, */
  976. btOpcode = BT_LO_OP_SET_TRACKING_INTERVAL;
  977. h2cParaBuf[0] = calVal;
  978. h2cParaLen = 1;
  979. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  980. /* ckeck bt return status. */
  981. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  982. pBtRsp->status = ((btOpcode << 8) | retStatus);
  983. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  984. return paraLen;
  985. }
  986. } else if (BT_SET_THERMAL_METER == setType) {
  987. btOpcode = BT_LO_OP_SET_THERMAL_METER;
  988. h2cParaBuf[0] = calVal;
  989. h2cParaLen = 1;
  990. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  991. /* ckeck bt return status. */
  992. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  993. pBtRsp->status = ((btOpcode << 8) | retStatus);
  994. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  995. return paraLen;
  996. }
  997. } else if (BT_ENABLE_CFO_TRACKING == setType) {
  998. btOpcode = BT_LO_OP_ENABLE_CFO_TRACKING;
  999. h2cParaBuf[0] = calVal;
  1000. h2cParaLen = 1;
  1001. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1002. /* ckeck bt return status. */
  1003. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1004. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1005. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1006. return paraLen;
  1007. }
  1008. }
  1009. pBtRsp->status = BT_STATUS_SUCCESS;
  1010. return paraLen;
  1011. }
  1012. u2Byte
  1013. mptbt_BtSetTxRxPars(
  1014. IN PADAPTER Adapter,
  1015. IN PBT_REQ_CMD pBtReq,
  1016. IN PBT_RSP_CMD pBtRsp
  1017. )
  1018. {
  1019. u1Byte h2cParaBuf[6] = {0};
  1020. u1Byte h2cParaLen = 0;
  1021. u2Byte paraLen = 0;
  1022. u1Byte retStatus = BT_STATUS_BT_OP_SUCCESS;
  1023. u1Byte btOpcode;
  1024. u1Byte btOpcodeVer = 0;
  1025. PBT_TXRX_PARAMETERS pTxRxPars = (PBT_TXRX_PARAMETERS)&pBtReq->pParamStart[0];
  1026. u2Byte lenTxRx = sizeof(BT_TXRX_PARAMETERS);
  1027. u1Byte i;
  1028. u1Byte bdAddr[6] = {0};
  1029. /* */
  1030. /* check upper layer parameters */
  1031. /* */
  1032. /* 1. check upper layer opcode version */
  1033. if (pBtReq->opCodeVer != 1) {
  1034. RTW_INFO("[MPT], Error!! Upper OP code version not match!!!\n");
  1035. pBtRsp->status = BT_STATUS_OPCODE_U_VERSION_MISMATCH;
  1036. return paraLen;
  1037. }
  1038. /* 2. check upper layer parameter length */
  1039. if (pBtReq->paraLength == sizeof(BT_TXRX_PARAMETERS)) {
  1040. RTW_INFO("[MPT], pTxRxPars->txrxChannel=0x%x\n", pTxRxPars->txrxChannel);
  1041. RTW_INFO("[MPT], pTxRxPars->txrxTxPktCnt=0x%8x\n", pTxRxPars->txrxTxPktCnt);
  1042. RTW_INFO("[MPT], pTxRxPars->txrxTxPktInterval=0x%x\n", pTxRxPars->txrxTxPktInterval);
  1043. RTW_INFO("[MPT], pTxRxPars->txrxPayloadType=0x%x\n", pTxRxPars->txrxPayloadType);
  1044. RTW_INFO("[MPT], pTxRxPars->txrxPktType=0x%x\n", pTxRxPars->txrxPktType);
  1045. RTW_INFO("[MPT], pTxRxPars->txrxPayloadLen=0x%x\n", pTxRxPars->txrxPayloadLen);
  1046. RTW_INFO("[MPT], pTxRxPars->txrxPktHeader=0x%x\n", pTxRxPars->txrxPktHeader);
  1047. RTW_INFO("[MPT], pTxRxPars->txrxWhitenCoeff=0x%x\n", pTxRxPars->txrxWhitenCoeff);
  1048. bdAddr[0] = pTxRxPars->txrxBdaddr[5];
  1049. bdAddr[1] = pTxRxPars->txrxBdaddr[4];
  1050. bdAddr[2] = pTxRxPars->txrxBdaddr[3];
  1051. bdAddr[3] = pTxRxPars->txrxBdaddr[2];
  1052. bdAddr[4] = pTxRxPars->txrxBdaddr[1];
  1053. bdAddr[5] = pTxRxPars->txrxBdaddr[0];
  1054. RTW_INFO("[MPT], pTxRxPars->txrxBdaddr: %s", &bdAddr[0]);
  1055. RTW_INFO("[MPT], pTxRxPars->txrxTxGainIndex=0x%x\n", pTxRxPars->txrxTxGainIndex);
  1056. } else {
  1057. RTW_INFO("[MPT], Error!! pBtReq->paraLength=%d, correct Len=%d\n", pBtReq->paraLength, lenTxRx);
  1058. pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U;
  1059. return paraLen;
  1060. }
  1061. /* */
  1062. /* execute lower layer opcodes */
  1063. /* */
  1064. /* fill h2c parameters */
  1065. btOpcode = BT_LO_OP_SET_PKT_HEADER;
  1066. if (pTxRxPars->txrxPktHeader > 0x3ffff) {
  1067. RTW_INFO("[MPT], Error!! pTxRxPars->txrxPktHeader=0x%x is out of range, (should be between 0x0~0x3ffff)\n", pTxRxPars->txrxPktHeader);
  1068. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  1069. return paraLen;
  1070. } else {
  1071. h2cParaBuf[0] = (u1Byte)(pTxRxPars->txrxPktHeader & 0xff);
  1072. h2cParaBuf[1] = (u1Byte)((pTxRxPars->txrxPktHeader & 0xff00) >> 8);
  1073. h2cParaBuf[2] = (u1Byte)((pTxRxPars->txrxPktHeader & 0xff0000) >> 16);
  1074. h2cParaLen = 3;
  1075. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1076. }
  1077. /* ckeck bt return status. */
  1078. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1079. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1080. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1081. return paraLen;
  1082. }
  1083. /* fill h2c parameters */
  1084. btOpcode = BT_LO_OP_SET_PKT_TYPE_LEN;
  1085. {
  1086. u2Byte payloadLenLimit = 0;
  1087. switch (pTxRxPars->txrxPktType) {
  1088. case MP_BT_PKT_DH1:
  1089. payloadLenLimit = 27 * 8;
  1090. break;
  1091. case MP_BT_PKT_DH3:
  1092. payloadLenLimit = 183 * 8;
  1093. break;
  1094. case MP_BT_PKT_DH5:
  1095. payloadLenLimit = 339 * 8;
  1096. break;
  1097. case MP_BT_PKT_2DH1:
  1098. payloadLenLimit = 54 * 8;
  1099. break;
  1100. case MP_BT_PKT_2DH3:
  1101. payloadLenLimit = 367 * 8;
  1102. break;
  1103. case MP_BT_PKT_2DH5:
  1104. payloadLenLimit = 679 * 8;
  1105. break;
  1106. case MP_BT_PKT_3DH1:
  1107. payloadLenLimit = 83 * 8;
  1108. break;
  1109. case MP_BT_PKT_3DH3:
  1110. payloadLenLimit = 552 * 8;
  1111. break;
  1112. case MP_BT_PKT_3DH5:
  1113. payloadLenLimit = 1021 * 8;
  1114. break;
  1115. case MP_BT_PKT_LE:
  1116. payloadLenLimit = 39 * 8;
  1117. break;
  1118. default: {
  1119. RTW_INFO("[MPT], Error!! Unknown pTxRxPars->txrxPktType=0x%x\n", pTxRxPars->txrxPktType);
  1120. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  1121. return paraLen;
  1122. }
  1123. break;
  1124. }
  1125. if (pTxRxPars->txrxPayloadLen > payloadLenLimit) {
  1126. RTW_INFO("[MPT], Error!! pTxRxPars->txrxPayloadLen=0x%x, (should smaller than %d)\n",
  1127. pTxRxPars->txrxPayloadLen, payloadLenLimit);
  1128. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  1129. return paraLen;
  1130. }
  1131. h2cParaBuf[0] = pTxRxPars->txrxPktType;
  1132. h2cParaBuf[1] = (u1Byte)((pTxRxPars->txrxPayloadLen & 0xff));
  1133. h2cParaBuf[2] = (u1Byte)((pTxRxPars->txrxPayloadLen & 0xff00) >> 8);
  1134. h2cParaLen = 3;
  1135. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1136. }
  1137. /* ckeck bt return status. */
  1138. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1139. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1140. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1141. return paraLen;
  1142. }
  1143. /* fill h2c parameters */
  1144. btOpcode = BT_LO_OP_SET_PKT_CNT_L_PL_TYPE;
  1145. if (pTxRxPars->txrxPayloadType > MP_BT_PAYLOAD_MAX) {
  1146. RTW_INFO("[MPT], Error!! pTxRxPars->txrxPayloadType=0x%x, (should be between 0~4)\n", pTxRxPars->txrxPayloadType);
  1147. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  1148. return paraLen;
  1149. } else {
  1150. h2cParaBuf[0] = (u1Byte)((pTxRxPars->txrxTxPktCnt & 0xff));
  1151. h2cParaBuf[1] = (u1Byte)((pTxRxPars->txrxTxPktCnt & 0xff00) >> 8);
  1152. h2cParaBuf[2] = pTxRxPars->txrxPayloadType;
  1153. h2cParaLen = 3;
  1154. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1155. }
  1156. /* ckeck bt return status. */
  1157. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1158. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1159. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1160. return paraLen;
  1161. }
  1162. /* fill h2c parameters */
  1163. btOpcode = BT_LO_OP_SET_PKT_CNT_H_PKT_INTV;
  1164. if (pTxRxPars->txrxTxPktInterval > 15) {
  1165. RTW_INFO("[MPT], Error!! pTxRxPars->txrxTxPktInterval=0x%x, (should be between 0~15)\n", pTxRxPars->txrxTxPktInterval);
  1166. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  1167. return paraLen;
  1168. } else {
  1169. h2cParaBuf[0] = (u1Byte)((pTxRxPars->txrxTxPktCnt & 0xff0000) >> 16);
  1170. h2cParaBuf[1] = (u1Byte)((pTxRxPars->txrxTxPktCnt & 0xff000000) >> 24);
  1171. h2cParaBuf[2] = pTxRxPars->txrxTxPktInterval;
  1172. h2cParaLen = 3;
  1173. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1174. }
  1175. /* ckeck bt return status. */
  1176. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1177. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1178. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1179. return paraLen;
  1180. }
  1181. /* fill h2c parameters */
  1182. btOpcode = BT_LO_OP_SET_WHITENCOEFF;
  1183. {
  1184. h2cParaBuf[0] = pTxRxPars->txrxWhitenCoeff;
  1185. h2cParaLen = 1;
  1186. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1187. }
  1188. /* ckeck bt return status. */
  1189. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1190. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1191. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1192. return paraLen;
  1193. }
  1194. /* fill h2c parameters */
  1195. btOpcode = BT_LO_OP_SET_CHNL_TX_GAIN;
  1196. if ((pTxRxPars->txrxChannel > 78) ||
  1197. (pTxRxPars->txrxTxGainIndex > 7)) {
  1198. RTW_INFO("[MPT], Error!! pTxRxPars->txrxChannel=0x%x, (should be between 0~78)\n", pTxRxPars->txrxChannel);
  1199. RTW_INFO("[MPT], Error!! pTxRxPars->txrxTxGainIndex=0x%x, (should be between 0~7)\n", pTxRxPars->txrxTxGainIndex);
  1200. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  1201. return paraLen;
  1202. } else {
  1203. h2cParaBuf[0] = pTxRxPars->txrxChannel;
  1204. h2cParaBuf[1] = pTxRxPars->txrxTxGainIndex;
  1205. h2cParaLen = 2;
  1206. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1207. }
  1208. /* ckeck bt return status. */
  1209. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1210. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1211. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1212. return paraLen;
  1213. }
  1214. /* fill h2c parameters */
  1215. btOpcode = BT_LO_OP_SET_BD_ADDR_L;
  1216. if ((pTxRxPars->txrxBdaddr[0] == 0) &&
  1217. (pTxRxPars->txrxBdaddr[1] == 0) &&
  1218. (pTxRxPars->txrxBdaddr[2] == 0) &&
  1219. (pTxRxPars->txrxBdaddr[3] == 0) &&
  1220. (pTxRxPars->txrxBdaddr[4] == 0) &&
  1221. (pTxRxPars->txrxBdaddr[5] == 0)) {
  1222. RTW_INFO("[MPT], Error!! pTxRxPars->txrxBdaddr=all zero\n");
  1223. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  1224. return paraLen;
  1225. }
  1226. if ((pTxRxPars->txrxBdaddr[0] == 0xff) &&
  1227. (pTxRxPars->txrxBdaddr[1] == 0xff) &&
  1228. (pTxRxPars->txrxBdaddr[2] == 0xff) &&
  1229. (pTxRxPars->txrxBdaddr[3] == 0xff) &&
  1230. (pTxRxPars->txrxBdaddr[4] == 0xff) &&
  1231. (pTxRxPars->txrxBdaddr[5] == 0xff)) {
  1232. RTW_INFO("[MPT], Error!! pTxRxPars->txrxBdaddr=all 0xf\n");
  1233. pBtRsp->status = (btOpcode << 8) | BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  1234. return paraLen;
  1235. }
  1236. {
  1237. h2cParaBuf[0] = pTxRxPars->txrxBdaddr[0];
  1238. h2cParaBuf[1] = pTxRxPars->txrxBdaddr[1];
  1239. h2cParaBuf[2] = pTxRxPars->txrxBdaddr[2];
  1240. h2cParaLen = 3;
  1241. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1242. }
  1243. /* ckeck bt return status. */
  1244. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1245. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1246. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1247. return paraLen;
  1248. }
  1249. btOpcode = BT_LO_OP_SET_BD_ADDR_H;
  1250. {
  1251. h2cParaBuf[0] = pTxRxPars->txrxBdaddr[3];
  1252. h2cParaBuf[1] = pTxRxPars->txrxBdaddr[4];
  1253. h2cParaBuf[2] = pTxRxPars->txrxBdaddr[5];
  1254. h2cParaLen = 3;
  1255. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1256. }
  1257. /* ckeck bt return status. */
  1258. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1259. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1260. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1261. return paraLen;
  1262. }
  1263. pBtRsp->status = BT_STATUS_SUCCESS;
  1264. return paraLen;
  1265. }
  1266. u2Byte
  1267. mptbt_BtTestCtrl(
  1268. IN PADAPTER Adapter,
  1269. IN PBT_REQ_CMD pBtReq,
  1270. IN PBT_RSP_CMD pBtRsp
  1271. )
  1272. {
  1273. u1Byte h2cParaBuf[6] = {0};
  1274. u1Byte h2cParaLen = 0;
  1275. u2Byte paraLen = 0;
  1276. u1Byte retStatus = BT_STATUS_BT_OP_SUCCESS;
  1277. u1Byte btOpcode;
  1278. u1Byte btOpcodeVer = 0;
  1279. u1Byte testCtrl = 0;
  1280. /* */
  1281. /* check upper layer parameters */
  1282. /* */
  1283. /* 1. check upper layer opcode version */
  1284. if (pBtReq->opCodeVer != 1) {
  1285. RTW_INFO("[MPT], Error!! Upper OP code version not match!!!\n");
  1286. pBtRsp->status = BT_STATUS_OPCODE_U_VERSION_MISMATCH;
  1287. return paraLen;
  1288. }
  1289. /* 2. check upper layer parameter length */
  1290. if (1 == pBtReq->paraLength) {
  1291. testCtrl = pBtReq->pParamStart[0];
  1292. RTW_INFO("[MPT], testCtrl=%d\n", testCtrl);
  1293. } else {
  1294. RTW_INFO("[MPT], Error!! wrong parameter length=%d (should be 1)\n", pBtReq->paraLength);
  1295. pBtRsp->status = BT_STATUS_PARAMETER_FORMAT_ERROR_U;
  1296. return paraLen;
  1297. }
  1298. /* */
  1299. /* execute lower layer opcodes */
  1300. /* */
  1301. /* 1. fill h2c parameters */
  1302. /* check bt mode */
  1303. btOpcode = BT_LO_OP_TEST_CTRL;
  1304. if (testCtrl >= MP_BT_TEST_MAX) {
  1305. RTW_INFO("[MPT], Error!! testCtrl=0x%x, (should be between smaller or equal to 0x%x)\n",
  1306. testCtrl, MP_BT_TEST_MAX - 1);
  1307. pBtRsp->status = BT_STATUS_PARAMETER_OUT_OF_RANGE_U;
  1308. return paraLen;
  1309. } else {
  1310. h2cParaBuf[0] = testCtrl;
  1311. h2cParaLen = 1;
  1312. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen);
  1313. }
  1314. /* 3. construct respond status code and data. */
  1315. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1316. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1317. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1318. return paraLen;
  1319. }
  1320. pBtRsp->status = BT_STATUS_SUCCESS;
  1321. return paraLen;
  1322. }
  1323. u2Byte
  1324. mptbt_TestBT(
  1325. IN PADAPTER Adapter,
  1326. IN PBT_REQ_CMD pBtReq,
  1327. IN PBT_RSP_CMD pBtRsp
  1328. )
  1329. {
  1330. u1Byte h2cParaBuf[6] = {0};
  1331. u1Byte h2cParaLen = 0;
  1332. u2Byte paraLen = 0;
  1333. u1Byte retStatus = BT_STATUS_BT_OP_SUCCESS;
  1334. u1Byte btOpcode;
  1335. u1Byte btOpcodeVer = 0;
  1336. u1Byte testCtrl = 0;
  1337. /* 1. fill h2c parameters */
  1338. btOpcode = 0x11;
  1339. h2cParaBuf[0] = 0x11;
  1340. h2cParaBuf[1] = 0x0;
  1341. h2cParaBuf[2] = 0x0;
  1342. h2cParaBuf[3] = 0x0;
  1343. h2cParaBuf[4] = 0x0;
  1344. h2cParaLen = 1;
  1345. /* retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, &h2cParaBuf[0], h2cParaLen); */
  1346. retStatus = mptbt_BtFwOpCodeProcess(Adapter, btOpcode, btOpcodeVer, h2cParaBuf, h2cParaLen);
  1347. /* 3. construct respond status code and data. */
  1348. if (BT_STATUS_BT_OP_SUCCESS != retStatus) {
  1349. pBtRsp->status = ((btOpcode << 8) | retStatus);
  1350. RTW_INFO("[MPT], Error!! status code=0x%x\n", pBtRsp->status);
  1351. return paraLen;
  1352. }
  1353. pBtRsp->status = BT_STATUS_SUCCESS;
  1354. return paraLen;
  1355. }
  1356. VOID
  1357. mptbt_BtControlProcess(
  1358. PADAPTER Adapter,
  1359. PVOID pInBuf
  1360. )
  1361. {
  1362. u1Byte H2C_Parameter[6] = {0};
  1363. PBT_H2C pH2c = (PBT_H2C)&H2C_Parameter[0];
  1364. PMPT_CONTEXT pMptCtx = &(Adapter->mppriv.mpt_ctx);
  1365. PBT_REQ_CMD pBtReq = (PBT_REQ_CMD)pInBuf;
  1366. PBT_RSP_CMD pBtRsp;
  1367. u1Byte i;
  1368. RTW_INFO("[MPT], mptbt_BtControlProcess()=========>\n");
  1369. RTW_INFO("[MPT], input opCodeVer=%d\n", pBtReq->opCodeVer);
  1370. RTW_INFO("[MPT], input OpCode=%d\n", pBtReq->OpCode);
  1371. RTW_INFO("[MPT], paraLength=%d\n", pBtReq->paraLength);
  1372. if (pBtReq->paraLength) {
  1373. /* RTW_INFO("[MPT], parameters(hex):0x%x %d\n",&pBtReq->pParamStart[0], pBtReq->paraLength); */
  1374. }
  1375. _rtw_memset((void *)pMptCtx->mptOutBuf, 0, 100);
  1376. pMptCtx->mptOutLen = 4; /* length of (BT_RSP_CMD.status+BT_RSP_CMD.paraLength) */
  1377. pBtRsp = (PBT_RSP_CMD)pMptCtx->mptOutBuf;
  1378. pBtRsp->status = BT_STATUS_SUCCESS;
  1379. pBtRsp->paraLength = 0x0;
  1380. /* The following we should maintain the User OP codes sent by upper layer */
  1381. switch (pBtReq->OpCode) {
  1382. case BT_UP_OP_BT_READY:
  1383. RTW_INFO("[MPT], OPcode : [BT_READY]\n");
  1384. pBtRsp->paraLength = mptbt_BtReady(Adapter, pBtReq, pBtRsp);
  1385. break;
  1386. case BT_UP_OP_BT_SET_MODE:
  1387. RTW_INFO("[MPT], OPcode : [BT_SET_MODE]\n");
  1388. pBtRsp->paraLength = mptbt_BtSetMode(Adapter, pBtReq, pBtRsp);
  1389. break;
  1390. case BT_UP_OP_BT_SET_TX_RX_PARAMETER:
  1391. RTW_INFO("[MPT], OPcode : [BT_SET_TXRX_PARAMETER]\n");
  1392. pBtRsp->paraLength = mptbt_BtSetTxRxPars(Adapter, pBtReq, pBtRsp);
  1393. break;
  1394. case BT_UP_OP_BT_SET_GENERAL:
  1395. RTW_INFO("[MPT], OPcode : [BT_SET_GENERAL]\n");
  1396. pBtRsp->paraLength = mptbt_BtSetGeneral(Adapter, pBtReq, pBtRsp);
  1397. break;
  1398. case BT_UP_OP_BT_GET_GENERAL:
  1399. RTW_INFO("[MPT], OPcode : [BT_GET_GENERAL]\n");
  1400. pBtRsp->paraLength = mptbt_BtGetGeneral(Adapter, pBtReq, pBtRsp);
  1401. break;
  1402. case BT_UP_OP_BT_TEST_CTRL:
  1403. RTW_INFO("[MPT], OPcode : [BT_TEST_CTRL]\n");
  1404. pBtRsp->paraLength = mptbt_BtTestCtrl(Adapter, pBtReq, pBtRsp);
  1405. break;
  1406. case BT_UP_OP_TEST_BT:
  1407. RTW_INFO("[MPT], OPcode : [TEST_BT]\n");
  1408. pBtRsp->paraLength = mptbt_TestBT(Adapter, pBtReq, pBtRsp);
  1409. break;
  1410. default:
  1411. RTW_INFO("[MPT], Error!! OPcode : UNDEFINED!!!!\n");
  1412. pBtRsp->status = BT_STATUS_UNKNOWN_OPCODE_U;
  1413. pBtRsp->paraLength = 0x0;
  1414. break;
  1415. }
  1416. pMptCtx->mptOutLen += pBtRsp->paraLength;
  1417. RTW_INFO("[MPT], pMptCtx->mptOutLen=%d, pBtRsp->paraLength=%d\n", pMptCtx->mptOutLen, pBtRsp->paraLength);
  1418. RTW_INFO("[MPT], mptbt_BtControlProcess()<=========\n");
  1419. }
  1420. #endif