cnm.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/cnm.c#2
  3. */
  4. /*! \file "cnm.c"
  5. \brief Module of Concurrent Network Management
  6. Module of Concurrent Network Management
  7. */
  8. /*
  9. ** Log: cnm.c
  10. **
  11. ** 06 26 2013 cm.chang
  12. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  13. ** For BSS_INFO alloc/free, Use fgIsInUse instead of fgIsNetActive
  14. **
  15. ** 05 07 2013 cm.chang
  16. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  17. ** Provide macro for TXM to query if BSS is CH_GRANTED
  18. **
  19. ** 01 21 2013 cm.chang
  20. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  21. ** 1. Create rP2pDevInfo structure
  22. ** 2. Support 80/160 MHz channel bandwidth for channel privilege
  23. **
  24. ** 01 17 2013 cm.chang
  25. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  26. ** Use ucBssIndex to replace eNetworkTypeIndex
  27. **
  28. ** 09 17 2012 cm.chang
  29. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  30. ** Duplicate source from MT6620 v2.3 driver branch
  31. ** (Davinci label: MT6620_WIFI_Driver_V2_3_120913_1942_As_MT6630_Base)
  32. *
  33. * 07 17 2012 yuche.tsai
  34. * NULL
  35. * Compile no error before trial run.
  36. *
  37. * 11 15 2011 cm.chang
  38. * NULL
  39. * Fix possible wrong message when P2P is unregistered
  40. *
  41. * 11 14 2011 yuche.tsai
  42. * [WCXRP00001107] [Volunteer Patch][Driver] Large Network Type index assert in FW issue.
  43. * Fix large network type index assert in FW issue.
  44. *
  45. * 11 10 2011 cm.chang
  46. * NULL
  47. * Modify debug message for XLOG
  48. *
  49. * 11 08 2011 cm.chang
  50. * NULL
  51. * Add RLM and CNM debug message for XLOG
  52. *
  53. * 11 01 2011 cm.chang
  54. * [WCXRP00001077] [All Wi-Fi][Driver] Fix wrong preferred channel for AP and BOW
  55. * Only check AIS channel for P2P and BOW
  56. *
  57. * 10 25 2011 cm.chang
  58. * [WCXRP00001058] [All Wi-Fi][Driver] Fix sta_rec's phyTypeSet and OBSS scan in AP mode
  59. * Extension channel of some 5G AP will not follow regulation requirement
  60. *
  61. * 09 30 2011 cm.chang
  62. * [WCXRP00001020] [MT6620 Wi-Fi][Driver] Handle secondary channel offset of AP in 5GHz band
  63. * .
  64. *
  65. * 09 01 2011 cm.chang
  66. * [WCXRP00000937] [MT6620 Wi-Fi][Driver][FW] cnm.c line #848 assert when doing monkey test
  67. * Print message only in Linux platform for monkey testing
  68. *
  69. * 06 23 2011 cp.wu
  70. * [WCXRP00000798] [MT6620 Wi-Fi][Firmware] Follow-ups for WAPI frequency offset workaround in firmware SCN module
  71. * change parameter name from PeerAddr to BSSID
  72. *
  73. * 06 20 2011 cp.wu
  74. * [WCXRP00000798] [MT6620 Wi-Fi][Firmware] Follow-ups for WAPI frequency offset workaround in firmware SCN module
  75. * 1. specify target's BSSID when requesting channel privilege.
  76. * 2. pass BSSID information to firmware domain
  77. *
  78. * 06 01 2011 cm.chang
  79. * [WCXRP00000756] [MT6620 Wi-Fi][Driver] 1. AIS follow channel of BOW 2. Provide legal channel function
  80. * Limit AIS to fixed channel same with BOW
  81. *
  82. * 04 12 2011 cm.chang
  83. * [WCXRP00000634] [MT6620 Wi-Fi][Driver][FW] 2nd BSS will not support 40MHz bandwidth for concurrency
  84. * .
  85. *
  86. * 03 10 2011 cm.chang
  87. * [WCXRP00000358] [MT6620 Wi-Fi][Driver] Provide concurrent information for each module
  88. * Check if P2P network index is Tethering AP
  89. *
  90. * 03 10 2011 cm.chang
  91. * [WCXRP00000358] [MT6620 Wi-Fi][Driver] Provide concurrent information for each module
  92. * Add some functions to let AIS/Tethering or AIS/BOW be the same channel
  93. *
  94. * 02 17 2011 cm.chang
  95. * [WCXRP00000358] [MT6620 Wi-Fi][Driver] Provide concurrent information for each module
  96. * When P2P registried, invoke BOW deactivate function
  97. *
  98. * 01 12 2011 cm.chang
  99. * [WCXRP00000358] [MT6620 Wi-Fi][Driver] Provide concurrent information for each module
  100. * Provide function to decide if BSS can be activated or not
  101. *
  102. * 12 07 2010 cm.chang
  103. * [WCXRP00000239] MT6620 Wi-Fi][Driver][FW] Merge concurrent branch back to maintrunk
  104. * 1. BSSINFO include RLM parameter
  105. * 2. free all sta records when network is disconnected
  106. *
  107. * 12 07 2010 cm.chang
  108. * [WCXRP00000238] MT6620 Wi-Fi][Driver][FW] Support regulation domain setting from NVRAM and supplicant
  109. * 1. Country code is from NVRAM or supplicant
  110. * 2. Change band definition in CMD/EVENT.
  111. *
  112. * 11 08 2010 cm.chang
  113. * [WCXRP00000169] [MT6620 Wi-Fi][Driver][FW] Remove unused CNM recover message ID
  114. * Remove CNM channel reover message ID
  115. *
  116. * 10 13 2010 cm.chang
  117. * [WCXRP00000094] [MT6620 Wi-Fi][Driver] Connect to 2.4GHz AP, Driver crash.
  118. * Add exception handle when cmd buffer is not available
  119. *
  120. * 08 24 2010 cm.chang
  121. * NULL
  122. * Support RLM initail channel of Ad-hoc, P2P and BOW
  123. *
  124. * 07 19 2010 wh.su
  125. *
  126. * update for security supporting.
  127. *
  128. * 07 19 2010 cm.chang
  129. *
  130. * Set RLM parameters and enable CNM channel manager
  131. *
  132. * 07 08 2010 cp.wu
  133. *
  134. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  135. *
  136. * 07 08 2010 cm.chang
  137. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  138. * Rename MID_MNY_CNM_CH_RELEASE to MID_MNY_CNM_CH_ABORT
  139. *
  140. * 07 01 2010 cm.chang
  141. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  142. * Fix wrong message ID for channel grant to requester
  143. *
  144. * 07 01 2010 cm.chang
  145. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  146. * Modify CNM message handler for new flow
  147. *
  148. * 06 07 2010 cm.chang
  149. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  150. * Set 20/40M bandwidth of AP HT OP before association process
  151. *
  152. * 05 31 2010 yarco.yang
  153. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  154. * Add RX TSF Log Feature and ADDBA Rsp with DECLINE handling
  155. *
  156. * 05 21 2010 yarco.yang
  157. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  158. * Support TCP/UDP/IP Checksum offload feature
  159. *
  160. * 05 12 2010 kevin.huang
  161. * [BORA00000794][WIFISYS][New Feature]Power Management Support
  162. * Add Power Management - Legacy PS-POLL support.
  163. *
  164. * 05 05 2010 cm.chang
  165. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  166. * Add a new function to send abort message
  167. *
  168. * 04 27 2010 cm.chang
  169. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  170. * BMC mac address shall be ignored in basic config command
  171. *
  172. * 04 24 2010 cm.chang
  173. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  174. * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
  175. *
  176. * 04 22 2010 cm.chang
  177. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  178. * Support change of MAC address by host command
  179. *
  180. * 04 16 2010 wh.su
  181. * [BORA00000680][MT6620] Support the statistic for Microsoft os query
  182. * adding the wpa-none for ibss beacon.
  183. *
  184. * 04 07 2010 cm.chang
  185. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  186. * Fix bug for OBSS scan
  187. *
  188. * 03 30 2010 cm.chang
  189. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  190. * Support 2.4G OBSS scan
  191. *
  192. * 03 16 2010 kevin.huang
  193. * [BORA00000663][WIFISYS][New Feature] AdHoc Mode Support
  194. * Add AdHoc Mode
  195. *
  196. * 03 10 2010 kevin.huang
  197. * [BORA00000654][WIFISYS][New Feature] CNM Module - Ch Manager Support
  198. *
  199. * * * * * * * * * * Add Channel Manager for arbitration of JOIN and SCAN Req
  200. *
  201. * 02 25 2010 wh.su
  202. * [BORA00000605][WIFISYS] Phase3 Integration
  203. * use the Rx0 dor event indicate.
  204. *
  205. * 02 08 2010 cm.chang
  206. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  207. * Support partial part about cmd basic configuration
  208. *
  209. * Dec 10 2009 mtk01104
  210. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  211. * Remove conditional compiling FPGA_V5
  212. *
  213. * Nov 18 2009 mtk01104
  214. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  215. * Add function cnmFsmEventInit()
  216. *
  217. * Nov 2 2009 mtk01104
  218. * [BORA00000018] Integrate WIFI part into BORA for the 1st time
  219. *
  220. **
  221. */
  222. /*******************************************************************************
  223. * C O M P I L E R F L A G S
  224. ********************************************************************************
  225. */
  226. /*******************************************************************************
  227. * E X T E R N A L R E F E R E N C E S
  228. ********************************************************************************
  229. */
  230. #include "precomp.h"
  231. /*******************************************************************************
  232. * C O N S T A N T S
  233. ********************************************************************************
  234. */
  235. /*******************************************************************************
  236. * D A T A T Y P E S
  237. ********************************************************************************
  238. */
  239. /*******************************************************************************
  240. * P U B L I C D A T A
  241. ********************************************************************************
  242. */
  243. /*******************************************************************************
  244. * P R I V A T E D A T A
  245. ********************************************************************************
  246. */
  247. /*******************************************************************************
  248. * M A C R O S
  249. ********************************************************************************
  250. */
  251. /*******************************************************************************
  252. * F U N C T I O N D E C L A R A T I O N S
  253. ********************************************************************************
  254. */
  255. /*******************************************************************************
  256. * F U N C T I O N S
  257. ********************************************************************************
  258. */
  259. /*----------------------------------------------------------------------------*/
  260. /*!
  261. * @brief This function is used to initialize variables in CNM_INFO_T.
  262. *
  263. * @param (none)
  264. *
  265. * @return (none)
  266. */
  267. /*----------------------------------------------------------------------------*/
  268. VOID cnmInit(P_ADAPTER_T prAdapter)
  269. {
  270. P_CNM_INFO_T prCnmInfo;
  271. ASSERT(prAdapter);
  272. prCnmInfo = &prAdapter->rCnmInfo;
  273. prCnmInfo->fgChGranted = FALSE;
  274. } /* end of cnmInit() */
  275. /*----------------------------------------------------------------------------*/
  276. /*!
  277. * @brief This function is used to initialize variables in CNM_INFO_T.
  278. *
  279. * @param (none)
  280. *
  281. * @return (none)
  282. */
  283. /*----------------------------------------------------------------------------*/
  284. VOID cnmUninit(P_ADAPTER_T prAdapter)
  285. {
  286. } /* end of cnmUninit() */
  287. /*----------------------------------------------------------------------------*/
  288. /*!
  289. * @brief Before handle the message from other module, it need to obtain
  290. * the Channel privilege from Channel Manager
  291. *
  292. * @param[in] prMsgHdr The message need to be handled.
  293. *
  294. * @return (none)
  295. */
  296. /*----------------------------------------------------------------------------*/
  297. VOID cnmChMngrRequestPrivilege(P_ADAPTER_T prAdapter, P_MSG_HDR_T prMsgHdr)
  298. {
  299. P_MSG_CH_REQ_T prMsgChReq;
  300. P_CMD_CH_PRIVILEGE_T prCmdBody;
  301. WLAN_STATUS rStatus;
  302. ASSERT(prAdapter);
  303. ASSERT(prMsgHdr);
  304. prMsgChReq = (P_MSG_CH_REQ_T) prMsgHdr;
  305. prCmdBody = (P_CMD_CH_PRIVILEGE_T)
  306. cnmMemAlloc(prAdapter, RAM_TYPE_BUF, sizeof(CMD_CH_PRIVILEGE_T));
  307. ASSERT(prCmdBody);
  308. /* To do: exception handle */
  309. if (!prCmdBody) {
  310. DBGLOG(CNM, ERROR, "ChReq: fail to get buf (net=%d, token=%d)\n",
  311. prMsgChReq->ucBssIndex, prMsgChReq->ucTokenID);
  312. cnmMemFree(prAdapter, prMsgHdr);
  313. return;
  314. }
  315. DBGLOG(CNM, INFO, "ChReq net=%d token=%d b=%d c=%d s=%d w=%d\n",
  316. prMsgChReq->ucBssIndex, prMsgChReq->ucTokenID,
  317. prMsgChReq->eRfBand, prMsgChReq->ucPrimaryChannel,
  318. prMsgChReq->eRfSco, prMsgChReq->eRfChannelWidth);
  319. prCmdBody->ucBssIndex = prMsgChReq->ucBssIndex;
  320. prCmdBody->ucTokenID = prMsgChReq->ucTokenID;
  321. prCmdBody->ucAction = CMD_CH_ACTION_REQ; /* Request */
  322. prCmdBody->ucPrimaryChannel = prMsgChReq->ucPrimaryChannel;
  323. prCmdBody->ucRfSco = (UINT_8) prMsgChReq->eRfSco;
  324. prCmdBody->ucRfBand = (UINT_8) prMsgChReq->eRfBand;
  325. prCmdBody->ucRfChannelWidth = (UINT_8) prMsgChReq->eRfChannelWidth;
  326. prCmdBody->ucRfCenterFreqSeg1 = (UINT_8) prMsgChReq->ucRfCenterFreqSeg1;
  327. prCmdBody->ucRfCenterFreqSeg2 = (UINT_8) prMsgChReq->ucRfCenterFreqSeg2;
  328. prCmdBody->ucReqType = (UINT_8) prMsgChReq->eReqType;
  329. prCmdBody->aucReserved[0] = 0;
  330. prCmdBody->aucReserved[1] = 0;
  331. prCmdBody->u4MaxInterval = prMsgChReq->u4MaxInterval;
  332. ASSERT(prCmdBody->ucBssIndex <= MAX_BSS_INDEX);
  333. /* For monkey testing 20110901 */
  334. if (prCmdBody->ucBssIndex > MAX_BSS_INDEX)
  335. DBGLOG(CNM, ERROR, "CNM: ChReq with wrong netIdx=%d\n\n", prCmdBody->ucBssIndex);
  336. rStatus = wlanSendSetQueryCmd(prAdapter, /* prAdapter */
  337. CMD_ID_CH_PRIVILEGE, /* ucCID */
  338. TRUE, /* fgSetQuery */
  339. FALSE, /* fgNeedResp */
  340. FALSE, /* fgIsOid */
  341. NULL, /* pfCmdDoneHandler */
  342. NULL, /* pfCmdTimeoutHandler */
  343. sizeof(CMD_CH_PRIVILEGE_T), /* u4SetQueryInfoLen */
  344. (PUINT_8) prCmdBody, /* pucInfoBuffer */
  345. NULL, /* pvSetQueryBuffer */
  346. 0 /* u4SetQueryBufferLen */
  347. );
  348. /* ASSERT(rStatus == WLAN_STATUS_PENDING); */
  349. cnmMemFree(prAdapter, prCmdBody);
  350. cnmMemFree(prAdapter, prMsgHdr);
  351. } /* end of cnmChMngrRequestPrivilege() */
  352. /*----------------------------------------------------------------------------*/
  353. /*!
  354. * @brief Before deliver the message to other module, it need to release
  355. * the Channel privilege to Channel Manager.
  356. *
  357. * @param[in] prMsgHdr The message need to be delivered
  358. *
  359. * @return (none)
  360. */
  361. /*----------------------------------------------------------------------------*/
  362. VOID cnmChMngrAbortPrivilege(P_ADAPTER_T prAdapter, P_MSG_HDR_T prMsgHdr)
  363. {
  364. P_MSG_CH_ABORT_T prMsgChAbort;
  365. P_CMD_CH_PRIVILEGE_T prCmdBody;
  366. P_CNM_INFO_T prCnmInfo;
  367. WLAN_STATUS rStatus;
  368. ASSERT(prAdapter);
  369. ASSERT(prMsgHdr);
  370. prMsgChAbort = (P_MSG_CH_ABORT_T) prMsgHdr;
  371. /* Check if being granted channel privilege is aborted */
  372. prCnmInfo = &prAdapter->rCnmInfo;
  373. if (prCnmInfo->fgChGranted &&
  374. prCnmInfo->ucBssIndex == prMsgChAbort->ucBssIndex && prCnmInfo->ucTokenID == prMsgChAbort->ucTokenID) {
  375. prCnmInfo->fgChGranted = FALSE;
  376. }
  377. prCmdBody = (P_CMD_CH_PRIVILEGE_T)
  378. cnmMemAlloc(prAdapter, RAM_TYPE_BUF, sizeof(CMD_CH_PRIVILEGE_T));
  379. ASSERT(prCmdBody);
  380. /* To do: exception handle */
  381. if (!prCmdBody) {
  382. DBGLOG(CNM, ERROR, "ChAbort: fail to get buf (net=%d, token=%d)\n",
  383. prMsgChAbort->ucBssIndex, prMsgChAbort->ucTokenID);
  384. cnmMemFree(prAdapter, prMsgHdr);
  385. return;
  386. }
  387. prCmdBody->ucBssIndex = prMsgChAbort->ucBssIndex;
  388. prCmdBody->ucTokenID = prMsgChAbort->ucTokenID;
  389. prCmdBody->ucAction = CMD_CH_ACTION_ABORT; /* Abort */
  390. DBGLOG(CNM, INFO, "ChAbort net=%d token=%d\n", prCmdBody->ucBssIndex, prCmdBody->ucTokenID);
  391. ASSERT(prCmdBody->ucBssIndex <= MAX_BSS_INDEX);
  392. /* For monkey testing 20110901 */
  393. if (prCmdBody->ucBssIndex > MAX_BSS_INDEX)
  394. DBGLOG(CNM, ERROR, "CNM: ChAbort with wrong netIdx=%d\n\n", prCmdBody->ucBssIndex);
  395. rStatus = wlanSendSetQueryCmd(prAdapter, /* prAdapter */
  396. CMD_ID_CH_PRIVILEGE, /* ucCID */
  397. TRUE, /* fgSetQuery */
  398. FALSE, /* fgNeedResp */
  399. FALSE, /* fgIsOid */
  400. NULL, /* pfCmdDoneHandler */
  401. NULL, /* pfCmdTimeoutHandler */
  402. sizeof(CMD_CH_PRIVILEGE_T), /* u4SetQueryInfoLen */
  403. (PUINT_8) prCmdBody, /* pucInfoBuffer */
  404. NULL, /* pvSetQueryBuffer */
  405. 0 /* u4SetQueryBufferLen */
  406. );
  407. /* ASSERT(rStatus == WLAN_STATUS_PENDING); */
  408. cnmMemFree(prAdapter, prCmdBody);
  409. cnmMemFree(prAdapter, prMsgHdr);
  410. } /* end of cnmChMngrAbortPrivilege() */
  411. /*----------------------------------------------------------------------------*/
  412. /*!
  413. * @brief
  414. *
  415. * @param (none)
  416. *
  417. * @return (none)
  418. */
  419. /*----------------------------------------------------------------------------*/
  420. VOID cnmChMngrHandleChEvent(P_ADAPTER_T prAdapter, P_WIFI_EVENT_T prEvent)
  421. {
  422. P_EVENT_CH_PRIVILEGE_T prEventBody;
  423. P_MSG_CH_GRANT_T prChResp;
  424. P_BSS_INFO_T prBssInfo;
  425. P_CNM_INFO_T prCnmInfo;
  426. ASSERT(prAdapter);
  427. ASSERT(prEvent);
  428. prEventBody = (P_EVENT_CH_PRIVILEGE_T) (prEvent->aucBuffer);
  429. prChResp = (P_MSG_CH_GRANT_T)
  430. cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_CH_GRANT_T));
  431. ASSERT(prChResp);
  432. /* To do: exception handle */
  433. if (!prChResp) {
  434. DBGLOG(CNM, ERROR, "ChGrant: fail to get buf (net=%d, token=%d)\n",
  435. prEventBody->ucBssIndex, prEventBody->ucTokenID);
  436. return;
  437. }
  438. DBGLOG(CNM, INFO, "ChGrant net=%d token=%d ch=%d sco=%d\n",
  439. prEventBody->ucBssIndex, prEventBody->ucTokenID,
  440. prEventBody->ucPrimaryChannel, prEventBody->ucRfSco);
  441. ASSERT(prEventBody->ucBssIndex <= MAX_BSS_INDEX);
  442. ASSERT(prEventBody->ucStatus == EVENT_CH_STATUS_GRANT);
  443. prBssInfo = prAdapter->aprBssInfo[prEventBody->ucBssIndex];
  444. /* Decide message ID based on network and response status */
  445. if (IS_BSS_AIS(prBssInfo))
  446. prChResp->rMsgHdr.eMsgId = MID_CNM_AIS_CH_GRANT;
  447. #if CFG_ENABLE_WIFI_DIRECT
  448. else if (prAdapter->fgIsP2PRegistered && IS_BSS_P2P(prBssInfo))
  449. prChResp->rMsgHdr.eMsgId = MID_CNM_P2P_CH_GRANT;
  450. #endif
  451. #if CFG_ENABLE_BT_OVER_WIFI
  452. else if (IS_BSS_BOW(prBssInfo))
  453. prChResp->rMsgHdr.eMsgId = MID_CNM_BOW_CH_GRANT;
  454. #endif
  455. else {
  456. cnmMemFree(prAdapter, prChResp);
  457. return;
  458. }
  459. prChResp->ucBssIndex = prEventBody->ucBssIndex;
  460. prChResp->ucTokenID = prEventBody->ucTokenID;
  461. prChResp->ucPrimaryChannel = prEventBody->ucPrimaryChannel;
  462. prChResp->eRfSco = (ENUM_CHNL_EXT_T) prEventBody->ucRfSco;
  463. prChResp->eRfBand = (ENUM_BAND_T) prEventBody->ucRfBand;
  464. prChResp->eRfChannelWidth = (ENUM_CHANNEL_WIDTH_T) prEventBody->ucRfChannelWidth;
  465. prChResp->ucRfCenterFreqSeg1 = prEventBody->ucRfCenterFreqSeg1;
  466. prChResp->ucRfCenterFreqSeg2 = prEventBody->ucRfCenterFreqSeg2;
  467. prChResp->eReqType = (ENUM_CH_REQ_TYPE_T) prEventBody->ucReqType;
  468. prChResp->u4GrantInterval = prEventBody->u4GrantInterval;
  469. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prChResp, MSG_SEND_METHOD_BUF);
  470. /* Record current granted BSS for TXM's reference */
  471. prCnmInfo = &prAdapter->rCnmInfo;
  472. prCnmInfo->ucBssIndex = prEventBody->ucBssIndex;
  473. prCnmInfo->ucTokenID = prEventBody->ucTokenID;
  474. prCnmInfo->fgChGranted = TRUE;
  475. }
  476. /*----------------------------------------------------------------------------*/
  477. /*!
  478. * @brief This function is invoked for P2P or BOW networks
  479. *
  480. * @param (none)
  481. *
  482. * @return TRUE: suggest to adopt the returned preferred channel
  483. * FALSE: No suggestion. Caller should adopt its preference
  484. */
  485. /*----------------------------------------------------------------------------*/
  486. BOOLEAN
  487. cnmPreferredChannel(P_ADAPTER_T prAdapter, P_ENUM_BAND_T prBand, PUINT_8 pucPrimaryChannel, P_ENUM_CHNL_EXT_T prBssSCO)
  488. {
  489. P_BSS_INFO_T prBssInfo;
  490. UINT_8 i;
  491. ASSERT(prAdapter);
  492. ASSERT(prBand);
  493. ASSERT(pucPrimaryChannel);
  494. ASSERT(prBssSCO);
  495. for (i = 0; i < BSS_INFO_NUM; i++) {
  496. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, i);
  497. if (prBssInfo) {
  498. if (IS_BSS_AIS(prBssInfo) && RLM_NET_PARAM_VALID(prBssInfo)) {
  499. *prBand = prBssInfo->eBand;
  500. *pucPrimaryChannel = prBssInfo->ucPrimaryChannel;
  501. *prBssSCO = prBssInfo->eBssSCO;
  502. return TRUE;
  503. }
  504. }
  505. }
  506. return FALSE;
  507. }
  508. /*----------------------------------------------------------------------------*/
  509. /*!
  510. * @brief
  511. *
  512. * @param (none)
  513. *
  514. * @return TRUE: available channel is limited to return value
  515. * FALSE: no limited
  516. */
  517. /*----------------------------------------------------------------------------*/
  518. BOOLEAN cnmAisInfraChannelFixed(P_ADAPTER_T prAdapter, P_ENUM_BAND_T prBand, PUINT_8 pucPrimaryChannel)
  519. {
  520. P_BSS_INFO_T prBssInfo;
  521. UINT_8 i;
  522. ASSERT(prAdapter);
  523. for (i = 0; i < BSS_INFO_NUM; i++) {
  524. prBssInfo = prAdapter->aprBssInfo[i];
  525. #if 0
  526. DBGLOG(INIT, INFO, "%s BSS[%u] active[%u] netType[%u]\n",
  527. __func__, i, prBssInfo->fgIsNetActive, prBssInfo->eNetworkType;
  528. #endif
  529. if (!IS_NET_ACTIVE(prAdapter, i))
  530. continue;
  531. #if CFG_ENABLE_WIFI_DIRECT
  532. if (prBssInfo->eNetworkType == NETWORK_TYPE_P2P) {
  533. BOOLEAN fgFixedChannel = p2pFuncIsAPMode(prAdapter->rWifiVar.prP2PConnSettings);
  534. if (fgFixedChannel) {
  535. *prBand = prBssInfo->eBand;
  536. *pucPrimaryChannel = prBssInfo->ucPrimaryChannel;
  537. return TRUE;
  538. }
  539. }
  540. #endif
  541. #if CFG_ENABLE_BT_OVER_WIFI && CFG_BOW_LIMIT_AIS_CHNL
  542. if (prBssInfo->eNetworkType == NETWORK_TYPE_BOW) {
  543. *prBand = prBssInfo->eBand;
  544. *pucPrimaryChannel = prBssInfo->ucPrimaryChannel;
  545. return TRUE;
  546. }
  547. #endif
  548. }
  549. return FALSE;
  550. }
  551. #if CFG_SUPPORT_CHNL_CONFLICT_REVISE
  552. BOOLEAN cnmAisDetectP2PChannel(P_ADAPTER_T prAdapter, P_ENUM_BAND_T prBand, PUINT_8 pucPrimaryChannel)
  553. {
  554. UINT_8 i = 0;
  555. P_BSS_INFO_T prBssInfo;
  556. #if CFG_ENABLE_WIFI_DIRECT
  557. for (; i < BSS_INFO_NUM; i++) {
  558. prBssInfo = prAdapter->aprBssInfo[i];
  559. if (prBssInfo->eNetworkType != NETWORK_TYPE_P2P)
  560. continue;
  561. if (prBssInfo->eConnectionState == PARAM_MEDIA_STATE_CONNECTED ||
  562. (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT && prBssInfo->eIntendOPMode == OP_MODE_NUM)) {
  563. *prBand = prBssInfo->eBand;
  564. *pucPrimaryChannel = prBssInfo->ucPrimaryChannel;
  565. return TRUE;
  566. }
  567. }
  568. #endif
  569. return FALSE;
  570. }
  571. #endif
  572. /*----------------------------------------------------------------------------*/
  573. /*!
  574. * @brief
  575. *
  576. * @param (none)
  577. *
  578. * @return (none)
  579. */
  580. /*----------------------------------------------------------------------------*/
  581. VOID cnmAisInfraConnectNotify(P_ADAPTER_T prAdapter)
  582. {
  583. #if CFG_ENABLE_BT_OVER_WIFI
  584. P_BSS_INFO_T prBssInfo, prAisBssInfo, prBowBssInfo;
  585. UINT_8 i;
  586. ASSERT(prAdapter);
  587. prAisBssInfo = NULL;
  588. prBowBssInfo = NULL;
  589. for (i = 0; i < BSS_INFO_NUM; i++) {
  590. prBssInfo = prAdapter->aprBssInfo[i];
  591. if (prBssInfo && IS_BSS_ACTIVE(prBssInfo)) {
  592. if (IS_BSS_AIS(prBssInfo))
  593. prAisBssInfo = prBssInfo;
  594. else if (IS_BSS_BOW(prBssInfo))
  595. prBowBssInfo = prBssInfo;
  596. }
  597. }
  598. if (prAisBssInfo && prBowBssInfo && RLM_NET_PARAM_VALID(prAisBssInfo) && RLM_NET_PARAM_VALID(prBowBssInfo)) {
  599. if (prAisBssInfo->eBand != prBowBssInfo->eBand ||
  600. prAisBssInfo->ucPrimaryChannel != prBowBssInfo->ucPrimaryChannel) {
  601. /* Notify BOW to do deactivation */
  602. bowNotifyAllLinkDisconnected(prAdapter);
  603. }
  604. }
  605. #endif
  606. }
  607. /*----------------------------------------------------------------------------*/
  608. /*!
  609. * @brief
  610. *
  611. * @param (none)
  612. *
  613. * @return TRUE: permitted
  614. * FALSE: Not permitted
  615. */
  616. /*----------------------------------------------------------------------------*/
  617. BOOLEAN cnmAisIbssIsPermitted(P_ADAPTER_T prAdapter)
  618. {
  619. P_BSS_INFO_T prBssInfo;
  620. UINT_8 i;
  621. ASSERT(prAdapter);
  622. /* P2P device network shall be included */
  623. for (i = 0; i <= BSS_INFO_NUM; i++) {
  624. prBssInfo = prAdapter->aprBssInfo[i];
  625. if (prBssInfo && IS_BSS_ACTIVE(prBssInfo) && !IS_BSS_AIS(prBssInfo))
  626. return FALSE;
  627. }
  628. return TRUE;
  629. }
  630. /*----------------------------------------------------------------------------*/
  631. /*!
  632. * @brief
  633. *
  634. * @param (none)
  635. *
  636. * @return TRUE: permitted
  637. * FALSE: Not permitted
  638. */
  639. /*----------------------------------------------------------------------------*/
  640. BOOLEAN cnmP2PIsPermitted(P_ADAPTER_T prAdapter)
  641. {
  642. P_BSS_INFO_T prBssInfo;
  643. UINT_8 i;
  644. BOOLEAN fgBowIsActive;
  645. ASSERT(prAdapter);
  646. fgBowIsActive = FALSE;
  647. for (i = 0; i < BSS_INFO_NUM; i++) {
  648. prBssInfo = prAdapter->aprBssInfo[i];
  649. if (prBssInfo && IS_BSS_ACTIVE(prBssInfo)) {
  650. if (prBssInfo->eCurrentOPMode == OP_MODE_IBSS)
  651. return FALSE;
  652. else if (IS_BSS_BOW(prBssInfo))
  653. fgBowIsActive = TRUE;
  654. }
  655. }
  656. #if CFG_ENABLE_BT_OVER_WIFI
  657. if (fgBowIsActive) {
  658. /* Notify BOW to do deactivation */
  659. bowNotifyAllLinkDisconnected(prAdapter);
  660. }
  661. #endif
  662. return TRUE;
  663. }
  664. /*----------------------------------------------------------------------------*/
  665. /*!
  666. * @brief
  667. *
  668. * @param (none)
  669. *
  670. * @return TRUE: permitted
  671. * FALSE: Not permitted
  672. */
  673. /*----------------------------------------------------------------------------*/
  674. BOOLEAN cnmBowIsPermitted(P_ADAPTER_T prAdapter)
  675. {
  676. P_BSS_INFO_T prBssInfo;
  677. UINT_8 i;
  678. ASSERT(prAdapter);
  679. /* P2P device network shall be included */
  680. for (i = 0; i <= BSS_INFO_NUM; i++) {
  681. prBssInfo = prAdapter->aprBssInfo[i];
  682. if (prBssInfo && IS_BSS_ACTIVE(prBssInfo) &&
  683. (IS_BSS_P2P(prBssInfo) || prBssInfo->eCurrentOPMode == OP_MODE_IBSS)) {
  684. return FALSE;
  685. }
  686. }
  687. return TRUE;
  688. }
  689. /*----------------------------------------------------------------------------*/
  690. /*!
  691. * @brief
  692. *
  693. * @param (none)
  694. *
  695. * @return TRUE: permitted
  696. * FALSE: Not permitted
  697. */
  698. /*----------------------------------------------------------------------------*/
  699. BOOLEAN cnmBss40mBwPermitted(P_ADAPTER_T prAdapter, UINT_8 ucBssIndex)
  700. {
  701. ASSERT(prAdapter);
  702. /* Note: To support real-time decision instead of current activated-time,
  703. * the STA roaming case shall be considered about synchronization
  704. * problem. Another variable fgAssoc40mBwAllowed is added to
  705. * represent HT capability when association
  706. */
  707. /* Decide max bandwidth by feature option */
  708. if (cnmGetBssMaxBw(prAdapter, ucBssIndex) < MAX_BW_40MHZ)
  709. return FALSE;
  710. #if 0
  711. /* Decide max by other BSS */
  712. for (i = 0; i < BSS_INFO_NUM; i++) {
  713. if (i != ucBssIndex) {
  714. prBssInfo = prAdapter->aprBssInfo[i];
  715. if (prBssInfo && IS_BSS_ACTIVE(prBssInfo) &&
  716. (prBssInfo->fg40mBwAllowed || prBssInfo->fgAssoc40mBwAllowed))
  717. return FALSE;
  718. }
  719. }
  720. #endif
  721. return TRUE;
  722. }
  723. /*----------------------------------------------------------------------------*/
  724. /*!
  725. * @brief
  726. *
  727. * @param (none)
  728. *
  729. * @return TRUE: permitted
  730. * FALSE: Not permitted
  731. */
  732. /*----------------------------------------------------------------------------*/
  733. BOOLEAN cnmBss80mBwPermitted(P_ADAPTER_T prAdapter, UINT_8 ucBssIndex)
  734. {
  735. ASSERT(prAdapter);
  736. /* Note: To support real-time decision instead of current activated-time,
  737. * the STA roaming case shall be considered about synchronization
  738. * problem. Another variable fgAssoc40mBwAllowed is added to
  739. * represent HT capability when association
  740. */
  741. /* Check 40Mhz first */
  742. if (!cnmBss40mBwPermitted(prAdapter, ucBssIndex))
  743. return FALSE;
  744. /* Decide max bandwidth by feature option */
  745. if (cnmGetBssMaxBw(prAdapter, ucBssIndex) < MAX_BW_80MHZ)
  746. return FALSE;
  747. return TRUE;
  748. }
  749. UINT_8 cnmGetBssMaxBw(P_ADAPTER_T prAdapter, UINT_8 ucBssIndex)
  750. {
  751. P_BSS_INFO_T prBssInfo;
  752. UINT_8 ucMaxBandwidth = MAX_BW_80MHZ;
  753. prBssInfo = GET_BSS_INFO_BY_INDEX(prAdapter, ucBssIndex);
  754. if (IS_BSS_AIS(prBssInfo)) {
  755. /* STA mode */
  756. if (prBssInfo->eBand == BAND_2G4)
  757. ucMaxBandwidth = prAdapter->rWifiVar.ucSta2gBandwidth;
  758. else
  759. ucMaxBandwidth = prAdapter->rWifiVar.ucSta5gBandwidth;
  760. if (ucMaxBandwidth > prAdapter->rWifiVar.ucStaBandwidth)
  761. ucMaxBandwidth = prAdapter->rWifiVar.ucStaBandwidth;
  762. } else if (IS_BSS_P2P(prBssInfo)) {
  763. /* AP mode */
  764. if (p2pFuncIsAPMode(prAdapter->rWifiVar.prP2PConnSettings)) {
  765. if (prBssInfo->eBand == BAND_2G4)
  766. ucMaxBandwidth = prAdapter->rWifiVar.ucAp2gBandwidth;
  767. else
  768. ucMaxBandwidth = prAdapter->rWifiVar.ucAp5gBandwidth;
  769. }
  770. /* P2P mode */
  771. else {
  772. if (prBssInfo->eBand == BAND_2G4)
  773. ucMaxBandwidth = prAdapter->rWifiVar.ucP2p2gBandwidth;
  774. else
  775. ucMaxBandwidth = prAdapter->rWifiVar.ucP2p5gBandwidth;
  776. }
  777. }
  778. return ucMaxBandwidth;
  779. }
  780. /*----------------------------------------------------------------------------*/
  781. /*!
  782. * @brief Search available HW ID and BSS_INFO structure and initialize
  783. * these parameters, i.e., fgIsNetActive, ucBssIndex, eNetworkType
  784. * and ucOwnMacIndex
  785. *
  786. * @param (none)
  787. *
  788. * @return
  789. */
  790. /*----------------------------------------------------------------------------*/
  791. P_BSS_INFO_T cnmGetBssInfoAndInit(P_ADAPTER_T prAdapter, ENUM_NETWORK_TYPE_T eNetworkType, BOOLEAN fgIsP2pDevice)
  792. {
  793. P_BSS_INFO_T prBssInfo;
  794. UINT_8 ucBssIndex, ucOwnMacIdx;
  795. ASSERT(prAdapter);
  796. if (eNetworkType == NETWORK_TYPE_P2P && fgIsP2pDevice) {
  797. prBssInfo = prAdapter->aprBssInfo[P2P_DEV_BSS_INDEX];
  798. prBssInfo->fgIsInUse = TRUE;
  799. prBssInfo->ucBssIndex = P2P_DEV_BSS_INDEX;
  800. prBssInfo->eNetworkType = eNetworkType;
  801. prBssInfo->ucOwnMacIndex = HW_BSSID_NUM;
  802. #if CFG_SUPPORT_PNO
  803. prBssInfo->fgIsPNOEnable = FALSE;
  804. prBssInfo->fgIsNetRequestInActive = FALSE;
  805. #endif
  806. return prBssInfo;
  807. }
  808. if (wlanGetEcoVersion(prAdapter) == 1)
  809. ucOwnMacIdx = 0;
  810. else
  811. ucOwnMacIdx = (eNetworkType == NETWORK_TYPE_MBSS) ? 0 : 1;
  812. /* Find available HW set */
  813. do {
  814. for (ucBssIndex = 0; ucBssIndex < BSS_INFO_NUM; ucBssIndex++) {
  815. prBssInfo = prAdapter->aprBssInfo[ucBssIndex];
  816. if (prBssInfo && prBssInfo->fgIsInUse && ucOwnMacIdx == prBssInfo->ucOwnMacIndex)
  817. break;
  818. }
  819. if (ucBssIndex >= BSS_INFO_NUM)
  820. break; /* No hit */
  821. } while (++ucOwnMacIdx < HW_BSSID_NUM);
  822. /* Find available BSS_INFO */
  823. for (ucBssIndex = 0; ucBssIndex < BSS_INFO_NUM; ucBssIndex++) {
  824. prBssInfo = prAdapter->aprBssInfo[ucBssIndex];
  825. if (prBssInfo && !prBssInfo->fgIsInUse) {
  826. prBssInfo->fgIsInUse = TRUE;
  827. prBssInfo->ucBssIndex = ucBssIndex;
  828. prBssInfo->eNetworkType = eNetworkType;
  829. prBssInfo->ucOwnMacIndex = ucOwnMacIdx;
  830. break;
  831. }
  832. }
  833. if (ucOwnMacIdx >= HW_BSSID_NUM || ucBssIndex >= BSS_INFO_NUM)
  834. prBssInfo = NULL;
  835. #if CFG_SUPPORT_PNO
  836. if (prBssInfo) {
  837. prBssInfo->fgIsPNOEnable = FALSE;
  838. prBssInfo->fgIsNetRequestInActive = FALSE;
  839. }
  840. #endif
  841. return prBssInfo;
  842. }
  843. /*----------------------------------------------------------------------------*/
  844. /*!
  845. * @brief Search available HW ID and BSS_INFO structure and initialize
  846. * these parameters, i.e., ucBssIndex, eNetworkType and ucOwnMacIndex
  847. *
  848. * @param (none)
  849. *
  850. * @return
  851. */
  852. /*----------------------------------------------------------------------------*/
  853. VOID cnmFreeBssInfo(P_ADAPTER_T prAdapter, P_BSS_INFO_T prBssInfo)
  854. {
  855. ASSERT(prAdapter);
  856. ASSERT(prBssInfo);
  857. prBssInfo->fgIsInUse = FALSE;
  858. }