11UINT32 mDhcp4DefaultTimeout[4] = { 4, 8, 16, 32 };
35 DhcpSb->ActiveChild->ElaspedTime = 0;
41 if (EFI_ERROR (Status)) {
49 if (EFI_ERROR (Status)) {
85 if (NewPacket !=
NULL) {
96 Config = &DhcpSb->ActiveConfig;
100 return EFI_NOT_READY;
107 &DhcpSb->ActiveChild->Dhcp4Protocol,
120 if ((Status ==
EFI_SUCCESS) || (Status == EFI_NOT_READY)) {
142 if ((
Child = DhcpSb->ActiveChild) ==
NULL) {
147 ((Which == DHCP_NOTIFY_COMPLETION) || (Which == DHCP_NOTIFY_ALL))
150 gBS->SignalEvent (
Child->CompletionEvent);
155 ((Which == DHCP_NOTIFY_RENEWREBIND) || (Which == DHCP_NOTIFY_ALL))
158 gBS->SignalEvent (
Child->RenewRebindEvent);
198 if (EFI_ERROR (Status)) {
209 DhcpSb->MaxRetries = DhcpSb->ActiveConfig.DiscoverTryCount;
211 DhcpSb->MaxRetries = DhcpSb->ActiveConfig.RequestTryCount;
214 if (DhcpSb->MaxRetries == 0) {
215 DhcpSb->MaxRetries = 4;
218 DhcpSb->CurRetry = 0;
219 DhcpSb->PacketToLive = 0;
220 DhcpSb->LastTimeout = 0;
221 DhcpSb->DhcpState = State;
239 ASSERT (DhcpSb->MaxRetries > DhcpSb->CurRetry);
242 Times = DhcpSb->ActiveConfig.DiscoverTimeout;
244 Times = DhcpSb->ActiveConfig.RequestTimeout;
248 Times = mDhcp4DefaultTimeout;
251 DhcpSb->PacketToLive = Times[DhcpSb->CurRetry];
252 DhcpSb->LastTimeout = DhcpSb->PacketToLive;
272 ASSERT (Para !=
NULL);
274 DhcpSb->Lease = Para->Lease;
275 DhcpSb->T2 = Para->T2;
276 DhcpSb->T1 = Para->T1;
278 if (DhcpSb->Lease == 0) {
279 DhcpSb->Lease = DHCP_DEFAULT_LEASE;
282 if ((DhcpSb->T2 == 0) || (DhcpSb->T2 >= Para->Lease)) {
283 DhcpSb->T2 = Para->Lease - (Para->Lease >> 3);
286 if ((DhcpSb->T1 == 0) || (DhcpSb->T1 >= Para->T2)) {
287 DhcpSb->T1 = DhcpSb->Lease >> 1;
319 UdpConfigData.AcceptBroadcast =
FALSE;
320 UdpConfigData.AcceptPromiscuous =
FALSE;
321 UdpConfigData.AcceptAnyPort =
FALSE;
322 UdpConfigData.AllowDuplicatePort =
TRUE;
323 UdpConfigData.TypeOfService = 0;
324 UdpConfigData.TimeToLive = 64;
325 UdpConfigData.DoNotFragment =
FALSE;
326 UdpConfigData.ReceiveTimeout = 1;
327 UdpConfigData.TransmitTimeout = 0;
329 UdpConfigData.UseDefaultAddress =
FALSE;
330 UdpConfigData.StationPort = DHCP_CLIENT_PORT;
331 UdpConfigData.RemotePort = DHCP_SERVER_PORT;
333 Ip = HTONL (DhcpSb->ClientAddr);
336 Ip = HTONL (DhcpSb->Netmask);
341 Status = UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData);
343 if (EFI_ERROR (Status)) {
350 if ((DhcpSb->Para !=
NULL) && (DhcpSb->Para->Router != 0)) {
353 Ip = HTONL (DhcpSb->Para->Router);
356 UdpIo->Protocol.Udp4->Routes (UdpIo->Protocol.Udp4,
FALSE, &Subnet, &Subnet, &Gateway);
378 DhcpSb->ClientAddr = EFI_NTOHL (DhcpSb->Selected->Dhcp4.Header.YourAddr);
380 if (DhcpSb->Para !=
NULL) {
381 DhcpSb->Netmask = DhcpSb->Para->NetMask;
382 DhcpSb->ServerAddr = DhcpSb->Para->ServerId;
385 if (DhcpSb->Netmask == 0) {
389 if (DhcpSb->LeaseIoPort !=
NULL) {
406 if (DhcpSb->LeaseIoPort ==
NULL) {
407 return EFI_OUT_OF_RESOURCES;
410 if (!DHCP_IS_BOOTP (DhcpSb->Para)) {
429 DhcpSb->Xid = DhcpSb->Xid + 1;
430 DhcpSb->ClientAddr = 0;
432 DhcpSb->ServerAddr = 0;
434 if (DhcpSb->LastOffer !=
NULL) {
436 DhcpSb->LastOffer =
NULL;
439 if (DhcpSb->Selected !=
NULL) {
441 DhcpSb->Selected =
NULL;
444 if (DhcpSb->Para !=
NULL) {
452 DhcpSb->ExtraRefresh =
FALSE;
454 if (DhcpSb->LeaseIoPort !=
NULL) {
456 DhcpSb->LeaseIoPort =
NULL;
459 if (DhcpSb->LastPacket !=
NULL) {
461 DhcpSb->LastPacket =
NULL;
464 DhcpSb->PacketToLive = 0;
465 DhcpSb->LastTimeout = 0;
466 DhcpSb->CurRetry = 0;
467 DhcpSb->MaxRetries = 0;
468 DhcpSb->LeaseLife = 0;
496 ASSERT (DhcpSb->LastOffer !=
NULL);
506 if (EFI_ERROR (Status)) {
510 Selected = DhcpSb->LastOffer;
514 if (TempPacket !=
NULL) {
517 Selected = TempPacket;
521 DhcpSb->Selected = Selected;
522 DhcpSb->LastOffer =
NULL;
530 if (DHCP_IS_BOOTP (DhcpSb->Para)) {
533 if (EFI_ERROR (Status)) {
547 if (EFI_ERROR (Status)) {
570 if (DHCP_CONNECTED (DhcpSb->DhcpState)) {
578 DhcpSb->IoStatus = Status;
611 if (!DHCP_IS_BOOTP (Para) &&
612 ((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))
627 if (DhcpSb->LastOffer !=
NULL) {
631 DhcpSb->LastOffer = Packet;
634 }
else if (Status == EFI_NOT_READY) {
635 if (DhcpSb->LastOffer !=
NULL) {
639 DhcpSb->LastOffer = Packet;
640 }
else if (Status == EFI_ABORTED) {
679 ASSERT (!DHCP_IS_BOOTP (DhcpSb->Para));
681 Head = &Packet->Dhcp4.Header;
682 Selected = &DhcpSb->Selected->Dhcp4.Header;
687 if (DHCP_IS_BOOTP (Para) ||
688 (Para->ServerId != DhcpSb->Para->ServerId) ||
689 ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))
699 Status = EFI_DEVICE_ERROR;
701 if (Para->DhcpType == DHCP_MSG_NAK) {
712 Message = (UINT8 *)
"Lease confirmed isn't the same as that in the offer";
718 if (EFI_ERROR (Status)) {
719 Message = (UINT8 *)
"Lease is denied upon received ACK";
728 if (EFI_ERROR (Status)) {
729 Message = (UINT8 *)
"Lease is denied upon entering bound";
740 DhcpSendMessage (DhcpSb, DhcpSb->Selected, DhcpSb->Para, DHCP_MSG_DECLINE, Message);
770 ASSERT (!DHCP_IS_BOOTP (DhcpSb->Para));
772 Head = &Packet->Dhcp4.Header;
773 Selected = &DhcpSb->Selected->Dhcp4.Header;
778 if (DHCP_IS_BOOTP (Para) ||
779 (Para->ServerId != DhcpSb->Para->ServerId) ||
780 ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))
790 Status = EFI_DEVICE_ERROR;
792 if (Para->DhcpType == DHCP_MSG_NAK) {
807 if (EFI_ERROR (Status)) {
815 DhcpSb->LeaseLife = 0;
818 if (DhcpSb->ExtraRefresh != 0) {
819 DhcpSb->ExtraRefresh =
FALSE;
852 Head = &Packet->Dhcp4.Header;
857 if (DHCP_IS_BOOTP (Para) ||
858 ((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))
868 if (Para->DhcpType == DHCP_MSG_NAK) {
871 DhcpSb->ClientAddr = 0;
881 if (EFI_NTOHL (Head->
YourAddr) != DhcpSb->ClientAddr) {
882 Status = EFI_DEVICE_ERROR;
887 if (EFI_ERROR (Status)) {
895 if (DhcpSb->Para ==
NULL) {
896 Status = EFI_OUT_OF_RESOURCES;
900 DhcpSb->Selected = Packet;
902 if (EFI_ERROR (Status)) {
947 if (EFI_ERROR (IoStatus)) {
949 }
else if (DhcpSb->ServiceState == DHCP_DESTROY) {
954 ASSERT (UdpPacket !=
NULL);
973 if (Packet ==
NULL) {
978 Head = &Packet->Dhcp4.
Header;
979 Packet->
Length =
NetbufCopy (UdpPacket, 0, UdpPacket->TotalSize, (UINT8 *)Head);
981 if (Packet->
Length != UdpPacket->TotalSize) {
988 if ((Head->OpCode != BOOTP_REPLY) ||
989 (NTOHL (Head->Xid) != DhcpSb->Xid) ||
1017 switch (DhcpSb->DhcpState) {
1052 if (EFI_ERROR (Status)) {
1062 if (Packet !=
NULL) {
1068 if (EFI_ERROR (Status)) {
1149 if (Packet ==
NULL) {
1150 return EFI_OUT_OF_RESOURCES;
1159 Config = &DhcpSb->ActiveConfig;
1163 SeedHead = &Seed->Dhcp4.Header;
1166 Head = &Packet->Dhcp4.
Header;
1169 Head->OpCode = BOOTP_REQUEST;
1170 Head->HwType = DhcpSb->HwType;
1171 Head->HwAddrLen = DhcpSb->HwLen;
1172 Head->Xid = HTONL (DhcpSb->Xid);
1173 Head->Reserved = HTONS (0x8000);
1175 EFI_IP4 (Head->
ClientAddr) = HTONL (DhcpSb->ClientAddr);
1178 if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) {
1180 }
else if ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState ==
Dhcp4Requesting)) {
1184 Head->Seconds = DhcpSb->LastPacket->Dhcp4.Header.Seconds;
1193 Buf = Packet->Dhcp4.
Option;
1202 if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE) ||
1203 ((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState ==
Dhcp4Requesting))
1206 ASSERT ((Para !=
NULL) && (Para->ServerId != 0));
1208 IpAddr = HTONL (Para->ServerId);
1220 if (Type == DHCP_MSG_REQUEST) {
1224 ASSERT (SeedHead !=
NULL);
1225 IpAddr = EFI_IP4 (SeedHead->
YourAddr);
1227 }
else if (Type == DHCP_MSG_DECLINE) {
1228 ASSERT (SeedHead !=
NULL);
1229 IpAddr = EFI_IP4 (SeedHead->
YourAddr);
1241 if ((Type != DHCP_MSG_DECLINE) && (Type != DHCP_MSG_RELEASE)) {
1242 MaxMsg = HTONS (0xFF00);
1257 if (DhcpSb->UserOptionLen != 0) {
1258 for (Index = 0; Index < Config->
OptionCount; Index++) {
1263 if (((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) &&
1278 *(Buf++) = DHCP4_TAG_EOP;
1279 Packet->
Length += (UINT32)(Buf - Packet->Dhcp4.
Option);
1287 if (Type == DHCP_MSG_DISCOVER) {
1289 }
else if (Type == DHCP_MSG_REQUEST) {
1291 }
else if (Type == DHCP_MSG_DECLINE) {
1295 if (EFI_ERROR (Status)) {
1300 if (NewPacket !=
NULL) {
1309 &DhcpSb->ClientAddressSendOut[0],
1311 Packet->Dhcp4.
Header.HwAddrLen
1317 Frag.Bulk = (UINT8 *)&Packet->Dhcp4.
Header;
1318 Frag.Len = Packet->
Length;
1323 return EFI_OUT_OF_RESOURCES;
1329 if (DhcpSb->LastPacket !=
NULL) {
1333 DhcpSb->LastPacket = Packet;
1340 EndPoint.RemoteAddr.Addr[0] = 0xffffffff;
1341 EndPoint.LocalAddr.Addr[0] = 0;
1342 EndPoint.RemotePort = DHCP_SERVER_PORT;
1343 EndPoint.LocalPort = DHCP_CLIENT_PORT;
1344 UdpIo = DhcpSb->UdpIo;
1346 if ((DhcpSb->DhcpState ==
Dhcp4Renewing) || (Type == DHCP_MSG_RELEASE)) {
1347 EndPoint.RemoteAddr.Addr[0] = DhcpSb->ServerAddr;
1348 EndPoint.LocalAddr.Addr[0] = DhcpSb->ClientAddr;
1349 UdpIo = DhcpSb->LeaseIoPort;
1352 ASSERT (UdpIo !=
NULL);
1363 if (EFI_ERROR (Status)) {
1365 return EFI_ACCESS_DENIED;
1392 ASSERT (DhcpSb->LastPacket !=
NULL);
1398 SetElapsedTime (&DhcpSb->LastPacket->Dhcp4.Header.Seconds, DhcpSb->ActiveChild);
1404 Frag.Bulk = (UINT8 *)&DhcpSb->LastPacket->Dhcp4.Header;
1405 Frag.Len = DhcpSb->LastPacket->Length;
1409 return EFI_OUT_OF_RESOURCES;
1415 EndPoint.RemotePort = DHCP_SERVER_PORT;
1416 EndPoint.LocalPort = DHCP_CLIENT_PORT;
1417 EndPoint.RemoteAddr.Addr[0] = 0xffffffff;
1418 EndPoint.LocalAddr.Addr[0] = 0;
1419 UdpIo = DhcpSb->UdpIo;
1422 EndPoint.RemoteAddr.Addr[0] = DhcpSb->ServerAddr;
1423 EndPoint.LocalAddr.Addr[0] = DhcpSb->ClientAddr;
1424 UdpIo = DhcpSb->LeaseIoPort;
1427 ASSERT (UdpIo !=
NULL);
1438 if (EFI_ERROR (Status)) {
1440 return EFI_ACCESS_DENIED;
1471 Instance = DhcpSb->ActiveChild;
1476 if ((Instance !=
NULL) && (Instance->ElaspedTime < 0xffff)) {
1477 Instance->ElaspedTime++;
1483 if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) {
1490 if (EFI_ERROR (Status)) {
1491 if (DhcpSb->LastOffer !=
NULL) {
1493 DhcpSb->LastOffer =
NULL;
1500 if (++DhcpSb->CurRetry < DhcpSb->MaxRetries) {
1506 }
else if (DHCP_CONNECTED (DhcpSb->DhcpState)) {
1512 if (DhcpSb->ExtraRefresh != 0) {
1515 if (DhcpSb->LeaseLife < DhcpSb->T1) {
1517 }
else if (DhcpSb->LeaseLife < DhcpSb->T2) {
1519 }
else if (DhcpSb->LeaseLife < DhcpSb->Lease) {
1525 DhcpSb->IoStatus = EFI_TIMEOUT;
1537 if (DHCP_CONNECTED (DhcpSb->DhcpState)) {
1538 DhcpSb->LeaseLife++;
1544 if (DhcpSb->ExtraRefresh != 0) {
1548 if (DhcpSb->LeaseLife == DhcpSb->Lease) {
1553 }
else if (DhcpSb->LeaseLife == DhcpSb->T2) {
1561 if (Instance !=
NULL) {
1562 Instance->ElaspedTime = 0;
1573 if (EFI_ERROR (Status)) {
1576 }
else if (DhcpSb->LeaseLife == DhcpSb->T1) {
1584 if (Instance !=
NULL) {
1585 Instance->ElaspedTime = 0;
1596 if (EFI_ERROR (Status)) {
1606 NET_LIST_FOR_EACH_SAFE (Entry, Next, &DhcpSb->Children) {
1607 Instance = NET_LIST_USER_STRUCT (Entry,
DHCP_PROTOCOL, Link);
1608 Instance->Timeout--;
1609 if ((Instance->Timeout == 0) && (Instance->Token !=
NULL)) {
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
NODE Child(IN NODE LoopVar6, IN UINT8 LoopVar5)
VOID EFIAPI DhcpDummyExtFree(IN VOID *Arg)
VOID DhcpCleanConfigure(IN OUT EFI_DHCP4_CONFIG_DATA *Config)
VOID PxeDhcpDone(IN DHCP_PROTOCOL *Instance)
VOID SetElapsedTime(IN UINT16 *Elapsed, IN DHCP_PROTOCOL *Instance)
EFI_STATUS DhcpLeaseAcquired(IN OUT DHCP_SERVICE *DhcpSb)
EFI_STATUS DhcpHandleReboot(IN DHCP_SERVICE *DhcpSb, IN EFI_DHCP4_PACKET *Packet, IN DHCP_PARAMETER *Para)
EFI_STATUS DhcpInitRequest(IN DHCP_SERVICE *DhcpSb)
EFI_STATUS DhcpHandleRequest(IN DHCP_SERVICE *DhcpSb, IN EFI_DHCP4_PACKET *Packet, IN DHCP_PARAMETER *Para)
EFI_STATUS DhcpHandleSelect(IN DHCP_SERVICE *DhcpSb, IN EFI_DHCP4_PACKET *Packet, IN DHCP_PARAMETER *Para)
EFI_STATUS DhcpHandleRenewRebind(IN DHCP_SERVICE *DhcpSb, IN EFI_DHCP4_PACKET *Packet, IN DHCP_PARAMETER *Para)
VOID DhcpComputeLease(IN OUT DHCP_SERVICE *DhcpSb, IN DHCP_PARAMETER *Para)
EFI_STATUS DhcpSendMessage(IN DHCP_SERVICE *DhcpSb, IN EFI_DHCP4_PACKET *Seed, IN DHCP_PARAMETER *Para, IN UINT8 Type, IN UINT8 *Msg)
EFI_STATUS EFIAPI DhcpConfigLeaseIoPort(IN UDP_IO *UdpIo, IN VOID *Context)
EFI_STATUS DhcpSetState(IN OUT DHCP_SERVICE *DhcpSb, IN INTN State, IN BOOLEAN CallUser)
VOID DhcpEndSession(IN DHCP_SERVICE *DhcpSb, IN EFI_STATUS Status)
VOID DhcpCleanLease(IN DHCP_SERVICE *DhcpSb)
EFI_STATUS DhcpCallUser(IN DHCP_SERVICE *DhcpSb, IN EFI_DHCP4_EVENT Event, IN EFI_DHCP4_PACKET *Packet OPTIONAL, OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL)
EFI_STATUS DhcpChooseOffer(IN DHCP_SERVICE *DhcpSb)
VOID DhcpSetTransmitTimer(IN OUT DHCP_SERVICE *DhcpSb)
EFI_STATUS DhcpRetransmit(IN DHCP_SERVICE *DhcpSb)
VOID EFIAPI DhcpOnPacketSent(NET_BUF *Packet, UDP_END_POINT *EndPoint, EFI_STATUS IoStatus, VOID *Context)
VOID EFIAPI DhcpOnTimerTick(IN EFI_EVENT Event, IN VOID *Context)
VOID EFIAPI DhcpInput(NET_BUF *UdpPacket, UDP_END_POINT *EndPoint, EFI_STATUS IoStatus, VOID *Context)
VOID DhcpNotifyUser(IN DHCP_SERVICE *DhcpSb, IN INTN Which)
EFI_STATUS DhcpValidateOptions(IN EFI_DHCP4_PACKET *Packet, OUT DHCP_PARAMETER **Para OPTIONAL)
UINT8 * DhcpAppendOption(OUT UINT8 *Buf, IN UINT8 Tag, IN UINT16 DataLen, IN UINT8 *Data)
#define DHCP_OPTION_MAGIC
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
VOID EFIAPI NetbufFree(IN NET_BUF *Nbuf)
UINT32 EFIAPI NetbufCopy(IN NET_BUF *Nbuf, IN UINT32 Offset, IN UINT32 Len, IN UINT8 *Dest)
NET_BUF *EFIAPI NetbufFromExt(IN NET_FRAGMENT *ExtFragment, IN UINT32 ExtNum, IN UINT32 HeadSpace, IN UINT32 HeadLen, IN NET_VECTOR_EXT_FREE ExtFree, IN VOID *Arg OPTIONAL)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI UdpIoRecvDatagram(IN UDP_IO *UdpIo, IN UDP_IO_CALLBACK CallBack, IN VOID *Context, IN UINT32 HeadLen)
EFI_STATUS EFIAPI UdpIoSendDatagram(IN UDP_IO *UdpIo, IN NET_BUF *Packet, IN UDP_END_POINT *EndPoint OPTIONAL, IN EFI_IP_ADDRESS *Gateway OPTIONAL, IN UDP_IO_CALLBACK CallBack, IN VOID *Context)
EFI_STATUS EFIAPI UdpIoFreeIo(IN UDP_IO *UdpIo)
UDP_IO *EFIAPI UdpIoCreateIo(IN EFI_HANDLE Controller, IN EFI_HANDLE ImageHandle, IN UDP_IO_CONFIG Configure, IN UINT8 UdpVersion, IN VOID *Context)
EFI_DHCP4_PACKET_OPTION ** OptionList
EFI_IPv4_ADDRESS ClientAddress
EFI_DHCP4_CALLBACK Dhcp4Callback
EFI_IPv4_ADDRESS ClientAddr
Client IP address from client.
UINT8 ClientHwAddr[16]
Client hardware address.
EFI_IPv4_ADDRESS YourAddr
Client IP address from server.