tcpiputils/dhcp/src/DHCPIP4States.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implements the DHCPv4 States representing each interface
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file DHCPIP4States.cpp
       
    20  @internalTechnology
       
    21 */
       
    22 
       
    23 #include "DHCPIP4States.h"
       
    24 #include "DHCPMsg.h"
       
    25 #include "DHCPServer.h"
       
    26 
       
    27 #include "DHCPStatesDebug.h"
       
    28 
       
    29 CAsynchEvent* CDHCPIP4Select::ProcessL(TRequestStatus& aStatus)
       
    30 /**
       
    31   * Interface function, execute state machine
       
    32   *
       
    33   * @internalTechnology
       
    34   */
       
    35 	{
       
    36 	DHCP_DEBUG_PUBLISH_STATE(DHCPDebug::EDHCPIP4Select);
       
    37 	CDHCPIP4StateMachine& rDHCPIPv4 = DHCPIPv4();
       
    38 	
       
    39 	if (rDHCPIPv4.iReceiving)
       
    40 		{		
       
    41 		if((rDHCPIPv4.GetMessageTypeL() == DHCPv4::EDHCPOffer) && rDHCPIPv4.CheckXid())
       
    42 			{
       
    43 			return CDHCPSelect::ProcessL(aStatus);
       
    44 			}
       
    45 		else
       
    46 			{
       
    47 			rDHCPIPv4.iReceiving = EFalse;
       
    48 			}	
       
    49 		}				
       
    50 	return rDHCPIPv4.ReceiveL(&aStatus);	
       
    51 	}
       
    52 
       
    53 #ifdef SYMBIAN_NETWORKING_DHCPSERVER	
       
    54 CAsynchEvent* CDHCPIP4HandleClientMsgs::ProcessL(TRequestStatus& aStatus)
       
    55 /**
       
    56   * Interface function, execute state machine
       
    57   *
       
    58   * @internalTechnology
       
    59   */
       
    60 	{
       
    61 	__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPIP4HandleClientMsgs::ProcessL")));
       
    62 	
       
    63 	DHCP_DEBUG_PUBLISH_STATE(DHCPDebug::EDHCPIP4HandleClientMsgs);
       
    64 	CDHCPIP4StateMachine& rDHCPv4  = DHCPIPv4();
       
    65 	rDHCPv4.iReceiving = EFalse;
       
    66 	
       
    67 #ifdef SYMBIAN_NETWORKING_ADDRESS_PROVISION
       
    68 	TBool provisioned = rDHCPv4.ClientHwAddrProvisioned();
       
    69 	if(provisioned)
       
    70 		{
       
    71 #endif //SYMBIAN_NETWORKING_ADDRESS_PROVISION
       
    72 		rDHCPv4.CheckClientMsgL();
       
    73 #ifdef SYMBIAN_NETWORKING_ADDRESS_PROVISION
       
    74 		}
       
    75 #endif //SYMBIAN_NETWORKING_ADDRESS_PROVISION
       
    76 	// self complete to continue the state machine
       
    77 	TRequestStatus* p = &aStatus;
       
    78 	User::RequestComplete(p, KErrNone);
       
    79 	return iNext;
       
    80 	}	
       
    81 	
       
    82 CAsynchEvent* CDHCPIP4SendRequestResponse::ProcessL(TRequestStatus& aStatus)
       
    83 	{
       
    84 	__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPIP4SendRequestResponse::ProcessL")));
       
    85 	
       
    86 	DHCP_DEBUG_PUBLISH_STATE(DHCPDebug::EDHCPIP4SendRequestResponse);
       
    87 	CDHCPIP4StateMachine& rDHCPIPv4 = DHCPIPv4();
       
    88 	
       
    89 	if (rDHCPIPv4.iReceiving)
       
    90 		{		
       
    91 		if((rDHCPIPv4.GetClientMessageTypeL() == DHCPv4::EDHCPRequest))
       
    92 			{
       
    93 			if(rDHCPIPv4.CheckXid())
       
    94 				{
       
    95 				// this is from the same client which we last serviced
       
    96 				return CDHCPSendRequestResponse::ProcessL(aStatus);	
       
    97 				}
       
    98 			else 
       
    99 				{
       
   100 				// this request is not from the same client as the one we recently serviced  
       
   101 				// check if this was a renew/rebind request from a client whom we provided an IP address in the past
       
   102 				// then we need to service this client and not ignore it
       
   103 				TUint32 clientAddr = rDHCPIPv4.GetClientIPAddress();
       
   104 				if(rDHCPIPv4.GetIPAddressToOffer() == clientAddr ||
       
   105 						!clientAddr)
       
   106 					{
       
   107 					rDHCPIPv4.SetClientIdentified(ETrue);
       
   108 					return 	CDHCPSendRequestResponse::ProcessL(aStatus);	
       
   109 					}
       
   110 				else
       
   111 					{
       
   112 					// unexpected packet, proceed to recieve the packet and discard.
       
   113 					__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPIP4SendRequestResponse::ProcessL Unexpected packet")));
       
   114 					rDHCPIPv4.iReceiving = EFalse;
       
   115 					} 
       
   116 				}	
       
   117 			}
       
   118 		else
       
   119 			{
       
   120 			rDHCPIPv4.iReceiving = EFalse;
       
   121 			}	
       
   122 		}				
       
   123 	return rDHCPIPv4.ReceiveOnPort67L(&aStatus);
       
   124 	}
       
   125 	
       
   126 CAsynchEvent* CDHCPIP4SendInformResponse::ProcessL(TRequestStatus& aStatus)
       
   127 	{
       
   128 	__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPIP4SendInformResponse::ProcessL")));
       
   129 	
       
   130 	DHCP_DEBUG_PUBLISH_STATE(DHCPDebug::EDHCPIP4SendInformResponse);	
       
   131 	CDHCPIP4StateMachine& rDHCPIPv4 = DHCPIPv4();
       
   132 	
       
   133 	if (rDHCPIPv4.iReceiving)
       
   134 		{		
       
   135 		if((rDHCPIPv4.GetClientMessageTypeL() == DHCPv4::EDHCPInform))
       
   136 			{
       
   137 			return CDHCPSendInformResponse::ProcessL(aStatus);
       
   138 			}
       
   139 		else
       
   140 			{
       
   141 			rDHCPIPv4.iReceiving = EFalse;
       
   142 			}	
       
   143 		}				
       
   144 	return rDHCPIPv4.ReceiveOnPort67L(&aStatus);
       
   145 	}	
       
   146 
       
   147 void CDHCPIP4BindServer::TimerExpired()
       
   148 	{
       
   149 	CDHCPStateMachine& rDHCP = Dhcp();
       
   150 	CDHCPBindServer::TimerExpired();
       
   151 	if ( !rDHCP.TimerActive() )
       
   152 		{
       
   153 		//finish either => bound or not
       
   154 		TRequestStatus* p = &iStateMachine->iStatus;
       
   155 		User::RequestComplete(p, iErr); 
       
   156 		rDHCP.SetAsyncCancelHandler(NULL);
       
   157 		}
       
   158 	}
       
   159 		
       
   160 #endif // SYMBIAN_NETWORKING_DHCPSERVER
       
   161 
       
   162 void CDHCPIP4WaitForDAD::TimerExpired()
       
   163 	{
       
   164 	CDHCPStateMachine& rDHCP = Dhcp();
       
   165 	CDHCPWaitForDADBind::TimerExpired();
       
   166 	if ( !rDHCP.TimerActive() )
       
   167 		{
       
   168 		//finish either => bound or not
       
   169 		TRequestStatus* p = &iStateMachine->iStatus;
       
   170 		User::RequestComplete(p, iErr); 
       
   171 		rDHCP.SetAsyncCancelHandler(NULL);
       
   172 		}
       
   173 	}
       
   174 	
       
   175 
       
   176