/** @file\r
EFI DHCP protocol implementation.\r
\r
-Copyright (c) 2006 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2006 - 2009, Intel Corporation.<BR>\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
\r
DhcpSb->CurRetry = 0;\r
DhcpSb->PacketToLive = 0;\r
-\r
+ DhcpSb->LastTimeout = 0;\r
DhcpSb->DhcpState = State;\r
return EFI_SUCCESS;\r
}\r
}\r
\r
DhcpSb->PacketToLive = Times[DhcpSb->CurRetry];\r
+ DhcpSb->LastTimeout = DhcpSb->PacketToLive;\r
\r
return;\r
}\r
}\r
\r
if (DhcpSb->LastPacket != NULL) {\r
- NetbufFree (DhcpSb->LastPacket);\r
+ FreePool (DhcpSb->LastPacket);\r
DhcpSb->LastPacket = NULL;\r
}\r
\r
DhcpSb->PacketToLive = 0;\r
+ DhcpSb->LastTimeout = 0;\r
DhcpSb->CurRetry = 0;\r
DhcpSb->MaxRetries = 0;\r
DhcpSb->LeaseLife = 0;\r
// Save it as the last sent packet for retransmission\r
//\r
if (DhcpSb->LastPacket != NULL) {\r
- NetbufFree (DhcpSb->LastPacket);\r
+ FreePool (DhcpSb->LastPacket);\r
}\r
\r
- NET_GET_REF (Wrap);\r
- DhcpSb->LastPacket = Wrap;\r
+ DhcpSb->LastPacket = Packet;\r
DhcpSetTransmitTimer (DhcpSb);\r
\r
//\r
}\r
\r
ASSERT (UdpIo != NULL);\r
- Status = UdpIoSendDatagram (UdpIo, Wrap, &EndPoint, 0, DhcpOnPacketSent, DhcpSb);\r
+ NET_GET_REF (Wrap);\r
+ \r
+ Status = UdpIoSendDatagram (\r
+ UdpIo, \r
+ Wrap, \r
+ &EndPoint, \r
+ 0, \r
+ DhcpOnPacketSent, \r
+ DhcpSb\r
+ );\r
\r
if (EFI_ERROR (Status)) {\r
- NetbufFree (Wrap);\r
+ NET_PUT_REF (Wrap);\r
return EFI_ACCESS_DENIED;\r
}\r
\r
{\r
UDP_IO_PORT *UdpIo;\r
UDP_POINTS 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
+ //\r
+ // Wrap it into a netbuf then send it.\r
+ //\r
+ Frag.Bulk = (UINT8 *) &DhcpSb->LastPacket->Dhcp4.Header;\r
+ Frag.Len = DhcpSb->LastPacket->Length;\r
+ Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, DhcpSb->LastPacket);\r
+\r
+ if (Wrap == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ \r
//\r
// Broadcast the message, unless we know the server address.\r
//\r
\r
ASSERT (UdpIo != NULL);\r
\r
- NET_GET_REF (DhcpSb->LastPacket);\r
+ NET_GET_REF (Wrap);\r
Status = UdpIoSendDatagram (\r
UdpIo,\r
- DhcpSb->LastPacket,\r
+ Wrap,\r
&EndPoint,\r
0,\r
DhcpOnPacketSent,\r
);\r
\r
if (EFI_ERROR (Status)) {\r
- NET_PUT_REF (DhcpSb->LastPacket);\r
+ NET_PUT_REF (Wrap);\r
return EFI_ACCESS_DENIED;\r
}\r
\r
UINT8 VendorOptLen;\r
CHAR8 *SystemSerialNumber;\r
EFI_DHCP4_HEADER *DhcpHeader;\r
+ UINT32 Xid;\r
\r
\r
Mode = Private->PxeBc.Mode;\r
\r
DhcpHeader->HwAddrLen = sizeof (EFI_GUID);\r
}\r
-\r
- Token.Packet->Dhcp4.Header.Xid = NET_RANDOM (NetRandomInitSeed ());\r
- Token.Packet->Dhcp4.Header.Reserved = (UINT16) ((IsBCast) ? 0xf000 : 0x0);\r
+ \r
+ Xid = NET_RANDOM (NetRandomInitSeed ());\r
+ Token.Packet->Dhcp4.Header.Xid = HTONL(Xid);\r
+ Token.Packet->Dhcp4.Header.Reserved = HTONS((IsBCast) ? 0x8000 : 0);\r
CopyMem (&Token.Packet->Dhcp4.Header.ClientAddr, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
\r
Token.RemotePort = Sport;\r
\r
- if (DestIp == NULL) {\r
+ if (IsBCast) {\r
SetMem (&Token.RemoteAddress, sizeof (EFI_IPv4_ADDRESS), 0xff);\r
} else {\r
CopyMem (&Token.RemoteAddress, DestIp, sizeof (EFI_IPv4_ADDRESS));\r
//\r
for (TryIndex = 1; TryIndex <= PXEBC_BOOT_REQUEST_RETRIES; TryIndex++) {\r
\r
- Token.TimeoutValue = PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex;\r
+ Token.TimeoutValue = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * TryIndex);\r
+ Token.Packet->Dhcp4.Header.Seconds = (UINT16) (PXEBC_BOOT_REQUEST_TIMEOUT * (TryIndex - 1));\r
\r
Status = Dhcp4->TransmitReceive (Dhcp4, &Token);\r
\r
/** @file\r
Interface routines for PxeBc.\r
\r
-Copyright (c) 2007 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2007 - 2009, Intel Corporation.<BR>\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
\r
#include "PxeBcImpl.h"\r
\r
-EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate = { EfiPxeLoadFile };\r
+UINT32 mPxeDhcpTimeout[4] = { 4, 8, 16, 32 };\r
\r
/**\r
Get and record the arp cache.\r
\r
Private->CurrentUdpSrcPort = 0;\r
Private->Udp4Write->Configure (Private->Udp4Write, NULL);\r
+ Private->Udp4Read->Groups (Private->Udp4Read, FALSE, NULL);\r
Private->Udp4Read->Configure (Private->Udp4Read, NULL);\r
\r
Private->Dhcp4->Stop (Private->Dhcp4);\r
EFI_DHCP4_MODE_DATA Dhcp4Mode;\r
EFI_DHCP4_PACKET_OPTION *OptList[PXEBC_DHCP4_MAX_OPTION_NUM];\r
UINT32 OptCount;\r
- UINT32 DiscoverTimeout;\r
- UINTN Index;\r
EFI_STATUS Status;\r
EFI_ARP_CONFIG_DATA ArpConfigData;\r
\r
\r
//\r
// Set the DHCP4 config data.\r
+ // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.\r
//\r
ZeroMem (&Dhcp4CfgData, sizeof (EFI_DHCP4_CONFIG_DATA));\r
Dhcp4CfgData.OptionCount = OptCount;\r
Dhcp4CfgData.OptionList = OptList;\r
Dhcp4CfgData.Dhcp4Callback = PxeBcDhcpCallBack;\r
Dhcp4CfgData.CallbackContext = Private;\r
- Dhcp4CfgData.DiscoverTryCount = 1;\r
- Dhcp4CfgData.DiscoverTimeout = &DiscoverTimeout;\r
-\r
- for (Index = 0; Index < PXEBC_DHCP4_DISCOVER_RETRIES; Index++) {\r
- //\r
- // The four discovery timeouts are 4, 8, 16, 32 seconds respectively.\r
- //\r
- DiscoverTimeout = (PXEBC_DHCP4_DISCOVER_INIT_TIMEOUT << Index);\r
+ Dhcp4CfgData.DiscoverTryCount = 4;\r
+ Dhcp4CfgData.DiscoverTimeout = mPxeDhcpTimeout;\r
\r
- Status = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r
- if (EFI_ERROR (Status)) {\r
- break;\r
- }\r
- //\r
- // Zero those arrays to record the varies numbers of DHCP OFFERS.\r
- //\r
- Private->GotProxyOffer = FALSE;\r
- Private->NumOffers = 0;\r
- Private->BootpIndex = 0;\r
- ZeroMem (Private->ServerCount, sizeof (Private->ServerCount));\r
- ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));\r
+ Status = Dhcp4->Configure (Dhcp4, &Dhcp4CfgData);\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_EXIT;\r
+ }\r
+ \r
+ //\r
+ // Zero those arrays to record the varies numbers of DHCP OFFERS.\r
+ //\r
+ Private->GotProxyOffer = FALSE;\r
+ Private->NumOffers = 0;\r
+ Private->BootpIndex = 0;\r
+ ZeroMem (Private->ServerCount, sizeof (Private->ServerCount));\r
+ ZeroMem (Private->ProxyIndex, sizeof (Private->ProxyIndex));\r
\r
- Status = Dhcp4->Start (Dhcp4, NULL);\r
- if (EFI_ERROR (Status)) {\r
- if (Status == EFI_TIMEOUT) {\r
- //\r
- // If no response is received or all received offers don't match\r
- // the PXE boot requirements, EFI_TIMEOUT will be returned.\r
- //\r
- continue;\r
- }\r
- if (Status == EFI_ICMP_ERROR) {\r
- Mode->IcmpErrorReceived = TRUE;\r
- }\r
- //\r
- // Other error status means the DHCP really fails.\r
- //\r
- break;\r
+ Status = Dhcp4->Start (Dhcp4, NULL);\r
+ if (EFI_ERROR (Status)) {\r
+ if (Status == EFI_ICMP_ERROR) {\r
+ Mode->IcmpErrorReceived = TRUE;\r
}\r
+ goto ON_EXIT;\r
+ }\r
\r
- Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);\r
- if (EFI_ERROR (Status)) {\r
- break;\r
- }\r
+ Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4Mode);\r
+ if (EFI_ERROR (Status)) {\r
+ goto ON_EXIT;\r
+ }\r
\r
- ASSERT (Dhcp4Mode.State == Dhcp4Bound);\r
+ ASSERT (Dhcp4Mode.State == Dhcp4Bound);\r
\r
- CopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r
+ CopyMem (&Private->StationIp, &Dhcp4Mode.ClientAddress, sizeof (EFI_IPv4_ADDRESS));\r
+ CopyMem (&Private->SubnetMask, &Dhcp4Mode.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
+ CopyMem (&Private->GatewayIp, &Dhcp4Mode.RouterAddress, sizeof (EFI_IPv4_ADDRESS));\r
\r
- CopyMem (&Mode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
- CopyMem (&Mode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
+ CopyMem (&Mode->StationIp, &Private->StationIp, sizeof (EFI_IPv4_ADDRESS));\r
+ CopyMem (&Mode->SubnetMask, &Private->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
\r
- //\r
- // Check the selected offer to see whether BINL is required, if no or BINL is\r
- // finished, set the various Mode members.\r
- //\r
- Status = PxeBcCheckSelectedOffer (Private);\r
- if (!EFI_ERROR (Status)) {\r
- break;\r
- }\r
+ //\r
+ // Check the selected offer to see whether BINL is required, if no or BINL is\r
+ // finished, set the various Mode members.\r
+ //\r
+ Status = PxeBcCheckSelectedOffer (Private);\r
+ if (!EFI_ERROR (Status)) {\r
+ goto ON_EXIT;\r
}\r
\r
+ON_EXIT:\r
if (EFI_ERROR (Status)) {\r
Dhcp4->Stop (Dhcp4);\r
Dhcp4->Configure (Dhcp4, NULL);\r
return Status;\r
}\r
\r
+EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate = { EfiPxeLoadFile };\r
+\r