/** @file\r
EFI DHCP protocol implementation.\r
\r
-Copyright (c) 2006 - 2009, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+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
http://opensource.org/licenses/bsd-license.php\r
\r
ASSERT ((DhcpSb->DhcpState == Dhcp4Init) || (DhcpSb->DhcpState == Dhcp4InitReboot));\r
\r
+ //\r
+ // Clear initial time to make sure that elapsed-time is set to 0 for first Discover or REQUEST message.\r
+ //\r
+ DhcpSb->ActiveChild->ElaspedTime= 0;\r
+ \r
if (DhcpSb->DhcpState == Dhcp4Init) {\r
DhcpSetState (DhcpSb, Dhcp4Selecting, FALSE);\r
Status = DhcpSendMessage (DhcpSb, NULL, NULL, DHCP_MSG_DISCOVER, NULL);\r
\r
@param DhcpSb The DHCP service instance\r
@param Para The DHCP parameter extracted from the server's\r
- response. \r
+ response.\r
**/\r
VOID\r
DhcpComputeLease (\r
DHCP driver needs this port to unicast packet to the server\r
such as DHCP release.\r
\r
- @param[in] UdpIo The UDP IO port to configure\r
+ @param[in] UdpIo The UDP IO to configure\r
@param[in] Context Dhcp service instance.\r
\r
@retval EFI_SUCCESS The UDP IO port is successfully configured.\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
DhcpConfigLeaseIoPort (\r
- IN UDP_IO_PORT *UdpIo,\r
+ IN UDP_IO *UdpIo,\r
IN VOID *Context\r
)\r
{\r
\r
ZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS));\r
\r
- Status = UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfigData);\r
+ Status = UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData);\r
\r
if (EFI_ERROR (Status)) {\r
return Status;\r
Ip = HTONL (DhcpSb->Para->Router);\r
CopyMem (&Gateway, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
\r
- UdpIo->Udp->Routes (UdpIo->Udp, FALSE, &Subnet, &Subnet, &Gateway);\r
+ UdpIo->Protocol.Udp4->Routes (UdpIo->Protocol.Udp4, FALSE, &Subnet, &Subnet, &Gateway);\r
}\r
\r
return EFI_SUCCESS;\r
}\r
\r
if (DhcpSb->LeaseIoPort != NULL) {\r
- UdpIoFreePort (DhcpSb->LeaseIoPort);\r
+ UdpIoFreeIo (DhcpSb->LeaseIoPort);\r
}\r
\r
//\r
// and transmit unicast packet with it as source address. Don't\r
// start receive on this port, the queued packet will be timeout.\r
//\r
- DhcpSb->LeaseIoPort = UdpIoCreatePort (\r
+ DhcpSb->LeaseIoPort = UdpIoCreateIo (\r
DhcpSb->Controller,\r
DhcpSb->Image,\r
DhcpConfigLeaseIoPort,\r
+ UDP_IO_UDP4_VERSION,\r
DhcpSb\r
);\r
\r
DhcpSb->DhcpState = Dhcp4Init;\r
DhcpSb->Xid = DhcpSb->Xid + 1;\r
DhcpSb->ClientAddr = 0;\r
+ DhcpSb->Netmask = 0;\r
DhcpSb->ServerAddr = 0;\r
\r
if (DhcpSb->LastOffer != NULL) {\r
DhcpSb->ExtraRefresh = FALSE;\r
\r
if (DhcpSb->LeaseIoPort != NULL) {\r
- UdpIoFreePort (DhcpSb->LeaseIoPort);\r
+ UdpIoFreeIo (DhcpSb->LeaseIoPort);\r
DhcpSb->LeaseIoPort = NULL;\r
}\r
\r
DhcpSb->CurRetry = 0;\r
DhcpSb->MaxRetries = 0;\r
DhcpSb->LeaseLife = 0;\r
+\r
+ //\r
+ // Clean active config data.\r
+ //\r
+ DhcpCleanConfigure (&DhcpSb->ActiveConfig);\r
}\r
\r
\r
TempPacket = (EFI_DHCP4_PACKET *) AllocatePool (NewPacket->Size);\r
if (TempPacket != NULL) {\r
CopyMem (TempPacket, NewPacket, NewPacket->Size);\r
- gBS->FreePool (Selected);\r
+ FreePool (Selected);\r
Selected = TempPacket;\r
}\r
}\r
return EFI_SUCCESS;\r
\r
ON_EXIT:\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
return Status;\r
}\r
\r
DhcpSb->IoStatus = EFI_SUCCESS;\r
DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_COMPLETION);\r
\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
return EFI_SUCCESS;\r
\r
REJECT:\r
DhcpSendMessage (DhcpSb, DhcpSb->Selected, DhcpSb->Para, DHCP_MSG_DECLINE, Message);\r
\r
ON_EXIT:\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
return Status;\r
}\r
\r
}\r
\r
ON_EXIT:\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
return Status;\r
}\r
\r
return EFI_SUCCESS;\r
\r
ON_EXIT:\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
return Status;\r
}\r
\r
state machine.\r
\r
@param UdpPacket The UDP packets received.\r
- @param Points The local/remote UDP access points\r
+ @param EndPoint The local/remote UDP access point\r
@param IoStatus The status of the UDP receive\r
@param Context The opaque parameter to the function.\r
\r
**/\r
VOID\r
+EFIAPI\r
DhcpInput (\r
NET_BUF *UdpPacket,\r
- UDP_POINTS *Points,\r
+ UDP_END_POINT *EndPoint,\r
EFI_STATUS IoStatus,\r
VOID *Context\r
)\r
DhcpSb = (DHCP_SERVICE *) Context;\r
\r
//\r
- // Don't restart receive if error occurs or DHCP is destoried.\r
+ // Don't restart receive if error occurs or DHCP is destroyed.\r
//\r
if (EFI_ERROR (IoStatus)) {\r
return ;\r
- } else if (DhcpSb->ServiceState == DHCP_DESTORY) {\r
+ } else if (DhcpSb->ServiceState == DHCP_DESTROY) {\r
NetbufFree (UdpPacket);\r
return ;\r
}\r
//\r
// Ignore the packet in INITREBOOT, INIT and BOUND states\r
//\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
Status = EFI_SUCCESS;\r
break;\r
\r
\r
if (EFI_ERROR (Status)) {\r
NetbufFree (UdpPacket);\r
+ UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);\r
DhcpEndSession (DhcpSb, Status);\r
return ;\r
}\r
NetbufFree (UdpPacket);\r
\r
if (Packet != NULL) {\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
}\r
\r
Status = UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);\r
\r
**/\r
VOID\r
+EFIAPI\r
DhcpReleasePacket (\r
IN VOID *Arg\r
)\r
{\r
- gBS->FreePool (Arg);\r
+ FreePool (Arg);\r
}\r
\r
\r
Release the net buffer when packet is sent.\r
\r
@param UdpPacket The UDP packets received.\r
- @param Points The local/remote UDP access points\r
+ @param EndPoint The local/remote UDP access point\r
@param IoStatus The status of the UDP receive\r
@param Context The opaque parameter to the function.\r
\r
**/\r
VOID\r
+EFIAPI\r
DhcpOnPacketSent (\r
NET_BUF *Packet,\r
- UDP_POINTS *Points,\r
+ UDP_END_POINT *EndPoint,\r
EFI_STATUS IoStatus,\r
VOID *Context\r
)\r
EFI_DHCP4_PACKET *NewPacket;\r
EFI_DHCP4_HEADER *Head;\r
EFI_DHCP4_HEADER *SeedHead;\r
- UDP_IO_PORT *UdpIo;\r
- UDP_POINTS EndPoint;\r
+ UDP_IO *UdpIo;\r
+ UDP_END_POINT EndPoint;\r
NET_BUF *Wrap;\r
NET_FRAGMENT Frag;\r
EFI_STATUS Status;\r
EFI_IP4 (Head->ClientAddr) = HTONL (DhcpSb->ClientAddr);\r
CopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen);\r
\r
+ if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) {\r
+ Head->Seconds = 0;\r
+ } else if ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting)) {\r
+ //\r
+ // Use the same value as the original DHCPDISCOVER message.\r
+ //\r
+ Head->Seconds = DhcpSb->LastPacket->Dhcp4.Header.Seconds;\r
+ } else {\r
+ SetElapsedTime(&Head->Seconds, DhcpSb->ActiveChild);\r
+ }\r
+\r
//\r
// Append the DHCP message type\r
//\r
}\r
\r
if (EFI_ERROR (Status)) {\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
return Status;\r
}\r
\r
if (NewPacket != NULL) {\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
Packet = NewPacket;\r
}\r
\r
Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, Packet);\r
\r
if (Wrap == NULL) {\r
- gBS->FreePool (Packet);\r
+ FreePool (Packet);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
// Broadcast the message, unless we know the server address.\r
// Use the lease UdpIo port to send the unicast packet.\r
//\r
- EndPoint.RemoteAddr = 0xffffffff;\r
- EndPoint.LocalAddr = 0;\r
- EndPoint.RemotePort = DHCP_SERVER_PORT;\r
- EndPoint.LocalPort = DHCP_CLIENT_PORT;\r
- UdpIo = DhcpSb->UdpIo;\r
+ EndPoint.RemoteAddr.Addr[0] = 0xffffffff;\r
+ EndPoint.LocalAddr.Addr[0] = 0;\r
+ EndPoint.RemotePort = DHCP_SERVER_PORT;\r
+ EndPoint.LocalPort = DHCP_CLIENT_PORT;\r
+ UdpIo = DhcpSb->UdpIo;\r
\r
if ((DhcpSb->DhcpState == Dhcp4Renewing) || (Type == DHCP_MSG_RELEASE)) {\r
- EndPoint.RemoteAddr = DhcpSb->ServerAddr;\r
- EndPoint.LocalAddr = DhcpSb->ClientAddr;\r
- UdpIo = DhcpSb->LeaseIoPort;\r
+ EndPoint.RemoteAddr.Addr[0] = DhcpSb->ServerAddr;\r
+ EndPoint.LocalAddr.Addr[0] = DhcpSb->ClientAddr;\r
+ UdpIo = DhcpSb->LeaseIoPort;\r
}\r
\r
ASSERT (UdpIo != NULL);\r
UdpIo, \r
Wrap, \r
&EndPoint, \r
- 0, \r
+ NULL, \r
DhcpOnPacketSent, \r
DhcpSb\r
);\r
IN DHCP_SERVICE *DhcpSb\r
)\r
{\r
- UDP_IO_PORT *UdpIo;\r
- UDP_POINTS EndPoint;\r
+ UDP_IO *UdpIo;\r
+ UDP_END_POINT EndPoint;\r
NET_BUF *Wrap;\r
NET_FRAGMENT Frag;\r
EFI_STATUS Status;\r
\r
ASSERT (DhcpSb->LastPacket != NULL);\r
\r
- DhcpSb->LastPacket->Dhcp4.Header.Seconds = HTONS (*(UINT16 *)(&DhcpSb->LastTimeout));\r
+ //\r
+ // For REQUEST message in Dhcp4Requesting state, do not change the secs fields.\r
+ //\r
+ if (DhcpSb->DhcpState != Dhcp4Requesting) {\r
+ SetElapsedTime(&DhcpSb->LastPacket->Dhcp4.Header.Seconds, DhcpSb->ActiveChild);\r
+ }\r
\r
//\r
// Wrap it into a netbuf then send it.\r
//\r
// Broadcast the message, unless we know the server address.\r
//\r
- EndPoint.RemotePort = DHCP_SERVER_PORT;\r
- EndPoint.LocalPort = DHCP_CLIENT_PORT;\r
- EndPoint.RemoteAddr = 0xffffffff;\r
- EndPoint.LocalAddr = 0;\r
- UdpIo = DhcpSb->UdpIo;\r
+ EndPoint.RemotePort = DHCP_SERVER_PORT;\r
+ EndPoint.LocalPort = DHCP_CLIENT_PORT;\r
+ EndPoint.RemoteAddr.Addr[0] = 0xffffffff;\r
+ EndPoint.LocalAddr.Addr[0] = 0;\r
+ UdpIo = DhcpSb->UdpIo;\r
\r
if (DhcpSb->DhcpState == Dhcp4Renewing) {\r
- EndPoint.RemoteAddr = DhcpSb->ServerAddr;\r
- EndPoint.LocalAddr = DhcpSb->ClientAddr;\r
- UdpIo = DhcpSb->LeaseIoPort;\r
+ EndPoint.RemoteAddr.Addr[0] = DhcpSb->ServerAddr;\r
+ EndPoint.LocalAddr.Addr[0] = DhcpSb->ClientAddr;\r
+ UdpIo = DhcpSb->LeaseIoPort;\r
}\r
\r
ASSERT (UdpIo != NULL);\r
UdpIo,\r
Wrap,\r
&EndPoint,\r
- 0,\r
+ NULL,\r
DhcpOnPacketSent,\r
DhcpSb\r
);\r
\r
DhcpSb = (DHCP_SERVICE *) Context;\r
Instance = DhcpSb->ActiveChild;\r
+\r
+ //\r
+ // 0xffff is the maximum supported value for elapsed time according to RFC.\r
+ //\r
+ if (Instance != NULL && Instance->ElaspedTime < 0xffff) {\r
+ Instance->ElaspedTime++;\r
+ }\r
\r
//\r
// Check the retransmit timer\r
Status = DhcpChooseOffer (DhcpSb);\r
\r
if (EFI_ERROR(Status)) {\r
- FreePool (DhcpSb->LastOffer);\r
- DhcpSb->LastOffer = NULL;\r
+ if (DhcpSb->LastOffer != NULL) {\r
+ FreePool (DhcpSb->LastOffer);\r
+ DhcpSb->LastOffer = NULL;\r
+ }\r
} else {\r
goto ON_EXIT;\r
}\r
goto END_SESSION;\r
}\r
\r
+ if (Instance != NULL) {\r
+ Instance->ElaspedTime= 0;\r
+ } \r
+ \r
Status = DhcpSendMessage (\r
DhcpSb,\r
DhcpSb->Selected,\r
goto END_SESSION;\r
}\r
\r
+ if (Instance != NULL) {\r
+ Instance->ElaspedTime= 0;\r
+ } \r
+\r
Status = DhcpSendMessage (\r
DhcpSb,\r
DhcpSb->Selected,\r