rtw_bt_mp.c 50 KB

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