summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c1
-rw-r--r--MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c24
-rw-r--r--MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h16
-rw-r--r--MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c36
4 files changed, 73 insertions, 4 deletions
diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c
index 3e722a20e6..cd4fbbd196 100644
--- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c
+++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Driver.c
@@ -478,6 +478,7 @@ DhcpInitProtocol (
Instance->RenewRebindEvent = NULL;
Instance->Token = NULL;
Instance->UdpIo = NULL;
+ Instance->ElaspedTime = 0;
NetbufQueInit (&Instance->ResponseQueue);
}
diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
index 0884026db4..b9a85f2333 100644
--- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
+++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.c
@@ -1,7 +1,7 @@
/** @file
This file implement the EFI_DHCP4_PROTOCOL interface.
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -932,6 +932,12 @@ EfiDhcp4RenewRebind (
DhcpSetState (DhcpSb, Dhcp4Rebinding, FALSE);
}
+ //
+ // Clear initial time to make sure that elapsed-time
+ // is set to 0 for first REQUEST in renewal process.
+ //
+ Instance->ElaspedTime = 0;
+
Status = DhcpSendMessage (
DhcpSb,
DhcpSb->Selected,
@@ -1723,3 +1729,19 @@ EfiDhcp4Parse (
return EFI_SUCCESS;
}
+
+/**
+ Set the elapsed time based on the given instance and the pointer to the
+ elapsed time option.
+
+ @param[in] Elapsed The pointer to the position to append.
+ @param[in] Instance The pointer to the Dhcp4 instance.
+**/
+VOID
+SetElapsedTime (
+ IN UINT16 *Elapsed,
+ IN DHCP_PROTOCOL *Instance
+ )
+{
+ WriteUnaligned16 (Elapsed, HTONS(Instance->ElaspedTime));
+}
diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h
index 89045be502..438f4cddf7 100644
--- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h
+++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Impl.h
@@ -6,7 +6,7 @@
RFC 1534: Interoperation Between DHCP and BOOTP
RFC 3396: Encoding Long Options in DHCP.
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -71,6 +71,7 @@ struct _DHCP_PROTOCOL {
EFI_DHCP4_TRANSMIT_RECEIVE_TOKEN *Token;
UDP_IO *UdpIo; // The UDP IO used for TransmitReceive.
UINT32 Timeout;
+ UINT16 ElaspedTime;
NET_BUF_QUEUE ResponseQueue;
};
@@ -183,4 +184,17 @@ DhcpCleanConfigure (
IN OUT EFI_DHCP4_CONFIG_DATA *Config
);
+/**
+ Set the elapsed time based on the given instance and the pointer to the
+ elapsed time option.
+
+ @param[in] Elapsed The pointer to the position to append.
+ @param[in] Instance The pointer to the Dhcp4 instance.
+**/
+VOID
+SetElapsedTime (
+ IN UINT16 *Elapsed,
+ IN DHCP_PROTOCOL *Instance
+ );
+
#endif
diff --git a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
index ba7082e985..65ab5ac702 100644
--- a/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
+++ b/MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
@@ -1,7 +1,7 @@
/** @file
EFI DHCP protocol implementation.
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -37,6 +37,11 @@ DhcpInitRequest (
ASSERT ((DhcpSb->DhcpState == Dhcp4Init) || (DhcpSb->DhcpState == Dhcp4InitReboot));
+ //
+ // Clear initial time to make sure that elapsed-time is set to 0 for first Discover or REQUEST message.
+ //
+ DhcpSb->ActiveChild->ElaspedTime= 0;
+
if (DhcpSb->DhcpState == Dhcp4Init) {
DhcpSetState (DhcpSb, Dhcp4Selecting, FALSE);
Status = DhcpSendMessage (DhcpSb, NULL, NULL, DHCP_MSG_DISCOVER, NULL);
@@ -1218,6 +1223,17 @@ DhcpSendMessage (
EFI_IP4 (Head->ClientAddr) = HTONL (DhcpSb->ClientAddr);
CopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen);
+ if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) {
+ Head->Seconds = 0;
+ } else if ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting)) {
+ //
+ // Use the same value as the original DHCPDISCOVER message.
+ //
+ Head->Seconds = DhcpSb->LastPacket->Dhcp4.Header.Seconds;
+ } else {
+ SetElapsedTime(&Head->Seconds, DhcpSb->ActiveChild);
+ }
+
//
// Append the DHCP message type
//
@@ -1429,7 +1445,12 @@ DhcpRetransmit (
ASSERT (DhcpSb->LastPacket != NULL);
- DhcpSb->LastPacket->Dhcp4.Header.Seconds = HTONS (*(UINT16 *)(&DhcpSb->LastTimeout));
+ //
+ // For REQUEST message in Dhcp4Requesting state, do not change the secs fields.
+ //
+ if (DhcpSb->DhcpState != Dhcp4Requesting) {
+ SetElapsedTime(&DhcpSb->LastPacket->Dhcp4.Header.Seconds, DhcpSb->ActiveChild);
+ }
//
// Wrap it into a netbuf then send it.
@@ -1502,6 +1523,13 @@ DhcpOnTimerTick (
DhcpSb = (DHCP_SERVICE *) Context;
Instance = DhcpSb->ActiveChild;
+
+ //
+ // 0xffff is the maximum supported value for elapsed time according to RFC.
+ //
+ if (Instance != NULL && Instance->ElaspedTime < 0xffff) {
+ Instance->ElaspedTime++;
+ }
//
// Check the retransmit timer
@@ -1593,6 +1621,8 @@ DhcpOnTimerTick (
goto END_SESSION;
}
+ Instance->ElaspedTime= 0;
+
Status = DhcpSendMessage (
DhcpSb,
DhcpSb->Selected,
@@ -1613,6 +1643,8 @@ DhcpOnTimerTick (
goto END_SESSION;
}
+ Instance->ElaspedTime= 0;
+
Status = DhcpSendMessage (
DhcpSb,
DhcpSb->Selected,