2 ** $Id: //Department/DaVinci/BRANCHES/MT662X_593X_WIFI_DRIVER_V2_3/mgmt/rlm_obss.c#1 $
10 /*******************************************************************************
11 * Copyright (c) 2009 MediaTek Inc.
13 * All rights reserved. Copying, compilation, modification, distribution
14 * or any other use whatsoever of this material is strictly prohibited
15 * except in accordance with a Software License Agreement with
17 ********************************************************************************
20 /*******************************************************************************
23 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
24 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
25 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
26 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
27 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
28 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
29 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
30 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
31 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
32 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
33 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
34 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
35 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
37 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
38 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
39 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
40 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
41 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
43 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
44 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
45 * OF LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
46 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
47 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
49 ********************************************************************************
55 * 07 17 2012 yuche.tsai
57 * Compile no error before trial run.
61 * Avoid possible OBSS scan when BSS is switched
65 * Add RLM and CNM debug message for XLOG
68 * [WCXRP00001058] [All Wi-Fi][Driver] Fix sta_rec's phyTypeSet and OBSS scan in AP mode
69 * Regulation class is changed to 81 in 20_40_coexistence action frame
72 * [WCXRP00000634] [MT6620 Wi-Fi][Driver][FW] 2nd BSS will not support 40MHz bandwidth for concurrency
76 * [WCXRP00000606] [MT6620 Wi-Fi][Driver][FW] Fix klocwork warning
80 * [WCXRP00000384] [MT6620 Wi-Fi][Driver][FW] Handle 20/40 action frame in AP mode and stop ampdu timer when sta_rec is freed
81 * Process received 20/40 coexistence action frame for AP mode
84 * [WCXRP00000358] [MT6620 Wi-Fi][Driver] Provide concurrent information for each module
85 * Refine function when rcv a 20/40M public action frame
88 * [WCXRP00000354] [MT6620 Wi-Fi][Driver][FW] Follow NVRAM bandwidth setting
89 * Use SCO of BSS_INFO to replace user-defined setting variables
92 * [WCXRP00000354] [MT6620 Wi-Fi][Driver][FW] Follow NVRAM bandwidth setting
93 * User-defined bandwidth is for 2.4G and 5G individually
96 * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
97 * use definition macro to replace hard-coded constant
101 * Change conditional compiling options for BOW
103 * 09 10 2010 cm.chang
105 * Always update Beacon content if FW sync OBSS info
107 * 08 24 2010 cm.chang
109 * Support RLM initail channel of Ad-hoc, P2P and BOW
111 * 08 20 2010 cm.chang
113 * Migrate RLM code to host from FW
115 * 07 26 2010 yuche.tsai
117 * Fix compile error while enabling WiFi Direct function.
119 * 07 21 2010 yuche.tsai
121 * Add P2P Scan & Scan Result Parsing & Saving.
125 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
127 * 07 08 2010 cm.chang
128 * [WPD00003841][LITE Driver] Migrate RLM/CNM to host driver
129 * Check draft RLM code for HT cap
131 * 05 07 2010 cm.chang
132 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
133 * Process 20/40 coexistence public action frame in AP mode
135 * 05 05 2010 cm.chang
136 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
137 * First draft support for 20/40M bandwidth for AP mode
139 * 04 24 2010 cm.chang
140 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
141 * g_aprBssInfo[] depends on CFG_SUPPORT_P2P and CFG_SUPPORT_BOW
143 * 04 13 2010 cm.chang
144 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
145 * Add more ASSERT to check exception
147 * 04 07 2010 cm.chang
148 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
149 * Add virtual test for OBSS scan
151 * 03 30 2010 cm.chang
152 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
153 * Support 2.4G OBSS scan
155 * 03 03 2010 cm.chang
156 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
157 * To support CFG_SUPPORT_BCM_STP
159 * 02 13 2010 cm.chang
160 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
161 * Support PCO in STA mode
163 * 02 12 2010 cm.chang
164 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
165 * Use bss info array for concurrent handle
167 * 02 05 2010 kevin.huang
168 * [BORA00000603][WIFISYS] [New Feature] AAA Module Support
169 * Add AAA Module Support, Revise Net Type to Net Type Index for array lookup
171 * 01 25 2010 cm.chang
172 * [BORA00000018]Integrate WIFI part into BORA for the 1st time
173 * Support protection and bandwidth switch
176 /*******************************************************************************
177 * C O M P I L E R F L A G S
178 ********************************************************************************
181 /*******************************************************************************
182 * E X T E R N A L R E F E R E N C E S
183 ********************************************************************************
187 /*******************************************************************************
189 ********************************************************************************
192 /*******************************************************************************
194 ********************************************************************************
197 /*******************************************************************************
198 * P U B L I C D A T A
199 ********************************************************************************
202 /*******************************************************************************
203 * P R I V A T E D A T A
204 ********************************************************************************
207 /*******************************************************************************
209 ********************************************************************************
212 /*******************************************************************************
213 * F U N C T I O N D E C L A R A T I O N S
214 ********************************************************************************
218 P_ADAPTER_T prAdapter,
222 /*******************************************************************************
224 ********************************************************************************
227 /*----------------------------------------------------------------------------*/
235 /*----------------------------------------------------------------------------*/
238 P_ADAPTER_T prAdapter
241 P_BSS_INFO_T prBssInfo;
244 RLM_NET_FOR_EACH(ucNetIdx) {
245 prBssInfo = &prAdapter->rWifiVar.arBssInfo[ucNetIdx];
248 cnmTimerInitTimer(prAdapter, &prBssInfo->rObssScanTimer,
249 rlmObssScanTimeout, (UINT_32) prBssInfo);
250 } /* end of RLM_NET_FOR_EACH */
253 /*----------------------------------------------------------------------------*/
261 /*----------------------------------------------------------------------------*/
263 rlmObssUpdateChnlLists (
264 P_ADAPTER_T prAdapter,
271 /*----------------------------------------------------------------------------*/
279 /*----------------------------------------------------------------------------*/
282 P_ADAPTER_T prAdapter,
286 P_MSG_SCN_SCAN_DONE prScanDoneMsg;
287 P_BSS_INFO_T prBssInfo;
288 P_MSDU_INFO_T prMsduInfo;
289 P_ACTION_20_40_COEXIST_FRAME prTxFrame;
290 UINT_16 i, u2PayloadLen;
294 prScanDoneMsg = (P_MSG_SCN_SCAN_DONE) prMsgHdr;
295 prBssInfo = &prAdapter->rWifiVar.arBssInfo[prScanDoneMsg->ucNetTypeIndex];
298 DBGLOG(RLM, INFO, ("OBSS Scan Done (NetIdx=%d, Mode=%d)\n",
299 prScanDoneMsg->ucNetTypeIndex, prBssInfo->eCurrentOPMode));
301 cnmMemFree(prAdapter, prMsgHdr);
303 #if CFG_ENABLE_WIFI_DIRECT
305 if ((prAdapter->fgIsP2PRegistered) &&
306 (IS_NET_ACTIVE(prAdapter, prBssInfo->ucNetTypeIndex)) &&
307 (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)) {
313 if (prBssInfo->eCurrentOPMode != OP_MODE_INFRASTRUCTURE ||
314 !RLM_NET_PARAM_VALID(prBssInfo) || prBssInfo->u2ObssScanInterval == 0) {
315 DBGLOG(RLM, WARN, ("OBSS Scan Done (NetIdx=%d) -- Aborted!!\n",
316 prBssInfo->ucNetTypeIndex));
320 /* To do: check 2.4G channel list to decide if obss mgmt should be
321 * sent to associated AP. Note: how to handle concurrent network?
322 * To do: invoke rlmObssChnlLevel() to decide if 20/40 BSS coexistence
323 * management frame is needed.
325 if ((prBssInfo->auc2G_20mReqChnlList[0] > 0 ||
326 prBssInfo->auc2G_NonHtChnlList[0] > 0) &&
327 (prMsduInfo = (P_MSDU_INFO_T) cnmMgtPktAlloc(prAdapter,
328 MAC_TX_RESERVED_FIELD + PUBLIC_ACTION_MAX_LEN)) != NULL) {
330 DBGLOG(RLM, INFO, ("Send 20/40 coexistence mgmt(20mReq=%d, NonHt=%d)\n",
331 prBssInfo->auc2G_20mReqChnlList[0],
332 prBssInfo->auc2G_NonHtChnlList[0]));
334 prTxFrame = (P_ACTION_20_40_COEXIST_FRAME)
335 ((UINT_32)(prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD);
337 prTxFrame->u2FrameCtrl = MAC_FRAME_ACTION;
338 COPY_MAC_ADDR(prTxFrame->aucDestAddr, prBssInfo->aucBSSID);
339 COPY_MAC_ADDR(prTxFrame->aucSrcAddr, prBssInfo->aucOwnMacAddr);
340 COPY_MAC_ADDR(prTxFrame->aucBSSID, prBssInfo->aucBSSID);
342 prTxFrame->ucCategory = CATEGORY_PUBLIC_ACTION;
343 prTxFrame->ucAction = ACTION_PUBLIC_20_40_COEXIST;
345 /* To do: find correct algorithm */
346 prTxFrame->rBssCoexist.ucId = ELEM_ID_20_40_BSS_COEXISTENCE;
347 prTxFrame->rBssCoexist.ucLength = 1;
348 prTxFrame->rBssCoexist.ucData =
349 (prBssInfo->auc2G_20mReqChnlList[0] > 0) ? BSS_COEXIST_20M_REQ : 0;
351 u2PayloadLen = 2 + 3;
353 if (prBssInfo->auc2G_NonHtChnlList[0] > 0) {
354 ASSERT(prBssInfo->auc2G_NonHtChnlList[0] <= CHNL_LIST_SZ_2G);
356 prTxFrame->rChnlReport.ucId = ELEM_ID_20_40_INTOLERANT_CHNL_REPORT;
357 prTxFrame->rChnlReport.ucLength =
358 prBssInfo->auc2G_NonHtChnlList[0] + 1;
359 prTxFrame->rChnlReport.ucRegulatoryClass = 81; /* 2.4GHz, ch1~13 */
360 for (i = 0; i < prBssInfo->auc2G_NonHtChnlList[0] &&
361 i < CHNL_LIST_SZ_2G; i++) {
362 prTxFrame->rChnlReport.aucChannelList[i] =
363 prBssInfo->auc2G_NonHtChnlList[i+1];
366 u2PayloadLen += IE_SIZE(&prTxFrame->rChnlReport);
368 ASSERT((WLAN_MAC_HEADER_LEN + u2PayloadLen) <= PUBLIC_ACTION_MAX_LEN);
370 /* Clear up channel lists in 2.4G band */
371 prBssInfo->auc2G_20mReqChnlList[0] = 0;
372 prBssInfo->auc2G_NonHtChnlList[0] = 0;
375 //4 Update information of MSDU_INFO_T
376 prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_MGMT; /* Management frame */
377 prMsduInfo->ucStaRecIndex = prBssInfo->prStaRecOfAP->ucIndex;
378 prMsduInfo->ucNetworkType = prBssInfo->ucNetTypeIndex;
379 prMsduInfo->ucMacHeaderLength = WLAN_MAC_MGMT_HEADER_LEN;
380 prMsduInfo->fgIs802_1x = FALSE;
381 prMsduInfo->fgIs802_11 = TRUE;
382 prMsduInfo->u2FrameLength = WLAN_MAC_MGMT_HEADER_LEN + u2PayloadLen;
383 prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
384 prMsduInfo->pfTxDoneHandler = NULL;
385 prMsduInfo->fgIsBasicRate = FALSE;
387 //4 Enqueue the frame to send this action frame.
388 nicTxEnqueueMsdu(prAdapter, prMsduInfo);
389 } /* end of prMsduInfo != NULL */
391 if (prBssInfo->u2ObssScanInterval > 0) {
392 DBGLOG(RLM, INFO, ("Set OBSS timer (NetIdx=%d, %d sec)\n",
393 prBssInfo->ucNetTypeIndex, prBssInfo->u2ObssScanInterval));
395 cnmTimerStartTimer(prAdapter, &prBssInfo->rObssScanTimer,
396 prBssInfo->u2ObssScanInterval * MSEC_PER_SEC);
400 /*----------------------------------------------------------------------------*/
408 /*----------------------------------------------------------------------------*/
411 P_ADAPTER_T prAdapter,
415 P_BSS_INFO_T prBssInfo;
417 prBssInfo = (P_BSS_INFO_T) u4Data;
420 #if CFG_ENABLE_WIFI_DIRECT
422 if (prAdapter->fgIsP2PRegistered &&
423 (IS_NET_ACTIVE(prAdapter, prBssInfo->ucNetTypeIndex)) &&
424 (prBssInfo->eCurrentOPMode == OP_MODE_ACCESS_POINT)) {
426 prBssInfo->fgObssActionForcedTo20M = FALSE;
428 /* Check if Beacon content need to be updated */
429 rlmUpdateParamsForAP(prAdapter, prBssInfo, FALSE);
433 #endif /* end of CFG_ENABLE_WIFI_DIRECT */
437 if (prBssInfo->eCurrentOPMode != OP_MODE_INFRASTRUCTURE ||
438 !RLM_NET_PARAM_VALID(prBssInfo) || prBssInfo->u2ObssScanInterval == 0) {
439 DBGLOG(RLM, WARN, ("OBSS Scan timeout (NetIdx=%d) -- Aborted!!\n",
440 prBssInfo->ucNetTypeIndex));
444 rlmObssTriggerScan(prAdapter, prBssInfo);
447 /*----------------------------------------------------------------------------*/
455 /*----------------------------------------------------------------------------*/
458 P_ADAPTER_T prAdapter,
459 P_BSS_INFO_T prBssInfo
462 P_MSG_SCN_SCAN_REQ prScanReqMsg;
466 prScanReqMsg = (P_MSG_SCN_SCAN_REQ)
467 cnmMemAlloc(prAdapter, RAM_TYPE_MSG, sizeof(MSG_SCN_SCAN_REQ));
468 ASSERT(prScanReqMsg);
471 DBGLOG(RLM, WARN, ("No buf for OBSS scan (NetIdx=%d)!!\n",
472 prBssInfo->ucNetTypeIndex));
474 cnmTimerStartTimer(prAdapter, &prBssInfo->rObssScanTimer,
475 prBssInfo->u2ObssScanInterval * MSEC_PER_SEC);
479 /* It is ok that ucSeqNum is set to fixed value because the same network
480 * OBSS scan interval is limited to OBSS_SCAN_MIN_INTERVAL (min 10 sec)
481 * and scan module don't care seqNum of OBSS scanning
483 prScanReqMsg->rMsgHdr.eMsgId = MID_RLM_SCN_SCAN_REQ;
484 prScanReqMsg->ucSeqNum = 0x33;
485 prScanReqMsg->ucNetTypeIndex = prBssInfo->ucNetTypeIndex;
486 prScanReqMsg->eScanType = SCAN_TYPE_ACTIVE_SCAN;
487 prScanReqMsg->ucSSIDType = SCAN_REQ_SSID_WILDCARD;
488 prScanReqMsg->ucSSIDLength = 0;
489 prScanReqMsg->eScanChannel = SCAN_CHANNEL_2G4;
490 prScanReqMsg->u2IELen = 0;
492 mboxSendMsg(prAdapter,
494 (P_MSG_HDR_T) prScanReqMsg,
495 MSG_SEND_METHOD_BUF);
497 DBGLOG(RLM, INFO, ("Timeout to trigger OBSS scan (NetIdx=%d)!!\n",
498 prBssInfo->ucNetTypeIndex));