pararoamingproc.c

来自「marvell8385 GSPI开发驱动」· C语言 代码 · 共 1,981 行 · 第 1/5 页

C
1,981
字号
	PMRVDRV_ADAPTER   Adapter = priv.pAdapter;
#ifdef PARA_WPA_1X
	int HandOffhandlerRetCode=0;
#endif
	CeSetThreadPriority(GetCurrentThread(), 150); 

	for (;;)
	{
		//wait until AutoRoamingEvent trigger happenned!
/*Fix the bug 2779/3151 by Stephen Zhang on 2007-06-25<<<<<<<<<*/ 
		//ResetEvent(priv.hAutoRoamingEvent);
/*Fix the bug 2779/3151 by Stephen Zhang on 2007-06-25>>>>>>>>>*/ 
		waitStatus = WaitForSingleObject(priv.hAutoRoamingEvent, INFINITE);	
		if (WAIT_OBJECT_0 != waitStatus)
		{
			RETAILMSG(1,(TEXT("call WaitFor AutoRoamingEvent Fail : \n")));
			DBGPRINT(DBG_ALL, ("AutoRoamingThread:call WaitFor AutoRoamingEvent Fail : \n"));
			return;
		}
#ifdef DEBUG_PARA_ROAMING_PRINT
		RETAILMSG(1,(TEXT("Enter AutoRoamingThread!...\n")));
		ParaPrintFile("\nEnter AutoRoamingThread!...\n");
#endif
DBGPRINT(DBG_ALL, ("Enter AutoRoamingThread!...\n"));	
		EnterCriticalSection(&priv.AutoRoamingCriticalSection);

		/*store the previous connected AP's SSID and BSSID*/
		NdisMoveMemory( &(Adapter->PreviousSSID), &(Adapter->CurrentSSID), 
		              sizeof(NDIS_802_11_SSID));
		        
		NdisMoveMemory( Adapter->PreviousBSSID, Adapter->CurrentBSSID, 
		              MRVDRV_ETH_ADDR_LEN);

		/*store the previous connected profile's index*/
		priv.ProfileAllList.PreviousProfileIndex = priv.ProfileAllList.CurrentProfileIndex;
		
		/* Set the  InfrastructureMode */
		Adapter->InfrastructureMode = Ndis802_11Infrastructure;

		Adapter->LinkSpeed = MRVDRV_LINK_SPEED_1mbps;	
		
		Adapter->AdHocCreated = FALSE;   
	
		
		LeaveCriticalSection(&priv.AutoRoamingCriticalSection);
		
restart_roaming:
#ifdef DEBUG_PARA_ROAMING_PRINT
		ParaPrintFile("\n[AutoRoamingThread]------restart_roaming!!!\n");
#endif
		//Start auto-roaming only if manual-roaming or auto-roaming have NOT happenned before!
		if((!priv.bManualRoamingInProcess) && (!priv.bAutoRoamingInProcess))
		{
		       int iNewRoundRoaming = 0;
			//Set auto-roaming flag
			priv.bAutoRoamingInProcess = TRUE;
			//Start auto-roaming timer only if the timer have NOT run before
			if(!priv.bAutoRoamingTimerIsSet)
			{
				NdisMCancelTimer(&priv.AutoRoamingTimer, &timerStatus);
#ifdef CONFIG_VERTICAL_HANDOFF
				NdisMSetTimer(&priv.AutoRoamingTimer, priv.iAutoRoamingTimeout);
#else
				NdisMSetTimer(&priv.AutoRoamingTimer, ROAMING_LINKLOST_TIMEOUT);
#endif
				iNewRoundRoaming = 1;
                            
                          /*start count auto-roaming times in a round*/
                          iAutoRoamingCount = 1;
				priv.bAutoRoamingTimerIsSet=TRUE;	
				rmm_CleanBlackBssidList(Adapter);
			}
			else
			{
				iAutoRoamingCount ++;
/*Fix the bug 2779/3151 by Stephen Zhang on 2007-06-25<<<<<<<<<*/ 
				if(iAutoRoamingCount >= AUTO_ROAMING_MAX_COUNTS)
/*Fix the bug 2779/3151 by Stephen Zhang on 2007-06-25>>>>>>>>>*/ 
				{
					NdisMCancelTimer(&priv.AutoRoamingTimer, &timerStatus);
                                priv.bAutoRoamingTimerIsSet = FALSE;
                                priv.bStopRoaming = TRUE;
                                Adapter->bIsAssociateInProgress = FALSE;
                                Adapter->bIsScanInProgress= FALSE;
				}
//				else
//				{
//					Sleep(1);
//				}
			}

//#ifdef DEBUG_PARA_ROAMING_PRINT
			RETAILMSG(1,(TEXT("\nIn a round,auto-roaming @ %d times!...\n"),iAutoRoamingCount));
//#endif
#ifdef DEBUG_PARA_ROAMING_PRINT
			ParaPrintFile("\n[AutoRoamingThread]------auto-roaming @ %d times!...\n",iAutoRoamingCount);
#endif
			//ALL channel-Scan before auto-roaming only if NOT fast roaming
			if(!priv.bFastAutoRoaming)
			{				

				priv.bAddedPrelistByPRM = RMM_ADD_PREFERLIST_FAILED;
#if 0
				//Notify profile manager module: WZC preferlist should be clear!
				ED_PostMessage(TEXT("PRM"), PRM_CLR_WZC_PREFERLIST, 0, 0);	
#endif				
				if((Adapter->MediaConnectStatus == NdisMediaStateConnected)
					&& (!(NdisEqualMemory(Adapter->NullBSSID, 
							Adapter->CurrentBSSID,MRVDRV_ETH_ADDR_LEN))))
				{
					if(!priv.bManualRoamingInProcess){
						//Do DEAUTHENTICATE and wait until finished
						ResetEvent(priv.hDeauthFinishedEvent);
						
						PrepareAndSendCommand(
						      Adapter,
						      HostCmd_CMD_802_11_DEAUTHENTICATE,
						      0,
						      HostCmd_OPTION_USE_INT,
						      (NDIS_OID)0,
						      HostCmd_PENDING_ON_NONE,
						      0,
						      FALSE,
						      NULL,
						      NULL,
						      NULL,
						      NULL);
						      
						//wait for 1000 ms
						waitStatus = WaitForSingleObject(priv.hDeauthFinishedEvent, 100);
						if (WAIT_OBJECT_0 != waitStatus)
						{
							RETAILMSG(1,(TEXT("call WaitFor hDeauthFinishedEvent Fail : \n")));
						}
					}
				}
				Adapter->MediaConnectStatus = NdisMediaStateDisconnected;
				//Set register WiFi state to disconnected
				//dwWifi = WSF_POWER_ON | WSF_HARDWARE_PRESENT;
				//SetRegisterWiFiState(dwWifi);
				
#ifdef DEBUG_PARA_ROAMING_PRINT
				RETAILMSG(1,(TEXT("AutoRoamingThread:NdisMediaStateDisconnected is caused by NOT FastAutoRoaming!...\n")));
#endif
				WriteCommonLogFile(WIFI_LOG,"AP is disconnected(Reason=3)  (FastAutoRoaming)!...\r\n",
								strlen("AP is disconnected(Reason=3)	(FastAutoRoaming)!...\r\n"));
				 if(g_AssociationDuration != 0)
				{
				  char logstr[200];
				  sprintf(logstr,"Association Duration is %d seconds\r\n", (GetTickCount() - g_AssociationDuration)/1000);
				  WriteCommonLogFile(WIFI_LOG,logstr, strlen(logstr));
				  g_AssociationDuration = 0;
				}


				// indicate the NDIS the media is disconnected!
				NdisMIndicateStatus(
					Adapter->MrvDrvAdapterHdl,
					NDIS_STATUS_MEDIA_DISCONNECT,
					(PVOID)NULL,
					0); 	
				NdisMIndicateStatusComplete(Adapter->MrvDrvAdapterHdl); 



				if((!Adapter->bIsScanInProgress) && (!Adapter->bIsAssociateInProgress )){
					if(!priv.bManualRoamingInProcess){
                                       if(iNewRoundRoaming == 1)
                                       {
							AllChannelScan(&priv);
                                       }
                                       else if((iAutoRoamingCount % AUTO_ROAMING_COUNTS_FOR_SMART_SCAN) == 0)
                                       {
                                        	SmartScan(&priv);
                                       }

					}
				}
				else
				{
#ifdef DEBUG_PARA_ROAMING_PRINT
					RETAILMSG(1,(TEXT("Before handoff: Can NOT scan caused by scan or associate is in progress!!!\n")));
#endif						
				}
			}
			else
			{
				if((!Adapter->bIsScanInProgress) && (!Adapter->bIsAssociateInProgress )){
					if(!priv.bManualRoamingInProcess){
                                       if(iNewRoundRoaming == 1)
                                       {
#ifdef DEBUG_PARA_ROAMING_PRINT
							RETAILMSG(1,(TEXT("NEED NOT smart scan when restart a new round fast-roaming!\n")));
#endif
                                       }
                                       else
                                       {/*If find the same AP in the previous auto-roaming try,We should smart scan now!
						     If find another suitable AP in the previous auto-roaming try,We should smart scan periodically!	   
                                       */
                                       	if(priv.bFindSameAPInFastRoaming ||
                                       		((priv.bFindSameAPInFastRoaming == FALSE) &&
                                       		((iAutoRoamingCount % AUTO_ROAMING_COUNTS_FOR_SMART_SCAN) == 0)))
                                       	{
								SmartScan(&priv);
							}
						}
					}
				}
				else
				{
#ifdef DEBUG_PARA_ROAMING_PRINT
					RETAILMSG(1,(TEXT("Before handoff: Can NOT scan caused by scan or associate is in progress!!!\n")));
#endif
				}
			}
			if(priv.RoamingPolicy == BEST_RSSI_GIVEN_SSID)
			{//profile set by WZC interface
			
				priv.bProfileSetWiFiConnected = FALSE; 
				//Find the best AP with given SSID from scan list
				iSearchRst = ParaSearchAPInScanList(&priv,&priv.FreeRoamingSSID,NULL,
									Ndis802_11Infrastructure,priv.RoamingPolicy);
			}
			else
			{//profile set by PARAGON interface
			
				//Find the best AP with given roaming policy from scan list
				iSearchRst = ParaSearchAPInScanList(&priv,NULL,NULL,
									Ndis802_11Infrastructure,priv.RoamingPolicy);
			}
			//restore PARAGON's default roaming policy					
			priv.RoamingPolicy = BEST_RSSI_GIVEN_PROFILES;
			
                    if(iSearchRst >= 0 && iSearchRst <MRVDRV_MAX_BSSID_LIST)
			{
#ifdef CONFIG_WLAN_PMU
                            wlan_PMUGotRelatedAPs (TRUE);
#endif
				/*TODO:
				/*Notify PMU module: Related AP exist!
				*/
#ifdef DEBUG_PARA_ROAMING_PRINT
				RETAILMSG(1,(TEXT("AutoRoamingThread:Find the fit AP!...\n")));
#endif
				priv.bHandoffViaBSSID = TRUE;
				
				// Set the handoff BSSID's Index
				Adapter->ulAttemptedBSSIDIndex = iSearchRst;
				
				// Set the handoff BSSID 
				NdisMoveMemory(priv.HandoffBSSID, 
					Adapter->PSBSSIDList[iSearchRst].MacAddress, 
			          	MRVDRV_ETH_ADDR_LEN);

				// Set the handoff SSID
				NdisMoveMemory(&priv.HandoffSSID, 
					&Adapter->PSBSSIDList[iSearchRst].Ssid, 
			          	sizeof(NDIS_802_11_SSID));

    				ucAttemptedProfileIdx = Adapter->ProfileListCursor;

                            if(Adapter->PSBSSIDList[iSearchRst].Ssid.Ssid[0] == '\0')
                            {
                            	NdisMoveMemory(&priv.HandoffSSID, 
                            		&priv.ProfileAllList.Profiles[ucAttemptedProfileIdx].Ssid, 
                            			sizeof(NDIS_802_11_SSID));
                            }
				//Needn't handoff if suitable AP is still the current connected one!
				if((Adapter->MediaConnectStatus == NdisMediaStateConnected)
					&& (NdisEqualMemory(Adapter->PSBSSIDList[iSearchRst].MacAddress, 
							Adapter->CurrentBSSID,MRVDRV_ETH_ADDR_LEN)))
				{
					priv.bFastAutoRoaming = TRUE;
					priv.bFindSameAPInFastRoaming = TRUE;

#ifdef CONFIG_VERTICAL_HANDOFF
					if(Adapter->LastRSSI < priv.VerticalHandoffCfg.RoveOut_RSSIThreshold)
#else					
					if(Adapter->LastRSSI < PARA_RSSI_ROAMING_THRESHOLD)
#endif
					{
						RETAILMSG(1,(TEXT("Leaving the current connected AP far away,so need fast-roaming  now! :)\n")));
#ifdef DEBUG_PARA_ROAMING_PRINT
						ParaPrintFile("\n[AutoRoamingThread]Leaving the current connected AP far away,so need fast-roaming  now! :)goto retry_roaming....\n");
#endif						
						goto retry_roaming;
					}
					else
					{
						RETAILMSG(1,(TEXT("Current connected AP is closing,so need NOT fast-roaming  now! ^_^ :)\n")));					
#ifdef CONFIG_VERTICAL_HANDOFF
						/*start timer to get beacon's rssi periodicly!*/
						NdisMSetTimer(&priv.GetBeaconRSSITimer, BEACON_RSSI_LISTEN_INTERVAL);      
						priv.bGetBeaconRSSITimerIsSet= TRUE;
#endif
#ifdef DEBUG_PARA_ROAMING_PRINT
						ParaPrintFile("\n[AutoRoamingThread]Current connected AP is closing,so need NOT fast-roaming  now! ^_^ :)goto roaming_finished....\n");
#endif
						goto roaming_finished;
					}
				}
				else//Execute the handoff now......
				{
					if(Adapter->MediaConnectStatus == NdisMediaStateConnected)
					{
						priv.bFastAutoRoaming = TRUE;
					}
					else
					{
						priv.bFastAutoRoaming = FALSE;						
					}
					priv.bFindSameAPInFastRoaming = FALSE;	
					
					if((!priv.bManualRoamingInProcess) && (!Adapter->bIsScanInProgress)
					 	&& (!Adapter->bIsAssociateInProgress ))
					{
		#ifdef PARA_WPA_1X
						RETAILMSG(1,(TEXT("AutoRoaming handoffhandler start :)\n")));
						DBGPRINT(DBG_ALL,("AutoRoaming handoffhandler start :)\n"));
						HandOffhandlerRetCode=HandoffHandler(&priv,ucAttemptedProfileIdx) ;
						RETAILMSG(1,(TEXT("AutoRoaming handoffhandler end :)\n")));
						DBGPRINT(DBG_ALL,("AutoRoaming handoffhandler end :)\n"));
						if(HandOffhandlerRetCode< 0)
						{//Exceptional quit from handoff
#ifdef DEBUG_PARA_ROAMING_PRINT
							ParaPrintFile("\n[AutoRoamingThread]Exceptional quit from handoff:(goto retry_roaming....\n");
#endif						
							goto retry_roaming;	
						}

		#else
						if(HandoffHandler(&priv,ucAttemptedProfileIdx) < 0)
						{//Exceptional quit from handoff
#ifdef DEBUG_PARA_ROAMING_PRINT
							ParaPrintFile("\n[AutoRoamingThread]Exceptional quit from handoff:(goto retry_roaming....\n");
#endif
							goto retry_roaming;	
						}
		#endif
					}
				}
			}
			else//Can NOT find any fit AP
			{
				if(Adapter->MediaConnectStatus == NdisMediaStateConnected)
				{
					priv.bFastAutoRoaming = TRUE;
				}
				else
				{
					priv.bFastAutoRoaming = FALSE;						
				}
				priv.bFindSameAPInFastRoaming = FALSE;	
#ifdef CONFIG_WLAN_PMU
				wlan_PMUGotRelatedAPs (FALSE);
#endif
                         /*TODO:
				/*Notify PMU module: Related AP dose NOT exist!
				*/
#ifdef DEBUG_PARA_ROAMING_PRINT
				RETAILMSG(1,(TEXT("Can NOT find any fit AP!...\n")));
#endif
#ifdef DEBUG_PARA_ROAMING_PRINT
				ParaPrintFile("\n[AutoRoamingThread]Can NOT find any fit AP!goto retry_roaming....\n");
#endif
				goto retry_roaming;
			}
			
			if(Adapter->MediaConnectStatus == NdisMediaStateConnected)
			{//roaming successful
                            rmm_CleanBlackBssidList(Adapter);

				/*TODO:
				/*Notify WMG module: WLAN will link up,
				/*Disable any UI's ops on Profile list memory!
				*/ 
				ED_PostMessage(TEXT("WMG"), WMG_PROTECT_PROFILE_MEM, 0, 0);
				
				// Make a copy of current AP's channel
				priv.CurrentChannel =(UCHAR) 
					(Adapter->PSBSSIDList[Adapter->ulAttemptedBSSIDIndex].Configuration.DSConfig-2407)/5;


				//Set current used profile's index
				ucAttemptedProfileIdx = RefreshConnectProfileIdx(&priv);				
				priv.ProfileAllList.CurrentProfileIndex = ucAttemptedProfileIdx;	
				
				for (i=0;i<priv.ProfileAllList.ProfilesNumber;i++){
					priv.ProfileAllList.Profiles[i].CurrentUsed = FALSE;
				}	
				priv.ProfileAllList.Profiles[ucAttemptedProfileIdx].CurrentUsed = TRUE;

				/*TODO:
				/*Notify other module: WLAN is link up!
				*/

				if((priv.ProfileAllList.CurrentProfileIndex != priv.ProfileAllList.PreviousProfileIndex)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?