rlm_obss.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/rlm_obss.c#2
  3. */
  4. /*! \file "rlm_obss.c"
  5. \brief
  6. */
  7. /*
  8. ** Log: rlm_obss.c
  9. **
  10. ** 08 13 2013 terry.wu
  11. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  12. ** Remove unused code
  13. **
  14. ** 03 12 2013 terry.wu
  15. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  16. ** Update Tx utility function for management frame
  17. **
  18. ** 01 17 2013 cm.chang
  19. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  20. ** Use ucBssIndex to replace eNetworkTypeIndex
  21. **
  22. ** 09 17 2012 cm.chang
  23. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  24. ** Duplicate source from MT6620 v2.3 driver branch
  25. ** (Davinci label: MT6620_WIFI_Driver_V2_3_120913_1942_As_MT6630_Base)
  26. *
  27. * 07 17 2012 yuche.tsai
  28. * NULL
  29. * Compile no error before trial run.
  30. *
  31. * 11 15 2011 cm.chang
  32. * NULL
  33. * Avoid possible OBSS scan when BSS is switched
  34. *
  35. * 11 08 2011 cm.chang
  36. * NULL
  37. * Add RLM and CNM debug message for XLOG
  38. *
  39. * 10 25 2011 cm.chang
  40. * [WCXRP00001058] [All Wi-Fi][Driver] Fix sta_rec's phyTypeSet and OBSS scan in AP mode
  41. * Regulation class is changed to 81 in 20_40_coexistence action frame
  42. *
  43. * 04 12 2011 cm.chang
  44. * [WCXRP00000634] [MT6620 Wi-Fi][Driver][FW] 2nd BSS will not support 40MHz bandwidth for concurrency
  45. * .
  46. *
  47. * 03 29 2011 cm.chang
  48. * [WCXRP00000606] [MT6620 Wi-Fi][Driver][FW] Fix klocwork warning
  49. * As CR title
  50. *
  51. * 01 24 2011 cm.chang
  52. * [WCXRP00000384] [MT6620 Wi-Fi][Driver][FW] Handle 20/40 action frame
  53. * in AP mode and stop ampdu timer when sta_rec is freed
  54. * Process received 20/40 coexistence action frame for AP mode
  55. *
  56. * 01 13 2011 cm.chang
  57. * [WCXRP00000358] [MT6620 Wi-Fi][Driver] Provide concurrent information for each module
  58. * Refine function when rcv a 20/40M public action frame
  59. *
  60. * 01 13 2011 cm.chang
  61. * [WCXRP00000354] [MT6620 Wi-Fi][Driver][FW] Follow NVRAM bandwidth setting
  62. * Use SCO of BSS_INFO to replace user-defined setting variables
  63. *
  64. * 01 12 2011 cm.chang
  65. * [WCXRP00000354] [MT6620 Wi-Fi][Driver][FW] Follow NVRAM bandwidth setting
  66. * User-defined bandwidth is for 2.4G and 5G individually
  67. *
  68. * 10 18 2010 cp.wu
  69. * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
  70. * use definition macro to replace hard-coded constant
  71. *
  72. * 09 16 2010 cm.chang
  73. * NULL
  74. * Change conditional compiling options for BOW
  75. *
  76. * 09 10 2010 cm.chang
  77. * NULL
  78. * Always update Beacon content if FW sync OBSS info
  79. *
  80. * 08 24 2010 cm.chang
  81. * NULL
  82. * Support RLM initail channel of Ad-hoc, P2P and BOW
  83. *
  84. * 08 20 2010 cm.chang
  85. * NULL
  86. * Migrate RLM code to host from FW
  87. *
  88. * 07 26 2010 yuche.tsai
  89. *
  90. * Fix compile error while enabling WiFi Direct function.
  91. *
  92. * 07 21 2010 yuche.tsai
  93. *
  94. * Add P2P Scan & Scan Result Parsing & Saving.
  95. *
  96. * 07 08 2010 cp.wu
  97. *
  98. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  99. *
  100. * 07 08 2010 cm.chang
  101. * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
  102. * Check draft RLM code for HT cap
  103. *
  104. * 05 07 2010 cm.chang
  105. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  106. * Process 20/40 coexistence public action frame in AP mode
  107. *
  108. * 05 05 2010 cm.chang
  109. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  110. * First draft support for 20/40M bandwidth for AP mode
  111. *
  112. * 04 24 2010 cm.chang
  113. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  114. * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
  115. *
  116. * 04 13 2010 cm.chang
  117. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  118. * Add more ASSERT to check exception
  119. *
  120. * 04 07 2010 cm.chang
  121. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  122. * Add virtual test for OBSS scan
  123. *
  124. * 03 30 2010 cm.chang
  125. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  126. * Support 2.4G OBSS scan
  127. *
  128. * 03 03 2010 cm.chang
  129. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  130. * To support CFG_SUPPORT_BCM_STP
  131. *
  132. * 02 13 2010 cm.chang
  133. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  134. * Support PCO in STA mode
  135. *
  136. * 02 12 2010 cm.chang
  137. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  138. * Use bss info array for concurrent handle
  139. *
  140. * 02 05 2010 kevin.huang
  141. * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
  142. * Add AAA Module Support, Revise Net Type to Net Type Index for array lookup
  143. *
  144. * 01 25 2010 cm.chang
  145. * [BORA00000018]Integrate WIFI part into BORA for the 1st time
  146. * Support protection and bandwidth switch
  147. */
  148. /*******************************************************************************
  149. * C O M P I L E R F L A G S
  150. ********************************************************************************
  151. */
  152. /*******************************************************************************
  153. * E X T E R N A L R E F E R E N C E S
  154. ********************************************************************************
  155. */
  156. #include "precomp.h"
  157. /*******************************************************************************
  158. * C O N S T A N T S
  159. ********************************************************************************
  160. */
  161. /*******************************************************************************
  162. * D A T A T Y P E S
  163. ********************************************************************************
  164. */
  165. /*******************************************************************************
  166. * P U B L I C D A T A
  167. ********************************************************************************
  168. */
  169. /*******************************************************************************
  170. * P R I V A T E D A T A
  171. ********************************************************************************
  172. */
  173. /*******************************************************************************
  174. * M A C R O S
  175. ********************************************************************************
  176. */
  177. /*******************************************************************************
  178. * F U N C T I O N D E C L A R A T I O N S
  179. ********************************************************************************
  180. */
  181. static VOID rlmObssScanTimeout(P_ADAPTER_T prAdapter, ULONG ulParamPtr);
  182. /*******************************************************************************
  183. * F U N C T I O N S
  184. ********************************************************************************
  185. */
  186. /*----------------------------------------------------------------------------*/
  187. /*!
  188. * \brief
  189. *
  190. * \param[in]
  191. *
  192. * \return none
  193. */
  194. /*----------------------------------------------------------------------------*/
  195. VOID rlmObssInit(P_ADAPTER_T prAdapter)
  196. {
  197. P_BSS_INFO_T prBssInfo;
  198. UINT_8 i;
  199. for (i = 0; i < BSS_INFO_NUM; i++) {
  200. prBssInfo = prAdapter->aprBssInfo[i];
  201. cnmTimerInitTimer(prAdapter, &prBssInfo->rObssScanTimer,
  202. (PFN_MGMT_TIMEOUT_FUNC) rlmObssScanTimeout, (ULONG) prBssInfo);
  203. }
  204. }
  205. /*----------------------------------------------------------------------------*/
  206. /*!
  207. * \brief
  208. *
  209. * \param[in]
  210. *
  211. * \return none
  212. */
  213. /*----------------------------------------------------------------------------*/
  214. BOOLEAN rlmObssUpdateChnlLists(P_ADAPTER_T prAdapter, P_SW_RFB_T prSwRfb)
  215. {
  216. return TRUE;
  217. }
  218. /*----------------------------------------------------------------------------*/
  219. /*!
  220. * \brief
  221. *
  222. * \param[in]
  223. *
  224. * \return none
  225. */
  226. /*----------------------------------------------------------------------------*/
  227. VOID rlmObssScanDone(P_ADAPTER_T prAdapter, P_MSG_HDR_T prMsgHdr)
  228. {
  229. P_MSG_SCN_SCAN_DONE prScanDoneMsg;
  230. P_BSS_INFO_T prBssInfo;
  231. P_MSDU_INFO_T prMsduInfo;
  232. P_ACTION_20_40_COEXIST_FRAME prTxFrame;
  233. UINT_16 i, u2PayloadLen;
  234. ASSERT(prMsgHdr);
  235. prScanDoneMsg = (P_MSG_SCN_SCAN_DONE) prMsgHdr;
  236. prBssInfo = prAdapter->aprBssInfo[prScanDoneMsg->ucBssIndex];
  237. ASSERT(prBssInfo);
  238. DBGLOG(RLM, INFO, "OBSS Scan Done (NetIdx=%d, Mode=%d)\n",
  239. prScanDoneMsg->ucBssIndex, prBssInfo->eCurrentOPMode);
  240. cnmMemFree(prAdapter, prMsgHdr);
  241. #if CFG_ENABLE_WIFI_DIRECT
  242. /* AP mode */
  243. if ((prAdapter->fgIsP2PRegistered) &&
  244. (IS_NET_ACTIVE(prAdapter, prBssInfo->ucBssIndex)) && (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)) {
  245. return;
  246. }
  247. #endif
  248. /* STA mode */
  249. if (prBssInfo->eCurrentOPMode != OP_MODE_INFRASTRUCTURE ||
  250. !RLM_NET_PARAM_VALID(prBssInfo) || prBssInfo->u2ObssScanInterval == 0) {
  251. DBGLOG(RLM, WARN, "OBSS Scan Done (NetIdx=%d) -- Aborted!!\n", prBssInfo->ucBssIndex);
  252. return;
  253. }
  254. /* To do: check 2.4G channel list to decide if obss mgmt should be
  255. * sent to associated AP. Note: how to handle concurrent network?
  256. * To do: invoke rlmObssChnlLevel() to decide if 20/40 BSS coexistence
  257. * management frame is needed.
  258. */
  259. if (prBssInfo->auc2G_20mReqChnlList[0] > 0 || prBssInfo->auc2G_NonHtChnlList[0] > 0) {
  260. DBGLOG(RLM, INFO, "Send 20/40 coexistence mgmt(20mReq=%d, NonHt=%d)\n",
  261. prBssInfo->auc2G_20mReqChnlList[0], prBssInfo->auc2G_NonHtChnlList[0]);
  262. prMsduInfo = (P_MSDU_INFO_T) cnmMgtPktAlloc(prAdapter, MAC_TX_RESERVED_FIELD + PUBLIC_ACTION_MAX_LEN);
  263. if (prMsduInfo) {
  264. prTxFrame = (P_ACTION_20_40_COEXIST_FRAME)
  265. ((ULONG) (prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD);
  266. prTxFrame->u2FrameCtrl = MAC_FRAME_ACTION;
  267. COPY_MAC_ADDR(prTxFrame->aucDestAddr, prBssInfo->aucBSSID);
  268. COPY_MAC_ADDR(prTxFrame->aucSrcAddr, prBssInfo->aucOwnMacAddr);
  269. COPY_MAC_ADDR(prTxFrame->aucBSSID, prBssInfo->aucBSSID);
  270. prTxFrame->ucCategory = CATEGORY_PUBLIC_ACTION;
  271. prTxFrame->ucAction = ACTION_PUBLIC_20_40_COEXIST;
  272. /* To do: find correct algorithm */
  273. prTxFrame->rBssCoexist.ucId = ELEM_ID_20_40_BSS_COEXISTENCE;
  274. prTxFrame->rBssCoexist.ucLength = 1;
  275. prTxFrame->rBssCoexist.ucData =
  276. (prBssInfo->auc2G_20mReqChnlList[0] > 0) ? BSS_COEXIST_20M_REQ : 0;
  277. u2PayloadLen = 2 + 3;
  278. if (prBssInfo->auc2G_NonHtChnlList[0] > 0) {
  279. ASSERT(prBssInfo->auc2G_NonHtChnlList[0] <= CHNL_LIST_SZ_2G);
  280. prTxFrame->rChnlReport.ucId = ELEM_ID_20_40_INTOLERANT_CHNL_REPORT;
  281. prTxFrame->rChnlReport.ucLength = prBssInfo->auc2G_NonHtChnlList[0] + 1;
  282. prTxFrame->rChnlReport.ucRegulatoryClass = 81; /* 2.4GHz, ch1~13 */
  283. for (i = 0; i < prBssInfo->auc2G_NonHtChnlList[0] && i < CHNL_LIST_SZ_2G; i++)
  284. prTxFrame->rChnlReport.aucChannelList[i] =
  285. prBssInfo->auc2G_NonHtChnlList[i + 1];
  286. u2PayloadLen += IE_SIZE(&prTxFrame->rChnlReport);
  287. }
  288. ASSERT((WLAN_MAC_HEADER_LEN + u2PayloadLen) <= PUBLIC_ACTION_MAX_LEN);
  289. /* Clear up channel lists in 2.4G band */
  290. prBssInfo->auc2G_20mReqChnlList[0] = 0;
  291. prBssInfo->auc2G_NonHtChnlList[0] = 0;
  292. /* 4 Update information of MSDU_INFO_T */
  293. TX_SET_MMPDU(prAdapter,
  294. prMsduInfo,
  295. prBssInfo->ucBssIndex,
  296. prBssInfo->prStaRecOfAP->ucIndex,
  297. WLAN_MAC_MGMT_HEADER_LEN,
  298. WLAN_MAC_MGMT_HEADER_LEN + u2PayloadLen, NULL, MSDU_RATE_MODE_AUTO);
  299. /* 4 Enqueue the frame to send this action frame. */
  300. nicTxEnqueueMsdu(prAdapter, prMsduInfo);
  301. }
  302. }
  303. /* end of prMsduInfo != NULL */
  304. if (prBssInfo->u2ObssScanInterval > 0) {
  305. DBGLOG(RLM, INFO, "Set OBSS timer (NetIdx=%d, %d sec)\n",
  306. prBssInfo->ucBssIndex, prBssInfo->u2ObssScanInterval);
  307. cnmTimerStartTimer(prAdapter, &prBssInfo->rObssScanTimer, prBssInfo->u2ObssScanInterval * MSEC_PER_SEC);
  308. }
  309. }
  310. /*----------------------------------------------------------------------------*/
  311. /*!
  312. * \brief
  313. *
  314. * \param[in]
  315. *
  316. * \return none
  317. */
  318. /*----------------------------------------------------------------------------*/
  319. static VOID rlmObssScanTimeout(P_ADAPTER_T prAdapter, ULONG ulParamPtr)
  320. {
  321. P_BSS_INFO_T prBssInfo;
  322. prBssInfo = (P_BSS_INFO_T) ulParamPtr;
  323. ASSERT(prBssInfo);
  324. #if CFG_ENABLE_WIFI_DIRECT
  325. /* AP mode */
  326. if (prAdapter->fgIsP2PRegistered &&
  327. (IS_NET_ACTIVE(prAdapter, prBssInfo->ucBssIndex)) && (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)) {
  328. prBssInfo->fgObssActionForcedTo20M = FALSE;
  329. /* Check if Beacon content need to be updated */
  330. rlmUpdateParamsForAP(prAdapter, prBssInfo, FALSE);
  331. return;
  332. }
  333. #if CFG_SUPPORT_WFD
  334. /* WFD streaming */
  335. else {
  336. P_WFD_CFG_SETTINGS_T prWfdCfgSettings = &prAdapter->rWifiVar.rWfdConfigureSettings;
  337. /* If WFD is enabled & connected */
  338. if (prWfdCfgSettings->ucWfdEnable) {
  339. /* Skip OBSS scan */
  340. prBssInfo->u2ObssScanInterval = 0;
  341. DBGLOG(RLM, INFO, "WFD is running. Stop OBSS scan.\n");
  342. return;
  343. } /* WFD is enabled */
  344. }
  345. #endif
  346. #endif /* end of CFG_ENABLE_WIFI_DIRECT */
  347. /* STA mode */
  348. if (prBssInfo->eCurrentOPMode != OP_MODE_INFRASTRUCTURE ||
  349. !RLM_NET_PARAM_VALID(prBssInfo) || prBssInfo->u2ObssScanInterval == 0) {
  350. DBGLOG(RLM, WARN, "OBSS Scan timeout (NetIdx=%d) -- Aborted!!\n", prBssInfo->ucBssIndex);
  351. return;
  352. }
  353. rlmObssTriggerScan(prAdapter, prBssInfo);
  354. }
  355. /*----------------------------------------------------------------------------*/
  356. /*!
  357. * \brief
  358. *
  359. * \param[in]
  360. *
  361. * \return none
  362. */
  363. /*----------------------------------------------------------------------------*/
  364. VOID rlmObssTriggerScan(P_ADAPTER_T prAdapter, P_BSS_INFO_T prBssInfo)
  365. {
  366. P_MSG_SCN_SCAN_REQ prScanReqMsg;
  367. ASSERT(prBssInfo);
  368. prScanReqMsg = (P_MSG_SCN_SCAN_REQ)
  369. cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_SCN_SCAN_REQ));
  370. ASSERT(prScanReqMsg);
  371. if (!prScanReqMsg) {
  372. DBGLOG(RLM, WARN, "No buf for OBSS scan (NetIdx=%d)!!\n", prBssInfo->ucBssIndex);
  373. cnmTimerStartTimer(prAdapter, &prBssInfo->rObssScanTimer, prBssInfo->u2ObssScanInterval * MSEC_PER_SEC);
  374. return;
  375. }
  376. /* It is ok that ucSeqNum is set to fixed value because the same network
  377. * OBSS scan interval is limited to OBSS_SCAN_MIN_INTERVAL (min 10 sec)
  378. * and scan module don't care seqNum of OBSS scanning
  379. */
  380. prScanReqMsg->rMsgHdr.eMsgId = MID_RLM_SCN_SCAN_REQ;
  381. prScanReqMsg->ucSeqNum = 0x33;
  382. prScanReqMsg->ucBssIndex = prBssInfo->ucBssIndex;
  383. prScanReqMsg->eScanType = SCAN_TYPE_ACTIVE_SCAN;
  384. prScanReqMsg->ucSSIDType = SCAN_REQ_SSID_WILDCARD;
  385. prScanReqMsg->ucSSIDLength = 0;
  386. prScanReqMsg->eScanChannel = SCAN_CHANNEL_2G4;
  387. prScanReqMsg->u2IELen = 0;
  388. mboxSendMsg(prAdapter, MBOX_ID_0, (P_MSG_HDR_T) prScanReqMsg, MSG_SEND_METHOD_BUF);
  389. DBGLOG(RLM, INFO, "Timeout to trigger OBSS scan (NetIdx=%d)!!\n", prBssInfo->ucBssIndex);
  390. }