PADAPTER
GetFirstGOPort(
	PADAPTER	pAdapter
)
{
	PADAPTER pDefaultAdapter = GetDefaultAdapter(pAdapter);
	PADAPTER pGOPort = NULL;
	
	pGOPort = pDefaultAdapter;
	
	while(pGOPort != NULL)
	{

	#if P2P_SUPPORT == 1
		if(P2P_ENABLED(GET_P2P_INFO(pGOPort)))
		{
			if(GET_P2P_INFO(pGOPort)->Role == P2P_GO)
			{
				if(P2P_ADAPTER_RTK_SUPPORT_P2P(pGOPort))
				{
					pGOPort = GetFirstAPAdapter(pDefaultAdapter);
				}
				break;
			}
		}
	#endif
	
		pGOPort = GetNextExtAdapter(pGOPort);
	}

	return pGOPort;
}
//
// Description: According to initial gain value to determine to enable or disable EDCCA.
//
// Suggested by SD3 Wilson. Added by tynli. 2011.11.25.
//
VOID
Phydm_DynamicEDCCA(
	IN		PVOID					pDM_VOID
)
{
	PDM_ODM_T		pDM_Odm = (PDM_ODM_T)pDM_VOID;
	PADAPTER		pAdapter	= pDM_Odm->Adapter;
	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(pAdapter);
	u1Byte			RegC50, RegC58;
	BOOLEAN			bEDCCAenable = FALSE;
	
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
	BOOLEAN			bFwCurrentInPSMode=FALSE;	

	pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_FW_PSMODE_STATUS, (pu1Byte)(&bFwCurrentInPSMode));	

	// Disable EDCCA mode while under LPS mode, added by Roger, 2012.09.14.
	if(bFwCurrentInPSMode)
		return;
#endif
	//
	// 2013/11/14 Ken According to BB team Jame's suggestion, we need to disable soft AP mode EDCCA.
	// 2014/01/08 MH For Miracst AP mode test. We need to disable EDCCA. Otherwise, we may stop
	// to send beacon in noisy environment or platform.
	//
	if(ACTING_AS_AP(pAdapter) || ACTING_AS_AP(GetFirstAPAdapter(pAdapter)))
	//if(ACTING_AS_AP(pAdapter))
	{
		ODM_RT_TRACE(pDM_Odm,PHYDM_COMP_ADAPTIVITY, ODM_DBG_LOUD, ("At least One Port as AP disable EDCCA\n"));
		Phydm_DisableEDCCA(pDM_Odm);
		if(pHalData->bPreEdccaEnable)
			Phydm_DisableEDCCA(pDM_Odm);
		pHalData->bPreEdccaEnable = FALSE;
		return;
	}
	
	RegC50 = (u1Byte)ODM_GetBBReg(pDM_Odm, rOFDM0_XAAGCCore1, bMaskByte0);
	RegC58 = (u1Byte)ODM_GetBBReg(pDM_Odm, rOFDM0_XBAGCCore1, bMaskByte0);


 	if((RegC50 > 0x28 && RegC58 > 0x28) ||
  		((pDM_Odm->SupportICType == ODM_RTL8723A && IS_WIRELESS_MODE_G(pAdapter) && RegC50>0x26)) ||
  		(pDM_Odm->SupportICType == ODM_RTL8188E && RegC50 > 0x28))
	{
		if(!pHalData->bPreEdccaEnable)
		{
			Phydm_EnableEDCCA(pDM_Odm);
			pHalData->bPreEdccaEnable = TRUE;
		}
		
	}
	else if((RegC50 < 0x25 && RegC58 < 0x25) || (pDM_Odm->SupportICType == ODM_RTL8188E && RegC50 < 0x25))
	{
		if(pHalData->bPreEdccaEnable)
		{
			Phydm_DisableEDCCA(pDM_Odm);
			pHalData->bPreEdccaEnable = FALSE;
		}
	}
}
VOID
CHNL_ChangeBwChnlFromPeerWorkitemCallBack(
	IN	PVOID			Context
)
{
	PADAPTER			Adapter = (PADAPTER)Context;	
	CHANNEL_WIDTH		ChnlBW;
	EXTCHNL_OFFSET		ExtChnlOffset;
	PMGNT_INFO			pMgntInfo = &Adapter->MgntInfo;
	PRT_CHANNEL_INFO	pChnlInfo = GET_CHNL_INFO(pMgntInfo);
	PADAPTER			pExtAdapter = GetFirstAPAdapter(Adapter);
	PADAPTER			pGoAdapter = GetFirstGOPort(Adapter);

	if(pExtAdapter != NULL)
	{
		if(pExtAdapter->bAPChannelInprogressForNewconnected)
		{
			RT_DISP(FCHNL, FCHNL_ERROR, ("%s: AP change channel in progress , return \n", __FUNCTION__));
			return;

		}
	}

	if(pGoAdapter != NULL)
	{
		if(pGoAdapter->bAPChannelInprogressForNewconnected)
		{
			RT_DISP(FCHNL, FCHNL_ERROR, ("%s: AP change channel in progress , return \n", __FUNCTION__));
			return;
		}
	}

	if(GetDefaultMgntInfo(Adapter)->RegMultiChannelFcsMode != 0)
	{
		if(TRUE == MultiChannel_IsFCSInProgress(Adapter))
		{
			RT_TRACE(COMP_MULTICHANNEL, DBG_TRACE, ("CHNL_ChangeBwChnlFromPeerWorkitemCallBack(): skip change ch & bw due to MCC\n"));
			return;
		}
	}
	
#if 0
	if(GetDefaultAdapter(Adapter)->bInHctTest)
	{
		RT_DISP(FCHNL, FCHNL_ERROR, ("%s: hct test , return \n", __FUNCTION__));
		return;
	
	}
#endif	

	
	chnl_GetBWFrom_IE(Adapter, &ChnlBW, &ExtChnlOffset);

	if(	pChnlInfo->CurrentChannelBandWidth != ChnlBW ||
		pChnlInfo->Ext20MHzChnlOffsetOf40MHz != ExtChnlOffset)
	{
		//
		// Leave LPS and wait until RF is already on before switching channel. 2014.09.25, by tynli.
		//
		LPSLeaveAndCheckReady(Adapter);

		RT_TRACE(COMP_MLME, DBG_LOUD, ("CHNL_ChangeBwChnlFromPeerWorkitemCallBack(): CurrentChannel=%d, ChnlBW=%d, ExtChnlOffset=%d\n",
			pMgntInfo->dot11CurrentChannelNumber, ChnlBW, ExtChnlOffset));

		CHNL_SetBwChnl(Adapter, pMgntInfo->dot11CurrentChannelNumber, ChnlBW, ExtChnlOffset);
		// We should set RA H2C cmd because the BW in TxDesc will be filled again by Fw, we 
		// need to inform Fw the BW changed information. 2012.11.26. by tynli. 
		// Suggested by SD1 Alex Chou.
		if(!ACTING_AS_AP(Adapter) && !ACTING_AS_IBSS(Adapter))
		{
			// we only need to set rate mask
			Adapter->HalFunc.UpdateHalRAMaskHandler(Adapter, pMgntInfo->mMacId, NULL, 0);

		}
	}

}