pararoamingproc.c

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

C
1,981
字号
					      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("ManualRoaming NdisMediaStateDisconnected is caused by ManualRoaming!...\n")));
#endif
DBGPRINT(DBG_ALL,("ManualRoaming NdisMediaStateDisconnected is caused by ManualRoaming!...\n"));
				WriteCommonLogFile(WIFI_LOG,"AP is disconnected(Reason=3)  (ManualRoaming)!...\r\n",
								strlen("AP is disconnected(Reason=3)	(ManualRoaming)!...\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);				
				/*TODO:
				/*Notify other module: WLAN is link down!
				*/
#ifdef CONFIG_WLAN_PMU
				wlan_PMUMsgRMMLinkStatus (1);
#endif
				priv.bAddedPrelistByPRM = RMM_ADD_PREFERLIST_FAILED;
#if 0
                            wlan_RMMCancelRetryPRMLinkupStatusTimer();
#endif
				ED_PostMessage(TEXT("PRM"), PRM_LINKDOWN, 0, 0);		
#ifdef DEBUG_PARA_ROAMING_PRINT
				ParaPrintFile("\n[ManualRoamingThread]profiles is error!ED_PostMessage---->PRM_LINKDOWN,so goto manual_set_finished....\n");
#endif				
				goto manual_set_finished;
			}
			else//profiles correct!
			{
				//Set profile but WiFi not connected~!
				priv.bProfileSetWiFiConnected = FALSE;
				
				//Change Channel list by received profiles
				ChangeChanListByProfiles(&priv);	

				if((Adapter->MediaConnectStatus == NdisMediaStateConnected)
					&& (!(NdisEqualMemory(Adapter->NullBSSID, 
							Adapter->CurrentBSSID,MRVDRV_ETH_ADDR_LEN))))
				{
					//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("ManualRoaming NdisMediaStateDisconnected is caused by ManualRoaming!...\n")));
#endif
WriteCommonLogFile(WIFI_LOG,"AP is disconnected(Reason=3)  (ManualRoaming)!...\r\n",
				strlen("AP is disconnected(Reason=3)	(ManualRoaming)!...\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;
}


DBGPRINT(DBG_ALL,("ManualRoaming NdisMediaStateDisconnected is caused by ManualRoaming!...\n"));

				// 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 )){
					AllChannelScan(&priv);	
				}
				else
				{
#ifdef DEBUG_PARA_ROAMING_PRINT
					RETAILMSG(1,(TEXT("ManualRoaming Profile got correct: Can NOT scan caused by scan or associate is in progress!!!\n")));
#endif
DBGPRINT(DBG_ALL,("ManualRoaming Profile got correct: Can NOT scan caused by scan or associate is in progress!!!\n"));

				}
				
				//Set the top-priority handoff profile's index is 0
				ucAttemptedProfileIdx = 0;

				// Set the top-priority handoff SSID
				NdisMoveMemory(&TopPriorityHandoffSSID, 
					&(priv.ProfileAllList.Profiles[ucAttemptedProfileIdx].Ssid), 
			          	sizeof(NDIS_802_11_SSID));				
			
				priv.bProfileSetWiFiConnected = FALSE; 
				//Find the best AP with given SSID from scan list
				iSearchRst = ParaSearchAPInScanList(&priv,&TopPriorityHandoffSSID,NULL,
									Ndis802_11Infrastructure,BEST_RSSI_GIVEN_SSID);

				//restore PARAGON's default roaming policy					
				priv.RoamingPolicy = BEST_RSSI_GIVEN_PROFILES;

				if( iSearchRst >= 0 )//find the fit AP
				{
#ifdef CONFIG_WLAN_PMU
                                    wlan_PMUGotRelatedAPs (TRUE);
#endif
                                   /*TODO:
					/*Notify PMU module: Related AP exist!
					*/
#ifdef DEBUG_PARA_ROAMING_PRINT
					RETAILMSG(1,(TEXT("Find the fit AP!...\n")));
#endif	
DBGPRINT(DBG_ALL,("Find the fit AP!...\n"));

					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));

					if((!Adapter->bIsScanInProgress) && (!Adapter->bIsAssociateInProgress ))
					{
						//Execute the handoff now......
		#ifdef PARA_WPA_1X
						RETAILMSG(1,(TEXT("ManualRoaming handoffhandler start :)\n")));
						DBGPRINT(DBG_ALL,("ManualRoaming handoffhandler start :)\n"));
						HandOffhandlerRetCode=HandoffHandler(&priv,ucAttemptedProfileIdx) ;
						RETAILMSG(1,(TEXT("ManualRoaming handoffhandler end :)\n")));
						DBGPRINT(DBG_ALL,("ManualRoaming handoffhandler end :)\n"));
						if(HandOffhandlerRetCode< 0)
						{//Exceptional quit from handoff
							//Clear manual-roaming flag 
							priv.bManualRoamingInProcess = FALSE;
							bRetryAutoRoaming = TRUE;
#ifdef DEBUG_PARA_ROAMING_PRINT
							ParaPrintFile("\n[ManualRoamingThread]Exceptional quit from handoff,so goto retry_auto_roaming....\n");
#endif								
							goto retry_auto_roaming;	
						}

		#else
						if(HandoffHandler(&priv,ucAttemptedProfileIdx) < 0)
						{//Exceptional quit from handoff
							//Clear manual-roaming flag 
							priv.bManualRoamingInProcess = FALSE;
							bRetryAutoRoaming = TRUE;
#ifdef DEBUG_PARA_ROAMING_PRINT
							ParaPrintFile("\n[ManualRoamingThread]Exceptional quit from handoff,so goto retry_auto_roaming....\n");
#endif							
							goto retry_auto_roaming;	
						}
		#endif
					}
				}
				else//Can NOT find any fit AP
				{
#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						
DBGPRINT(DBG_ALL,("Can NOT find any fit AP!...\n"));

					//Clear manual-roaming flag 
					priv.bManualRoamingInProcess = FALSE;
					bRetryAutoRoaming = TRUE;
#ifdef DEBUG_PARA_ROAMING_PRINT
					ParaPrintFile("\n[ManualRoamingThread]Can NOT find any fit AP,so goto retry_auto_roaming....\n");
#endif					
					goto retry_auto_roaming;
				}

				if(Adapter->MediaConnectStatus == NdisMediaStateConnected)
				{//set successful				

					// 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!
					*/
					
					//Whatever, notify other module: enter into another net and link up
					priv.bAddedPrelistByPRM = RMM_ADDING_PREFERLIST;	
			#ifdef PARA_WPA_1X
					if(HandOffhandlerRetCode!=HANDOFF_HAD_POSTED_LINK_UP){
			#endif
					ED_PostMessage(TEXT("PRM"), PRM_LINKUP, 1, priv.ProfileAllList.CurrentProfileIndex);
#if 0
					wlan_RMMSetRetryPRMLinkupStatusTimer();
#endif
			#ifdef PARA_WPA_1X
					}
					else
					{
						ED_PostMessage(TEXT("PRM"), PRM_LINKUP, 3, priv.ProfileAllList.CurrentProfileIndex);
					}
			#endif

#ifdef CONFIG_WLAN_PMU
                                    wlan_PMUMsgRMMLinkStatus (0);
#endif


//#ifdef DEBUG_PARA_ROAMING_PRINT
					RETAILMSG(1,(TEXT("ManualRoamingThread:Indicate the NDIS that media is CONNECTED!\n")));
//#endif

					//Sleep(10);
					//NdisMSleep(100);
					// indicate the NDIS the media is connected
					/*NdisMIndicateStatus(Adapter->MrvDrvAdapterHdl,
						NDIS_STATUS_MEDIA_CONNECT,
						(PVOID)NULL, 
						0);
					NdisMIndicateStatusComplete(Adapter->MrvDrvAdapterHdl);
*/
					if(!priv.bProfileSetWiFiConnected)
					{
						priv.bProfileSetWiFiConnected = TRUE; 
					}
					
					//Wake up OID_SET_SSID thread...!
					/*if(priv.bOID_SET_SSID)
					{
						// indicate the NDIS SetInformation OID_802_11_SSID is successful ~!
						//NdisMSetInformationComplete(Adapter->MrvDrvAdapterHdl,
				          	//								NDIS_STATUS_SUCCESS);						
						SetEvent(priv.hOIDSetSSIDFinishedEvent);
					}*/
#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[ManualRoamingThread]Set successfully!!ED_PostMessage----->PRM_LINKUP,so goto manual_set_finished....\n");
#endif	
					goto manual_set_finished;
				}
				else
				{//set failed
					//Clear manual-roaming flag 
					priv.bManualRoamingInProcess = FALSE;
					bRetryAutoRoaming = TRUE;
#ifdef DEBUG_PARA_ROAMING_PRINT
					ParaPrintFile("\n[ManualRoamingThread]Set failed!!so goto retry_auto_roaming....\n");
#endif						
					goto retry_auto_roaming;	
				}
				
			}//end of profiles correct!
manual_set_finished:
#ifdef DEBUG_PARA_ROAMING_PRINT
			ParaPrintFile("\n[ManualRoamingThread]manual_set_finished!!!\n");
#endif
			//Clear manual-roaming flag 
			priv.bManualRoamingInProcess = FALSE;
			
			//Stop the auto-roaming timer
			if (priv.bAutoRoamingTimerIsSet)
			{   

                            NdisMCancelTimer(&priv.AutoRoamingTimer, &timerStatus);
                            
				priv.bAutoRoamingTimerIsSet = FALSE;
			}

			//Stop the data busy retry-roaming timer
			if (priv.bDataBusyRetryRoamingTimerIsSet)
			{   
				NdisMCancelTimer(&priv.DataBusyRetryRoamingTimer, &timerStatus);
				priv.bDataBusyRetryRoamingTimerIsSet = FALSE;
			}
			
retry_auto_roaming:
			if(bRetryAutoRoaming)
			{
#ifdef DEBUG_PARA_ROAMING_PRINT
				ParaPrintFile("\n[ManualRoamingThread]retry_auto_roaming!!!\n");
#endif			
				bRetryAutoRoaming = FALSE;
#ifdef DEBUG_PARA_ROAMING_PRINT
				RETAILMSG(1,(TEXT("ManualRoaming Wake up auto-roaming!Caused by manual-roaming...\n")));
#endif	
DBGPRINT(DBG_ALL,("ManualRoaming Wake up auto-roaming!Caused by manual-roaming...\n"));

				priv.bFastAutoRoaming = FALSE;
				SetEvent(priv.hAutoRoamingEvent);
			}
		}
//#ifdef DEBUG_PARA_ROAMING_PRINT
		RETAILMSG(1,(TEXT("ManualRoaming End and wait next wakeup event...\n")));
//#endif			
	}

	
}


void WlanSmartDetectionThread(PVOID pContext)
{
	DWORD         waitStatus;
	
	PMRVDRV_ADAPTER   Adapter = priv.pAdapter;

	CeSetThreadPriority(GetCurrentThread(), 150); 

	for (;;)
	{
		//wait until WlanSmartDetectionEvent trigger happenned!
		ResetEvent(priv.hWlanSmartDetectionEvent);	
		waitStatus = WaitForSingleObject(priv.hWlanSmartDetectionEvent, INFINITE);
		if (WAIT_OBJECT_0 != waitStatus)

⌨️ 快捷键说明

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