/** @file\r
\r
-Copyright (c) 2006 - 2007, Intel Corporation\r
+Copyright (c) 2006 - 2008, Intel Corporation\r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
@param DhcpSb The DHCP service instance\r
\r
@retval EFI_SUCCESS The request has been sent\r
+ @retval other Some error occurs when sending the request.\r
\r
**/\r
EFI_STATUS\r
@retval EFI_ABORTED The user function ask it to abort.\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
DhcpCallUser (\r
IN DHCP_SERVICE *DhcpSb,\r
Notify the user about the operation result.\r
\r
@param DhcpSb DHCP service instance\r
- @param Which which notify function to signal\r
+ @param Which Which notify function to signal\r
\r
@return None\r
\r
}\r
\r
if ((Child->CompletionEvent != NULL) &&\r
- ((Which == DHCP_NOTIFY_COMPLETION) || (Which == DHCP_NOTIFY_ALL))) {\r
+ ((Which == DHCP_NOTIFY_COMPLETION) || (Which == DHCP_NOTIFY_ALL))\r
+ ) {\r
\r
gBS->SignalEvent (Child->CompletionEvent);\r
Child->CompletionEvent = NULL;\r
}\r
\r
if ((Child->RenewRebindEvent != NULL) &&\r
- ((Which == DHCP_NOTIFY_RENEWREBIND) || (Which == DHCP_NOTIFY_ALL))) {\r
+ ((Which == DHCP_NOTIFY_RENEWREBIND) || (Which == DHCP_NOTIFY_ALL))\r
+ ) {\r
\r
gBS->SignalEvent (Child->RenewRebindEvent);\r
Child->RenewRebindEvent = NULL;\r
**/\r
EFI_STATUS\r
DhcpSetState (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN INTN State,\r
- IN BOOLEAN CallUser\r
+ IN OUT DHCP_SERVICE *DhcpSb,\r
+ IN INTN State,\r
+ IN BOOLEAN CallUser\r
)\r
{\r
EFI_STATUS Status;\r
@return None\r
\r
**/\r
-STATIC\r
VOID\r
DhcpSetTransmitTimer (\r
- IN DHCP_SERVICE *DhcpSb\r
+ IN OUT DHCP_SERVICE *DhcpSb\r
)\r
{\r
UINT32 *Times;\r
\r
DhcpSb->PacketToLive = Times[DhcpSb->CurRetry];\r
\r
- if (DhcpSb->DhcpState == Dhcp4Selecting) {\r
- DhcpSb->WaitOffer = DhcpSb->PacketToLive;\r
- }\r
+ return;\r
}\r
\r
/**\r
@return None\r
\r
**/\r
-STATIC\r
VOID\r
DhcpComputeLease (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN DHCP_PARAMETER *Para\r
+ IN OUT DHCP_SERVICE *DhcpSb,\r
+ IN DHCP_PARAMETER *Para\r
)\r
{\r
ASSERT (Para != NULL);\r
such as DHCP release.\r
\r
@param UdpIo The UDP IO port to configure\r
- @param Context The opaque parameter to the function.\r
+ @param Context Dhcp service instance.\r
\r
@retval EFI_SUCCESS The UDP IO port is successfully configured.\r
@retval Others It failed to configure the port.\r
@retval EFI_SUCCESS The lease is recorded.\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
DhcpLeaseAcquired (\r
- IN DHCP_SERVICE *DhcpSb\r
+ IN OUT DHCP_SERVICE *DhcpSb\r
)\r
{\r
INTN Class;\r
\r
if (DhcpSb->Netmask == 0) {\r
Class = NetGetIpClass (DhcpSb->ClientAddr);\r
- DhcpSb->Netmask = mIp4AllMasks[Class << 3];\r
+ DhcpSb->Netmask = gIp4AllMasks[Class << 3];\r
}\r
\r
if (DhcpSb->LeaseIoPort != NULL) {\r
DhcpSb->PacketToLive = 0;\r
DhcpSb->CurRetry = 0;\r
DhcpSb->MaxRetries = 0;\r
- DhcpSb->WaitOffer = 0;\r
DhcpSb->LeaseLife = 0;\r
}\r
\r
@retval EFI_SUCCESS One of the offer is selected.\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
DhcpChooseOffer (\r
IN DHCP_SERVICE *DhcpSb\r
\r
ASSERT (DhcpSb->LastOffer != NULL);\r
\r
- //\r
- // Stop waiting more offers\r
- //\r
- DhcpSb->WaitOffer = 0;\r
-\r
//\r
// User will cache previous offers if he wants to select\r
// from multiple offers. If user provides an invalid packet,\r
@return None\r
\r
**/\r
-STATIC\r
VOID\r
DhcpEndSession (\r
IN DHCP_SERVICE *DhcpSb,\r
@retval Others Some error occured.\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
DhcpHandleSelect (\r
IN DHCP_SERVICE *DhcpSb,\r
// Don't return a error for these two case otherwise the session is ended.\r
//\r
if (!DHCP_IS_BOOTP (Para) &&\r
- ((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))) {\r
+ ((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))\r
+ ) {\r
goto ON_EXIT;\r
}\r
\r
@retval Others Some error occured.\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
DhcpHandleRequest (\r
IN DHCP_SERVICE *DhcpSb,\r
// Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK.\r
//\r
if (DHCP_IS_BOOTP (Para) ||\r
- (Para->ServerId != DhcpSb->Para->ServerId) ||\r
- ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))) {\r
+ (Para->ServerId != DhcpSb->Para->ServerId) ||\r
+ ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))\r
+ ) {\r
\r
Status = EFI_SUCCESS;\r
goto ON_EXIT;\r
@retval Others Some error occured.\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
DhcpHandleRenewRebind (\r
IN DHCP_SERVICE *DhcpSb,\r
// Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK\r
//\r
if (DHCP_IS_BOOTP (Para) ||\r
- (Para->ServerId != DhcpSb->Para->ServerId) ||\r
- ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))) {\r
+ (Para->ServerId != DhcpSb->Para->ServerId) ||\r
+ ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))\r
+ ) {\r
\r
Status = EFI_SUCCESS;\r
goto ON_EXIT;\r
DhcpSb->LeaseLife = 0;\r
DhcpSetState (DhcpSb, Dhcp4Bound, TRUE);\r
\r
- if (DhcpSb->ExtraRefresh) {\r
+ if (DhcpSb->ExtraRefresh != 0) {\r
DhcpSb->ExtraRefresh = FALSE;\r
\r
DhcpSb->IoStatus = EFI_SUCCESS;\r
@retval Others Some error occured.\r
\r
**/\r
-STATIC\r
EFI_STATUS\r
DhcpHandleReboot (\r
IN DHCP_SERVICE *DhcpSb,\r
// Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK\r
//\r
if (DHCP_IS_BOOTP (Para) ||\r
- ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))) {\r
+ ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))\r
+ ) {\r
\r
Status = EFI_SUCCESS;\r
goto ON_EXIT;\r
\r
\r
/**\r
- Handle the received DHCP packets. This function drivers the DHCP\r
+ Handle the received DHCP packets. This function drives the DHCP\r
state machine.\r
\r
@param UdpPacket The UDP packets received.\r
//\r
if ((Head->OpCode != BOOTP_REPLY) ||\r
(NTOHL (Head->Xid) != DhcpSb->Xid) ||\r
- !NET_MAC_EQUAL (&DhcpSb->Mac, Head->ClientHwAddr, DhcpSb->HwLen)) {\r
+ (CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0)) {\r
goto RESTART;\r
}\r
\r
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources for the packet\r
@retval EFI_ACCESS_DENIED Failed to transmit the packet through UDP\r
@retval EFI_SUCCESS The message is sent\r
+ @retval other Other error occurs\r
\r
**/\r
EFI_STATUS\r
// 3. DHCP request to confirm one lease.\r
//\r
if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE) ||\r
- ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting))) {\r
+ ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting))\r
+ ) {\r
\r
ASSERT ((Para != NULL) && (Para->ServerId != 0));\r
\r
Packet = NewPacket;\r
}\r
\r
+ //\r
+ // Save the Client Address will be sent out\r
+ //\r
+ CopyMem (\r
+ &DhcpSb->ClientAddressSendOut[0],\r
+ &Packet->Dhcp4.Header.ClientHwAddr[0],\r
+ Packet->Dhcp4.Header.HwAddrLen\r
+ );\r
+\r
+\r
//\r
// Wrap it into a netbuf then send it.\r
//\r
DHCP_SERVICE *DhcpSb;\r
DHCP_PROTOCOL *Instance;\r
EFI_STATUS Status;\r
- \r
+\r
DhcpSb = (DHCP_SERVICE *) Context;\r
Instance = DhcpSb->ActiveChild;\r
-\r
+ \r
//\r
- // Check the time to wait offer\r
+ // Check the retransmit timer\r
//\r
- if ((DhcpSb->WaitOffer > 0) && (--DhcpSb->WaitOffer == 0)) {\r
+ if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) {\r
+\r
//\r
- // OK, offer collection finished, select a offer\r
+ // Select offer at each timeout if any offer received.\r
//\r
- ASSERT (DhcpSb->DhcpState == Dhcp4Selecting);\r
+ if (DhcpSb->DhcpState == Dhcp4Selecting && DhcpSb->LastOffer != NULL) {\r
\r
- if (DhcpSb->LastOffer == NULL) {\r
- goto END_SESSION;\r
- }\r
+ Status = DhcpChooseOffer (DhcpSb);\r
\r
- if (EFI_ERROR (DhcpChooseOffer (DhcpSb))) {\r
- goto END_SESSION;\r
+ if (EFI_ERROR(Status)) {\r
+ FreePool (DhcpSb->LastOffer);\r
+ DhcpSb->LastOffer = NULL;\r
+ } else {\r
+ goto ON_EXIT;\r
+ }\r
}\r
- }\r
- \r
- //\r
- // Check the retransmit timer\r
- //\r
- if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) {\r
-\r
+ \r
if (++DhcpSb->CurRetry < DhcpSb->MaxRetries) {\r
//\r
// Still has another try\r
DhcpRetransmit (DhcpSb);\r
DhcpSetTransmitTimer (DhcpSb);\r
\r
- } else {\r
- if (!DHCP_CONNECTED (DhcpSb->DhcpState)) {\r
- goto END_SESSION;\r
- }\r
+ } else if (DHCP_CONNECTED (DhcpSb->DhcpState)) {\r
\r
//\r
// Retransmission failed, if the DHCP request is initiated by\r
// user, adjust the current state according to the lease life.\r
// Otherwise do nothing to wait the lease to timeout\r
//\r
- if (DhcpSb->ExtraRefresh) {\r
+ if (DhcpSb->ExtraRefresh != 0) {\r
Status = EFI_SUCCESS;\r
\r
if (DhcpSb->LeaseLife < DhcpSb->T1) {\r
DhcpSb->IoStatus = EFI_TIMEOUT;\r
DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_RENEWREBIND);\r
}\r
+ } else {\r
+ goto END_SESSION;\r
}\r
}\r
\r
// Don't timeout the lease, only count the life if user is\r
// requesting extra renew/rebind. Adjust the state after that.\r
//\r
- if (DhcpSb->ExtraRefresh) {\r
+ if (DhcpSb->ExtraRefresh != 0) {\r
return ;\r
}\r
\r
}\r
}\r
\r
- //\r
- //\r
- //\r
+ON_EXIT:\r
if ((Instance != NULL) && (Instance->Token != NULL)) {\r
Instance->Timeout--;\r
if (Instance->Timeout == 0) {\r