\r
**/\r
\r
-\r
#include "Dhcp4Impl.h"\r
\r
UINT32 mDhcp4DefaultTimeout[4] = { 4, 8, 16, 32 };\r
\r
-\r
/**\r
Send an initial DISCOVER or REQUEST message according to the\r
DHCP service's current state.\r
**/\r
EFI_STATUS\r
DhcpInitRequest (\r
- IN DHCP_SERVICE *DhcpSb\r
+ IN DHCP_SERVICE *DhcpSb\r
)\r
{\r
- EFI_STATUS Status;\r
+ EFI_STATUS Status;\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
+ DhcpSb->ActiveChild->ElaspedTime = 0;\r
\r
if (DhcpSb->DhcpState == Dhcp4Init) {\r
DhcpSetState (DhcpSb, Dhcp4Selecting, FALSE);\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
Call user provided callback function, and return the value the\r
function returns. If the user doesn't provide a callback, a\r
**/\r
EFI_STATUS\r
DhcpCallUser (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN EFI_DHCP4_EVENT Event,\r
- IN EFI_DHCP4_PACKET *Packet OPTIONAL,\r
- OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL\r
+ IN DHCP_SERVICE *DhcpSb,\r
+ IN EFI_DHCP4_EVENT Event,\r
+ IN EFI_DHCP4_PACKET *Packet OPTIONAL,\r
+ OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL\r
)\r
{\r
- EFI_DHCP4_CONFIG_DATA *Config;\r
- EFI_STATUS Status;\r
+ EFI_DHCP4_CONFIG_DATA *Config;\r
+ EFI_STATUS Status;\r
\r
if (NewPacket != NULL) {\r
*NewPacket = NULL;\r
Status = Config->Dhcp4Callback (\r
&DhcpSb->ActiveChild->Dhcp4Protocol,\r
Config->CallbackContext,\r
- (EFI_DHCP4_STATE) DhcpSb->DhcpState,\r
+ (EFI_DHCP4_STATE)DhcpSb->DhcpState,\r
Event,\r
Packet,\r
NewPacket\r
return EFI_ABORTED;\r
}\r
\r
-\r
/**\r
Notify the user about the operation result.\r
\r
**/\r
VOID\r
DhcpNotifyUser (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN INTN Which\r
+ IN DHCP_SERVICE *DhcpSb,\r
+ IN INTN Which\r
)\r
{\r
- DHCP_PROTOCOL *Child;\r
+ DHCP_PROTOCOL *Child;\r
\r
if ((Child = DhcpSb->ActiveChild) == NULL) {\r
- return ;\r
+ return;\r
}\r
\r
if ((Child->CompletionEvent != NULL) &&\r
((Which == DHCP_NOTIFY_COMPLETION) || (Which == DHCP_NOTIFY_ALL))\r
- ) {\r
-\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
- ) {\r
-\r
+ )\r
+ {\r
gBS->SignalEvent (Child->RenewRebindEvent);\r
Child->RenewRebindEvent = NULL;\r
}\r
}\r
\r
-\r
-\r
/**\r
Set the DHCP state. If CallUser is true, it will try to notify\r
the user before change the state by DhcpNotifyUser. It returns\r
**/\r
EFI_STATUS\r
DhcpSetState (\r
- IN OUT 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
+ EFI_STATUS Status;\r
\r
if (CallUser) {\r
Status = EFI_SUCCESS;\r
\r
if (State == Dhcp4Renewing) {\r
Status = DhcpCallUser (DhcpSb, Dhcp4EnterRenewing, NULL, NULL);\r
-\r
} else if (State == Dhcp4Rebinding) {\r
Status = DhcpCallUser (DhcpSb, Dhcp4EnterRebinding, NULL, NULL);\r
-\r
} else if (State == Dhcp4Bound) {\r
Status = DhcpCallUser (DhcpSb, Dhcp4BoundCompleted, NULL, NULL);\r
-\r
}\r
\r
if (EFI_ERROR (Status)) {\r
DhcpSb->MaxRetries = 4;\r
}\r
\r
- DhcpSb->CurRetry = 0;\r
- DhcpSb->PacketToLive = 0;\r
- DhcpSb->LastTimeout = 0;\r
- DhcpSb->DhcpState = State;\r
+ DhcpSb->CurRetry = 0;\r
+ DhcpSb->PacketToLive = 0;\r
+ DhcpSb->LastTimeout = 0;\r
+ DhcpSb->DhcpState = State;\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
Set the retransmit timer for the packet. It will select from either\r
the discover timeouts/request timeouts or the default timeout values.\r
**/\r
VOID\r
DhcpSetTransmitTimer (\r
- IN OUT DHCP_SERVICE *DhcpSb\r
+ IN OUT DHCP_SERVICE *DhcpSb\r
)\r
{\r
- UINT32 *Times;\r
+ UINT32 *Times;\r
\r
ASSERT (DhcpSb->MaxRetries > DhcpSb->CurRetry);\r
\r
**/\r
VOID\r
DhcpComputeLease (\r
- IN OUT 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
}\r
}\r
\r
-\r
/**\r
Configure a UDP IO port to use the acquired lease address.\r
DHCP driver needs this port to unicast packet to the server\r
EFI_STATUS\r
EFIAPI\r
DhcpConfigLeaseIoPort (\r
- IN UDP_IO *UdpIo,\r
- IN VOID *Context\r
+ IN UDP_IO *UdpIo,\r
+ IN VOID *Context\r
)\r
{\r
- EFI_UDP4_CONFIG_DATA UdpConfigData;\r
- EFI_IPv4_ADDRESS Subnet;\r
- EFI_IPv4_ADDRESS Gateway;\r
- DHCP_SERVICE *DhcpSb;\r
- EFI_STATUS Status;\r
- IP4_ADDR Ip;\r
-\r
- DhcpSb = (DHCP_SERVICE *) Context;\r
-\r
- UdpConfigData.AcceptBroadcast = FALSE;\r
- UdpConfigData.AcceptPromiscuous = FALSE;\r
- UdpConfigData.AcceptAnyPort = FALSE;\r
- UdpConfigData.AllowDuplicatePort = TRUE;\r
- UdpConfigData.TypeOfService = 0;\r
- UdpConfigData.TimeToLive = 64;\r
- UdpConfigData.DoNotFragment = FALSE;\r
- UdpConfigData.ReceiveTimeout = 1;\r
- UdpConfigData.TransmitTimeout = 0;\r
-\r
- UdpConfigData.UseDefaultAddress = FALSE;\r
- UdpConfigData.StationPort = DHCP_CLIENT_PORT;\r
- UdpConfigData.RemotePort = DHCP_SERVER_PORT;\r
+ EFI_UDP4_CONFIG_DATA UdpConfigData;\r
+ EFI_IPv4_ADDRESS Subnet;\r
+ EFI_IPv4_ADDRESS Gateway;\r
+ DHCP_SERVICE *DhcpSb;\r
+ EFI_STATUS Status;\r
+ IP4_ADDR Ip;\r
+\r
+ DhcpSb = (DHCP_SERVICE *)Context;\r
+\r
+ UdpConfigData.AcceptBroadcast = FALSE;\r
+ UdpConfigData.AcceptPromiscuous = FALSE;\r
+ UdpConfigData.AcceptAnyPort = FALSE;\r
+ UdpConfigData.AllowDuplicatePort = TRUE;\r
+ UdpConfigData.TypeOfService = 0;\r
+ UdpConfigData.TimeToLive = 64;\r
+ UdpConfigData.DoNotFragment = FALSE;\r
+ UdpConfigData.ReceiveTimeout = 1;\r
+ UdpConfigData.TransmitTimeout = 0;\r
+\r
+ UdpConfigData.UseDefaultAddress = FALSE;\r
+ UdpConfigData.StationPort = DHCP_CLIENT_PORT;\r
+ UdpConfigData.RemotePort = DHCP_SERVER_PORT;\r
\r
Ip = HTONL (DhcpSb->ClientAddr);\r
CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
Update the lease states when a new lease is acquired. It will not only\r
save the acquired the address and lease time, it will also create a UDP\r
**/\r
EFI_STATUS\r
DhcpLeaseAcquired (\r
- IN OUT DHCP_SERVICE *DhcpSb\r
+ IN OUT DHCP_SERVICE *DhcpSb\r
)\r
{\r
DhcpSb->ClientAddr = EFI_NTOHL (DhcpSb->Selected->Dhcp4.Header.YourAddr);\r
\r
if (DhcpSb->Para != NULL) {\r
- DhcpSb->Netmask = DhcpSb->Para->NetMask;\r
- DhcpSb->ServerAddr = DhcpSb->Para->ServerId;\r
+ DhcpSb->Netmask = DhcpSb->Para->NetMask;\r
+ DhcpSb->ServerAddr = DhcpSb->Para->ServerId;\r
}\r
\r
if (DhcpSb->Netmask == 0) {\r
return DhcpSetState (DhcpSb, Dhcp4Bound, TRUE);\r
}\r
\r
-\r
/**\r
Clean up the DHCP related states, IoStatus isn't reset.\r
\r
**/\r
VOID\r
DhcpCleanLease (\r
- IN DHCP_SERVICE *DhcpSb\r
+ IN DHCP_SERVICE *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
+ 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
FreePool (DhcpSb->LastOffer);\r
DhcpSb->Para = NULL;\r
}\r
\r
- DhcpSb->Lease = 0;\r
- DhcpSb->T1 = 0;\r
- DhcpSb->T2 = 0;\r
- DhcpSb->ExtraRefresh = FALSE;\r
+ DhcpSb->Lease = 0;\r
+ DhcpSb->T1 = 0;\r
+ DhcpSb->T2 = 0;\r
+ DhcpSb->ExtraRefresh = FALSE;\r
\r
if (DhcpSb->LeaseIoPort != NULL) {\r
UdpIoFreeIo (DhcpSb->LeaseIoPort);\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
+ DhcpSb->PacketToLive = 0;\r
+ DhcpSb->LastTimeout = 0;\r
+ DhcpSb->CurRetry = 0;\r
+ DhcpSb->MaxRetries = 0;\r
+ DhcpSb->LeaseLife = 0;\r
\r
//\r
// Clean active config data.\r
DhcpCleanConfigure (&DhcpSb->ActiveConfig);\r
}\r
\r
-\r
/**\r
Select a offer among all the offers collected. If the offer selected is\r
of BOOTP, the lease is recorded and user notified. If the offer is of\r
**/\r
EFI_STATUS\r
DhcpChooseOffer (\r
- IN DHCP_SERVICE *DhcpSb\r
+ IN DHCP_SERVICE *DhcpSb\r
)\r
{\r
- EFI_DHCP4_PACKET *Selected;\r
- EFI_DHCP4_PACKET *NewPacket;\r
- EFI_DHCP4_PACKET *TempPacket;\r
- EFI_STATUS Status;\r
+ EFI_DHCP4_PACKET *Selected;\r
+ EFI_DHCP4_PACKET *NewPacket;\r
+ EFI_DHCP4_PACKET *TempPacket;\r
+ EFI_STATUS Status;\r
\r
ASSERT (DhcpSb->LastOffer != NULL);\r
\r
Selected = DhcpSb->LastOffer;\r
\r
if ((NewPacket != NULL) && !EFI_ERROR (DhcpValidateOptions (NewPacket, NULL))) {\r
- TempPacket = (EFI_DHCP4_PACKET *) AllocatePool (NewPacket->Size);\r
+ TempPacket = (EFI_DHCP4_PACKET *)AllocatePool (NewPacket->Size);\r
if (TempPacket != NULL) {\r
CopyMem (TempPacket, NewPacket, NewPacket->Size);\r
FreePool (Selected);\r
return DhcpSendMessage (DhcpSb, Selected, DhcpSb->Para, DHCP_MSG_REQUEST, NULL);\r
}\r
\r
-\r
/**\r
Terminate the current address acquire. All the allocated resources\r
are released. Be careful when calling this function. A rule related\r
**/\r
VOID\r
DhcpEndSession (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN EFI_STATUS Status\r
+ IN DHCP_SERVICE *DhcpSb,\r
+ IN EFI_STATUS Status\r
)\r
{\r
if (DHCP_CONNECTED (DhcpSb->DhcpState)) {\r
DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_ALL);\r
}\r
\r
-\r
/**\r
Handle packets in DHCP select state.\r
\r
**/\r
EFI_STATUS\r
DhcpHandleSelect (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN EFI_DHCP4_PACKET *Packet,\r
- IN DHCP_PARAMETER *Para\r
+ IN DHCP_SERVICE *DhcpSb,\r
+ IN EFI_DHCP4_PACKET *Packet,\r
+ IN DHCP_PARAMETER *Para\r
)\r
{\r
- EFI_STATUS Status;\r
+ EFI_STATUS Status;\r
\r
Status = EFI_SUCCESS;\r
\r
//\r
if (!DHCP_IS_BOOTP (Para) &&\r
((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))\r
- ) {\r
+ )\r
+ {\r
goto ON_EXIT;\r
}\r
\r
DhcpSb->LastOffer = Packet;\r
\r
return DhcpChooseOffer (DhcpSb);\r
-\r
} else if (Status == EFI_NOT_READY) {\r
if (DhcpSb->LastOffer != NULL) {\r
FreePool (DhcpSb->LastOffer);\r
}\r
\r
DhcpSb->LastOffer = Packet;\r
-\r
} else if (Status == EFI_ABORTED) {\r
//\r
// DhcpInput will end the session upon error return. Remember\r
return Status;\r
}\r
\r
-\r
/**\r
Handle packets in DHCP request state.\r
\r
**/\r
EFI_STATUS\r
DhcpHandleRequest (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN EFI_DHCP4_PACKET *Packet,\r
- IN DHCP_PARAMETER *Para\r
+ IN DHCP_SERVICE *DhcpSb,\r
+ IN EFI_DHCP4_PACKET *Packet,\r
+ IN DHCP_PARAMETER *Para\r
)\r
{\r
- EFI_DHCP4_HEADER *Head;\r
- EFI_DHCP4_HEADER *Selected;\r
- EFI_STATUS Status;\r
- UINT8 *Message;\r
+ EFI_DHCP4_HEADER *Head;\r
+ EFI_DHCP4_HEADER *Selected;\r
+ EFI_STATUS Status;\r
+ UINT8 *Message;\r
\r
ASSERT (!DHCP_IS_BOOTP (DhcpSb->Para));\r
\r
- Head = &Packet->Dhcp4.Header;\r
- Selected = &DhcpSb->Selected->Dhcp4.Header;\r
+ Head = &Packet->Dhcp4.Header;\r
+ Selected = &DhcpSb->Selected->Dhcp4.Header;\r
\r
//\r
// Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK.\r
if (DHCP_IS_BOOTP (Para) ||\r
(Para->ServerId != DhcpSb->Para->ServerId) ||\r
((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))\r
- ) {\r
-\r
+ )\r
+ {\r
Status = EFI_SUCCESS;\r
goto ON_EXIT;\r
}\r
Message = NULL;\r
\r
if (!EFI_IP4_EQUAL (&Head->YourAddr, &Selected->YourAddr)) {\r
- Message = (UINT8 *) "Lease confirmed isn't the same as that in the offer";\r
+ Message = (UINT8 *)"Lease confirmed isn't the same as that in the offer";\r
goto REJECT;\r
}\r
\r
Status = DhcpCallUser (DhcpSb, Dhcp4RcvdAck, Packet, NULL);\r
\r
if (EFI_ERROR (Status)) {\r
- Message = (UINT8 *) "Lease is denied upon received ACK";\r
+ Message = (UINT8 *)"Lease is denied upon received ACK";\r
goto REJECT;\r
}\r
\r
Status = DhcpLeaseAcquired (DhcpSb);\r
\r
if (EFI_ERROR (Status)) {\r
- Message = (UINT8 *) "Lease is denied upon entering bound";\r
+ Message = (UINT8 *)"Lease is denied upon entering bound";\r
goto REJECT;\r
}\r
\r
return Status;\r
}\r
\r
-\r
/**\r
Handle packets in DHCP renew/rebound state.\r
\r
**/\r
EFI_STATUS\r
DhcpHandleRenewRebind (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN EFI_DHCP4_PACKET *Packet,\r
- IN DHCP_PARAMETER *Para\r
+ IN DHCP_SERVICE *DhcpSb,\r
+ IN EFI_DHCP4_PACKET *Packet,\r
+ IN DHCP_PARAMETER *Para\r
)\r
{\r
- EFI_DHCP4_HEADER *Head;\r
- EFI_DHCP4_HEADER *Selected;\r
- EFI_STATUS Status;\r
+ EFI_DHCP4_HEADER *Head;\r
+ EFI_DHCP4_HEADER *Selected;\r
+ EFI_STATUS Status;\r
\r
ASSERT (!DHCP_IS_BOOTP (DhcpSb->Para));\r
\r
- Head = &Packet->Dhcp4.Header;\r
- Selected = &DhcpSb->Selected->Dhcp4.Header;\r
+ Head = &Packet->Dhcp4.Header;\r
+ Selected = &DhcpSb->Selected->Dhcp4.Header;\r
\r
//\r
// Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK\r
if (DHCP_IS_BOOTP (Para) ||\r
(Para->ServerId != DhcpSb->Para->ServerId) ||\r
((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))\r
- ) {\r
-\r
+ )\r
+ {\r
Status = EFI_SUCCESS;\r
goto ON_EXIT;\r
}\r
DhcpSetState (DhcpSb, Dhcp4Bound, TRUE);\r
\r
if (DhcpSb->ExtraRefresh != 0) {\r
- DhcpSb->ExtraRefresh = FALSE;\r
+ DhcpSb->ExtraRefresh = FALSE;\r
\r
- DhcpSb->IoStatus = EFI_SUCCESS;\r
+ DhcpSb->IoStatus = EFI_SUCCESS;\r
DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_RENEWREBIND);\r
}\r
\r
return Status;\r
}\r
\r
-\r
/**\r
Handle packets in DHCP reboot state.\r
\r
**/\r
EFI_STATUS\r
DhcpHandleReboot (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN EFI_DHCP4_PACKET *Packet,\r
- IN DHCP_PARAMETER *Para\r
+ IN DHCP_SERVICE *DhcpSb,\r
+ IN EFI_DHCP4_PACKET *Packet,\r
+ IN DHCP_PARAMETER *Para\r
)\r
{\r
- EFI_DHCP4_HEADER *Head;\r
- EFI_STATUS Status;\r
+ EFI_DHCP4_HEADER *Head;\r
+ EFI_STATUS Status;\r
\r
Head = &Packet->Dhcp4.Header;\r
\r
//\r
if (DHCP_IS_BOOTP (Para) ||\r
((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))\r
- ) {\r
-\r
+ )\r
+ {\r
Status = EFI_SUCCESS;\r
goto ON_EXIT;\r
}\r
if (Para->DhcpType == DHCP_MSG_NAK) {\r
DhcpCallUser (DhcpSb, Dhcp4RcvdNak, Packet, NULL);\r
\r
- DhcpSb->ClientAddr = 0;\r
- DhcpSb->DhcpState = Dhcp4Init;\r
+ DhcpSb->ClientAddr = 0;\r
+ DhcpSb->DhcpState = Dhcp4Init;\r
\r
- Status = DhcpInitRequest (DhcpSb);\r
+ Status = DhcpInitRequest (DhcpSb);\r
goto ON_EXIT;\r
}\r
\r
goto ON_EXIT;\r
}\r
\r
- DhcpSb->Selected = Packet;\r
- Status = DhcpLeaseAcquired (DhcpSb);\r
+ DhcpSb->Selected = Packet;\r
+ Status = DhcpLeaseAcquired (DhcpSb);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
return Status;\r
}\r
\r
-\r
/**\r
Handle the received DHCP packets. This function drives the DHCP\r
state machine.\r
VOID\r
EFIAPI\r
DhcpInput (\r
- NET_BUF *UdpPacket,\r
- UDP_END_POINT *EndPoint,\r
- EFI_STATUS IoStatus,\r
- VOID *Context\r
+ NET_BUF *UdpPacket,\r
+ UDP_END_POINT *EndPoint,\r
+ EFI_STATUS IoStatus,\r
+ VOID *Context\r
)\r
{\r
- DHCP_SERVICE *DhcpSb;\r
- EFI_DHCP4_HEADER *Head;\r
- EFI_DHCP4_PACKET *Packet;\r
- DHCP_PARAMETER *Para;\r
- EFI_STATUS Status;\r
- UINT32 Len;\r
+ DHCP_SERVICE *DhcpSb;\r
+ EFI_DHCP4_HEADER *Head;\r
+ EFI_DHCP4_PACKET *Packet;\r
+ DHCP_PARAMETER *Para;\r
+ EFI_STATUS Status;\r
+ UINT32 Len;\r
\r
- Packet = NULL;\r
- DhcpSb = (DHCP_SERVICE *) Context;\r
+ Packet = NULL;\r
+ DhcpSb = (DHCP_SERVICE *)Context;\r
\r
//\r
// Don't restart receive if error occurs or DHCP is destroyed.\r
//\r
if (EFI_ERROR (IoStatus)) {\r
- return ;\r
+ return;\r
} else if (DhcpSb->ServiceState == DHCP_DESTROY) {\r
NetbufFree (UdpPacket);\r
- return ;\r
+ return;\r
}\r
\r
ASSERT (UdpPacket != NULL);\r
//\r
// Copy the DHCP message to a continuous memory block\r
//\r
- Len = sizeof (EFI_DHCP4_PACKET) + UdpPacket->TotalSize - sizeof (EFI_DHCP4_HEADER);\r
- Packet = (EFI_DHCP4_PACKET *) AllocatePool (Len);\r
+ Len = sizeof (EFI_DHCP4_PACKET) + UdpPacket->TotalSize - sizeof (EFI_DHCP4_HEADER);\r
+ Packet = (EFI_DHCP4_PACKET *)AllocatePool (Len);\r
\r
if (Packet == NULL) {\r
goto RESTART;\r
}\r
\r
- Packet->Size = Len;\r
- Head = &Packet->Dhcp4.Header;\r
- Packet->Length = NetbufCopy (UdpPacket, 0, UdpPacket->TotalSize, (UINT8 *) Head);\r
+ Packet->Size = Len;\r
+ Head = &Packet->Dhcp4.Header;\r
+ Packet->Length = NetbufCopy (UdpPacket, 0, UdpPacket->TotalSize, (UINT8 *)Head);\r
\r
if (Packet->Length != UdpPacket->TotalSize) {\r
goto RESTART;\r
//\r
if ((Head->OpCode != BOOTP_REPLY) ||\r
(NTOHL (Head->Xid) != DhcpSb->Xid) ||\r
- (CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0)) {\r
+ (CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0))\r
+ {\r
goto RESTART;\r
}\r
\r
Para = NULL;\r
if ((Packet->Length > sizeof (EFI_DHCP4_HEADER) + sizeof (UINT32)) &&\r
(Packet->Dhcp4.Magik == DHCP_OPTION_MAGIC) &&\r
- EFI_ERROR (DhcpValidateOptions (Packet, &Para))) {\r
-\r
+ EFI_ERROR (DhcpValidateOptions (Packet, &Para)))\r
+ {\r
goto RESTART;\r
}\r
\r
Status = EFI_SUCCESS;\r
\r
switch (DhcpSb->DhcpState) {\r
- case Dhcp4Selecting:\r
- Status = DhcpHandleSelect (DhcpSb, Packet, Para);\r
- break;\r
+ case Dhcp4Selecting:\r
+ Status = DhcpHandleSelect (DhcpSb, Packet, Para);\r
+ break;\r
\r
- case Dhcp4Requesting:\r
- Status = DhcpHandleRequest (DhcpSb, Packet, Para);\r
- break;\r
+ case Dhcp4Requesting:\r
+ Status = DhcpHandleRequest (DhcpSb, Packet, Para);\r
+ break;\r
\r
- case Dhcp4InitReboot:\r
- case Dhcp4Init:\r
- case Dhcp4Bound:\r
- //\r
- // Ignore the packet in INITREBOOT, INIT and BOUND states\r
- //\r
- FreePool (Packet);\r
- Status = EFI_SUCCESS;\r
- break;\r
+ case Dhcp4InitReboot:\r
+ case Dhcp4Init:\r
+ case Dhcp4Bound:\r
+ //\r
+ // Ignore the packet in INITREBOOT, INIT and BOUND states\r
+ //\r
+ FreePool (Packet);\r
+ Status = EFI_SUCCESS;\r
+ break;\r
\r
- case Dhcp4Renewing:\r
- case Dhcp4Rebinding:\r
- Status = DhcpHandleRenewRebind (DhcpSb, Packet, Para);\r
- break;\r
+ case Dhcp4Renewing:\r
+ case Dhcp4Rebinding:\r
+ Status = DhcpHandleRenewRebind (DhcpSb, Packet, Para);\r
+ break;\r
\r
- case Dhcp4Rebooting:\r
- Status = DhcpHandleReboot (DhcpSb, Packet, Para);\r
- break;\r
+ case Dhcp4Rebooting:\r
+ Status = DhcpHandleReboot (DhcpSb, Packet, Para);\r
+ break;\r
}\r
\r
if (Para != NULL) {\r
NetbufFree (UdpPacket);\r
UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);\r
DhcpEndSession (DhcpSb, Status);\r
- return ;\r
+ return;\r
}\r
\r
RESTART:\r
VOID\r
EFIAPI\r
DhcpOnPacketSent (\r
- NET_BUF *Packet,\r
- UDP_END_POINT *EndPoint,\r
- EFI_STATUS IoStatus,\r
- VOID *Context\r
+ NET_BUF *Packet,\r
+ UDP_END_POINT *EndPoint,\r
+ EFI_STATUS IoStatus,\r
+ VOID *Context\r
)\r
{\r
NetbufFree (Packet);\r
}\r
\r
-\r
-\r
/**\r
Build and transmit a DHCP message according to the current states.\r
This function implement the Table 5. of RFC 2131. Always transits\r
**/\r
EFI_STATUS\r
DhcpSendMessage (\r
- IN DHCP_SERVICE *DhcpSb,\r
- IN EFI_DHCP4_PACKET *Seed,\r
- IN DHCP_PARAMETER *Para,\r
- IN UINT8 Type,\r
- IN UINT8 *Msg\r
+ IN DHCP_SERVICE *DhcpSb,\r
+ IN EFI_DHCP4_PACKET *Seed,\r
+ IN DHCP_PARAMETER *Para,\r
+ IN UINT8 Type,\r
+ IN UINT8 *Msg\r
)\r
{\r
- EFI_DHCP4_CONFIG_DATA *Config;\r
- EFI_DHCP4_PACKET *Packet;\r
- EFI_DHCP4_PACKET *NewPacket;\r
- EFI_DHCP4_HEADER *Head;\r
- EFI_DHCP4_HEADER *SeedHead;\r
- UDP_IO *UdpIo;\r
- UDP_END_POINT EndPoint;\r
- NET_BUF *Wrap;\r
- NET_FRAGMENT Frag;\r
- EFI_STATUS Status;\r
- IP4_ADDR IpAddr;\r
- UINT8 *Buf;\r
- UINT16 MaxMsg;\r
- UINT32 Len;\r
- UINT32 Index;\r
+ EFI_DHCP4_CONFIG_DATA *Config;\r
+ EFI_DHCP4_PACKET *Packet;\r
+ EFI_DHCP4_PACKET *NewPacket;\r
+ EFI_DHCP4_HEADER *Head;\r
+ EFI_DHCP4_HEADER *SeedHead;\r
+ UDP_IO *UdpIo;\r
+ UDP_END_POINT EndPoint;\r
+ NET_BUF *Wrap;\r
+ NET_FRAGMENT Frag;\r
+ EFI_STATUS Status;\r
+ IP4_ADDR IpAddr;\r
+ UINT8 *Buf;\r
+ UINT16 MaxMsg;\r
+ UINT32 Len;\r
+ UINT32 Index;\r
\r
//\r
// Allocate a big enough memory block to hold the DHCP packet\r
Len = sizeof (EFI_DHCP4_PACKET) + 128 + DhcpSb->UserOptionLen;\r
\r
if (Msg != NULL) {\r
- Len += (UINT32)AsciiStrLen ((CHAR8 *) Msg);\r
+ Len += (UINT32)AsciiStrLen ((CHAR8 *)Msg);\r
}\r
\r
Packet = AllocatePool (Len);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- Packet->Size = Len;\r
- Packet->Length = sizeof (EFI_DHCP4_HEADER) + sizeof (UINT32);\r
+ Packet->Size = Len;\r
+ Packet->Length = sizeof (EFI_DHCP4_HEADER) + sizeof (UINT32);\r
\r
//\r
// Fill in the DHCP header fields\r
//\r
- Config = &DhcpSb->ActiveConfig;\r
- SeedHead = NULL;\r
+ Config = &DhcpSb->ActiveConfig;\r
+ SeedHead = NULL;\r
\r
if (Seed != NULL) {\r
SeedHead = &Seed->Dhcp4.Header;\r
Head = &Packet->Dhcp4.Header;\r
ZeroMem (Head, sizeof (EFI_DHCP4_HEADER));\r
\r
- Head->OpCode = BOOTP_REQUEST;\r
- Head->HwType = DhcpSb->HwType;\r
- Head->HwAddrLen = DhcpSb->HwLen;\r
- Head->Xid = HTONL (DhcpSb->Xid);\r
- Head->Reserved = HTONS (0x8000); //Server, broadcast the message please.\r
+ Head->OpCode = BOOTP_REQUEST;\r
+ Head->HwType = DhcpSb->HwType;\r
+ Head->HwAddrLen = DhcpSb->HwLen;\r
+ Head->Xid = HTONL (DhcpSb->Xid);\r
+ Head->Reserved = HTONS (0x8000); // Server, broadcast the message please.\r
\r
EFI_IP4 (Head->ClientAddr) = HTONL (DhcpSb->ClientAddr);\r
CopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen);\r
//\r
Head->Seconds = DhcpSb->LastPacket->Dhcp4.Header.Seconds;\r
} else {\r
- SetElapsedTime(&Head->Seconds, DhcpSb->ActiveChild);\r
+ SetElapsedTime (&Head->Seconds, DhcpSb->ActiveChild);\r
}\r
\r
//\r
//\r
if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE) ||\r
((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting))\r
- ) {\r
-\r
+ )\r
+ {\r
ASSERT ((Para != NULL) && (Para->ServerId != 0));\r
\r
- IpAddr = HTONL (Para->ServerId);\r
- Buf = DhcpAppendOption (Buf, DHCP4_TAG_SERVER_ID, 4, (UINT8 *) &IpAddr);\r
+ IpAddr = HTONL (Para->ServerId);\r
+ Buf = DhcpAppendOption (Buf, DHCP4_TAG_SERVER_ID, 4, (UINT8 *)&IpAddr);\r
}\r
\r
//\r
if (Type == DHCP_MSG_REQUEST) {\r
if (DhcpSb->DhcpState == Dhcp4Rebooting) {\r
IpAddr = EFI_IP4 (Config->ClientAddress);\r
-\r
} else if (DhcpSb->DhcpState == Dhcp4Requesting) {\r
ASSERT (SeedHead != NULL);\r
IpAddr = EFI_IP4 (SeedHead->YourAddr);\r
}\r
-\r
} else if (Type == DHCP_MSG_DECLINE) {\r
ASSERT (SeedHead != NULL);\r
IpAddr = EFI_IP4 (SeedHead->YourAddr);\r
}\r
\r
if (IpAddr != 0) {\r
- Buf = DhcpAppendOption (Buf, DHCP4_TAG_REQUEST_IP, 4, (UINT8 *) &IpAddr);\r
+ Buf = DhcpAppendOption (Buf, DHCP4_TAG_REQUEST_IP, 4, (UINT8 *)&IpAddr);\r
}\r
\r
//\r
// override the BOOTFILE and SERVER fields in the message head.\r
//\r
if ((Type != DHCP_MSG_DECLINE) && (Type != DHCP_MSG_RELEASE)) {\r
- MaxMsg = HTONS (0xFF00);\r
- Buf = DhcpAppendOption (Buf, DHCP4_TAG_MAXMSG, 2, (UINT8 *) &MaxMsg);\r
+ MaxMsg = HTONS (0xFF00);\r
+ Buf = DhcpAppendOption (Buf, DHCP4_TAG_MAXMSG, 2, (UINT8 *)&MaxMsg);\r
}\r
\r
//\r
// Append the user's message if it isn't NULL\r
//\r
if (Msg != NULL) {\r
- Len = MIN ((UINT32) AsciiStrLen ((CHAR8 *) Msg), 255);\r
- Buf = DhcpAppendOption (Buf, DHCP4_TAG_MESSAGE, (UINT16) Len, Msg);\r
+ Len = MIN ((UINT32)AsciiStrLen ((CHAR8 *)Msg), 255);\r
+ Buf = DhcpAppendOption (Buf, DHCP4_TAG_MESSAGE, (UINT16)Len, Msg);\r
}\r
\r
//\r
// if it is a DHCP decline or DHCP release .\r
//\r
if (((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) &&\r
- (Config->OptionList[Index]->OpCode != DHCP4_TAG_CLIENT_ID)) {\r
+ (Config->OptionList[Index]->OpCode != DHCP4_TAG_CLIENT_ID))\r
+ {\r
continue;\r
}\r
\r
}\r
}\r
\r
- *(Buf++) = DHCP4_TAG_EOP;\r
- Packet->Length += (UINT32) (Buf - Packet->Dhcp4.Option);\r
+ *(Buf++) = DHCP4_TAG_EOP;\r
+ Packet->Length += (UINT32)(Buf - Packet->Dhcp4.Option);\r
\r
//\r
// OK, the message is built, call the user to override it.\r
\r
if (Type == DHCP_MSG_DISCOVER) {\r
Status = DhcpCallUser (DhcpSb, Dhcp4SendDiscover, Packet, &NewPacket);\r
-\r
} else if (Type == DHCP_MSG_REQUEST) {\r
Status = DhcpCallUser (DhcpSb, Dhcp4SendRequest, Packet, &NewPacket);\r
-\r
} else if (Type == DHCP_MSG_DECLINE) {\r
Status = DhcpCallUser (DhcpSb, Dhcp4SendDecline, Packet, &NewPacket);\r
}\r
//\r
// Wrap it into a netbuf then send it.\r
//\r
- Frag.Bulk = (UINT8 *) &Packet->Dhcp4.Header;\r
+ Frag.Bulk = (UINT8 *)&Packet->Dhcp4.Header;\r
Frag.Len = Packet->Length;\r
Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);\r
\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
Retransmit a saved packet. Only DISCOVER and REQUEST messages\r
will be retransmitted.\r
**/\r
EFI_STATUS\r
DhcpRetransmit (\r
- IN DHCP_SERVICE *DhcpSb\r
+ IN DHCP_SERVICE *DhcpSb\r
)\r
{\r
- UDP_IO *UdpIo;\r
- UDP_END_POINT EndPoint;\r
- NET_BUF *Wrap;\r
- NET_FRAGMENT Frag;\r
- EFI_STATUS Status;\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
// 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
+ SetElapsedTime (&DhcpSb->LastPacket->Dhcp4.Header.Seconds, DhcpSb->ActiveChild);\r
}\r
\r
//\r
// Wrap it into a netbuf then send it.\r
//\r
- Frag.Bulk = (UINT8 *) &DhcpSb->LastPacket->Dhcp4.Header;\r
+ Frag.Bulk = (UINT8 *)&DhcpSb->LastPacket->Dhcp4.Header;\r
Frag.Len = DhcpSb->LastPacket->Length;\r
Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);\r
\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
Each DHCP service has three timer. Two of them are count down timer.\r
One for the packet retransmission. The other is to collect the offers.\r
VOID\r
EFIAPI\r
DhcpOnTimerTick (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
)\r
{\r
- LIST_ENTRY *Entry;\r
- LIST_ENTRY *Next;\r
- DHCP_SERVICE *DhcpSb;\r
- DHCP_PROTOCOL *Instance;\r
- EFI_STATUS Status;\r
+ LIST_ENTRY *Entry;\r
+ LIST_ENTRY *Next;\r
+ DHCP_SERVICE *DhcpSb;\r
+ DHCP_PROTOCOL *Instance;\r
+ EFI_STATUS Status;\r
\r
- DhcpSb = (DHCP_SERVICE *) Context;\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
+ if ((Instance != NULL) && (Instance->ElaspedTime < 0xffff)) {\r
Instance->ElaspedTime++;\r
}\r
\r
// Check the retransmit timer\r
//\r
if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) {\r
-\r
//\r
// Select offer at each timeout if any offer received.\r
//\r
- if (DhcpSb->DhcpState == Dhcp4Selecting && DhcpSb->LastOffer != NULL) {\r
-\r
+ if ((DhcpSb->DhcpState == Dhcp4Selecting) && (DhcpSb->LastOffer != NULL)) {\r
Status = DhcpChooseOffer (DhcpSb);\r
\r
- if (EFI_ERROR(Status)) {\r
+ if (EFI_ERROR (Status)) {\r
if (DhcpSb->LastOffer != NULL) {\r
FreePool (DhcpSb->LastOffer);\r
DhcpSb->LastOffer = NULL;\r
//\r
DhcpRetransmit (DhcpSb);\r
DhcpSetTransmitTimer (DhcpSb);\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
\r
if (DhcpSb->LeaseLife < DhcpSb->T1) {\r
Status = DhcpSetState (DhcpSb, Dhcp4Bound, FALSE);\r
-\r
} else if (DhcpSb->LeaseLife < DhcpSb->T2) {\r
Status = DhcpSetState (DhcpSb, Dhcp4Renewing, FALSE);\r
-\r
} else if (DhcpSb->LeaseLife < DhcpSb->Lease) {\r
Status = DhcpSetState (DhcpSb, Dhcp4Rebinding, FALSE);\r
-\r
} else {\r
goto END_SESSION;\r
-\r
}\r
\r
DhcpSb->IoStatus = EFI_TIMEOUT;\r
// requesting extra renew/rebind. Adjust the state after that.\r
//\r
if (DhcpSb->ExtraRefresh != 0) {\r
- return ;\r
+ return;\r
}\r
\r
if (DhcpSb->LeaseLife == DhcpSb->Lease) {\r
// Lease expires, end the session\r
//\r
goto END_SESSION;\r
-\r
} else if (DhcpSb->LeaseLife == DhcpSb->T2) {\r
//\r
// T2 expires, transit to rebinding then send a REQUEST to any server\r
}\r
\r
if (Instance != NULL) {\r
- Instance->ElaspedTime= 0;\r
+ Instance->ElaspedTime = 0;\r
}\r
\r
Status = DhcpSendMessage (\r
if (EFI_ERROR (Status)) {\r
goto END_SESSION;\r
}\r
-\r
} else if (DhcpSb->LeaseLife == DhcpSb->T1) {\r
//\r
// T1 expires, transit to renewing, then send a REQUEST to the server\r
}\r
\r
if (Instance != NULL) {\r
- Instance->ElaspedTime= 0;\r
+ Instance->ElaspedTime = 0;\r
}\r
\r
Status = DhcpSendMessage (\r
NET_LIST_FOR_EACH_SAFE (Entry, Next, &DhcpSb->Children) {\r
Instance = NET_LIST_USER_STRUCT (Entry, DHCP_PROTOCOL, Link);\r
Instance->Timeout--;\r
- if (Instance->Timeout == 0 && Instance->Token != NULL) {\r
+ if ((Instance->Timeout == 0) && (Instance->Token != NULL)) {\r
PxeDhcpDone (Instance);\r
}\r
}\r
\r
- return ;\r
+ return;\r
\r
END_SESSION:\r
DhcpEndSession (DhcpSb, EFI_TIMEOUT);\r
\r
- return ;\r
+ return;\r
}\r