summaryrefslogtreecommitdiffstats
path: root/NetworkPkg/Dhcp4Dxe/Dhcp4Io.c
diff options
context:
space:
mode:
Diffstat (limited to 'NetworkPkg/Dhcp4Dxe/Dhcp4Io.c')
-rw-r--r--NetworkPkg/Dhcp4Dxe/Dhcp4Io.c525
1 files changed, 244 insertions, 281 deletions
diff --git a/NetworkPkg/Dhcp4Dxe/Dhcp4Io.c b/NetworkPkg/Dhcp4Dxe/Dhcp4Io.c
index f073eed58a..238e186c5b 100644
--- a/NetworkPkg/Dhcp4Dxe/Dhcp4Io.c
+++ b/NetworkPkg/Dhcp4Dxe/Dhcp4Io.c
@@ -6,12 +6,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-
#include "Dhcp4Impl.h"
UINT32 mDhcp4DefaultTimeout[4] = { 4, 8, 16, 32 };
-
/**
Send an initial DISCOVER or REQUEST message according to the
DHCP service's current state.
@@ -24,17 +22,17 @@ UINT32 mDhcp4DefaultTimeout[4] = { 4, 8, 16, 32 };
**/
EFI_STATUS
DhcpInitRequest (
- IN DHCP_SERVICE *DhcpSb
+ IN DHCP_SERVICE *DhcpSb
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
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;
+ DhcpSb->ActiveChild->ElaspedTime = 0;
if (DhcpSb->DhcpState == Dhcp4Init) {
DhcpSetState (DhcpSb, Dhcp4Selecting, FALSE);
@@ -57,7 +55,6 @@ DhcpInitRequest (
return EFI_SUCCESS;
}
-
/**
Call user provided callback function, and return the value the
function returns. If the user doesn't provide a callback, a
@@ -76,14 +73,14 @@ DhcpInitRequest (
**/
EFI_STATUS
DhcpCallUser (
- IN DHCP_SERVICE *DhcpSb,
- IN EFI_DHCP4_EVENT Event,
- IN EFI_DHCP4_PACKET *Packet OPTIONAL,
- OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL
+ IN DHCP_SERVICE *DhcpSb,
+ IN EFI_DHCP4_EVENT Event,
+ IN EFI_DHCP4_PACKET *Packet OPTIONAL,
+ OUT EFI_DHCP4_PACKET **NewPacket OPTIONAL
)
{
- EFI_DHCP4_CONFIG_DATA *Config;
- EFI_STATUS Status;
+ EFI_DHCP4_CONFIG_DATA *Config;
+ EFI_STATUS Status;
if (NewPacket != NULL) {
*NewPacket = NULL;
@@ -109,7 +106,7 @@ DhcpCallUser (
Status = Config->Dhcp4Callback (
&DhcpSb->ActiveChild->Dhcp4Protocol,
Config->CallbackContext,
- (EFI_DHCP4_STATE) DhcpSb->DhcpState,
+ (EFI_DHCP4_STATE)DhcpSb->DhcpState,
Event,
Packet,
NewPacket
@@ -127,7 +124,6 @@ DhcpCallUser (
return EFI_ABORTED;
}
-
/**
Notify the user about the operation result.
@@ -137,35 +133,33 @@ DhcpCallUser (
**/
VOID
DhcpNotifyUser (
- IN DHCP_SERVICE *DhcpSb,
- IN INTN Which
+ IN DHCP_SERVICE *DhcpSb,
+ IN INTN Which
)
{
- DHCP_PROTOCOL *Child;
+ DHCP_PROTOCOL *Child;
if ((Child = DhcpSb->ActiveChild) == NULL) {
- return ;
+ return;
}
if ((Child->CompletionEvent != NULL) &&
((Which == DHCP_NOTIFY_COMPLETION) || (Which == DHCP_NOTIFY_ALL))
- ) {
-
+ )
+ {
gBS->SignalEvent (Child->CompletionEvent);
Child->CompletionEvent = NULL;
}
if ((Child->RenewRebindEvent != NULL) &&
((Which == DHCP_NOTIFY_RENEWREBIND) || (Which == DHCP_NOTIFY_ALL))
- ) {
-
+ )
+ {
gBS->SignalEvent (Child->RenewRebindEvent);
Child->RenewRebindEvent = NULL;
}
}
-
-
/**
Set the DHCP state. If CallUser is true, it will try to notify
the user before change the state by DhcpNotifyUser. It returns
@@ -183,25 +177,22 @@ DhcpNotifyUser (
**/
EFI_STATUS
DhcpSetState (
- IN OUT DHCP_SERVICE *DhcpSb,
- IN INTN State,
- IN BOOLEAN CallUser
+ IN OUT DHCP_SERVICE *DhcpSb,
+ IN INTN State,
+ IN BOOLEAN CallUser
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
if (CallUser) {
Status = EFI_SUCCESS;
if (State == Dhcp4Renewing) {
Status = DhcpCallUser (DhcpSb, Dhcp4EnterRenewing, NULL, NULL);
-
} else if (State == Dhcp4Rebinding) {
Status = DhcpCallUser (DhcpSb, Dhcp4EnterRebinding, NULL, NULL);
-
} else if (State == Dhcp4Bound) {
Status = DhcpCallUser (DhcpSb, Dhcp4BoundCompleted, NULL, NULL);
-
}
if (EFI_ERROR (Status)) {
@@ -224,14 +215,13 @@ DhcpSetState (
DhcpSb->MaxRetries = 4;
}
- DhcpSb->CurRetry = 0;
- DhcpSb->PacketToLive = 0;
- DhcpSb->LastTimeout = 0;
- DhcpSb->DhcpState = State;
+ DhcpSb->CurRetry = 0;
+ DhcpSb->PacketToLive = 0;
+ DhcpSb->LastTimeout = 0;
+ DhcpSb->DhcpState = State;
return EFI_SUCCESS;
}
-
/**
Set the retransmit timer for the packet. It will select from either
the discover timeouts/request timeouts or the default timeout values.
@@ -241,10 +231,10 @@ DhcpSetState (
**/
VOID
DhcpSetTransmitTimer (
- IN OUT DHCP_SERVICE *DhcpSb
+ IN OUT DHCP_SERVICE *DhcpSb
)
{
- UINT32 *Times;
+ UINT32 *Times;
ASSERT (DhcpSb->MaxRetries > DhcpSb->CurRetry);
@@ -275,8 +265,8 @@ DhcpSetTransmitTimer (
**/
VOID
DhcpComputeLease (
- IN OUT DHCP_SERVICE *DhcpSb,
- IN DHCP_PARAMETER *Para
+ IN OUT DHCP_SERVICE *DhcpSb,
+ IN DHCP_PARAMETER *Para
)
{
ASSERT (Para != NULL);
@@ -298,7 +288,6 @@ DhcpComputeLease (
}
}
-
/**
Configure a UDP IO port to use the acquired lease address.
DHCP driver needs this port to unicast packet to the server
@@ -314,32 +303,32 @@ DhcpComputeLease (
EFI_STATUS
EFIAPI
DhcpConfigLeaseIoPort (
- IN UDP_IO *UdpIo,
- IN VOID *Context
+ IN UDP_IO *UdpIo,
+ IN VOID *Context
)
{
- EFI_UDP4_CONFIG_DATA UdpConfigData;
- EFI_IPv4_ADDRESS Subnet;
- EFI_IPv4_ADDRESS Gateway;
- DHCP_SERVICE *DhcpSb;
- EFI_STATUS Status;
- IP4_ADDR Ip;
-
- DhcpSb = (DHCP_SERVICE *) Context;
-
- UdpConfigData.AcceptBroadcast = FALSE;
- UdpConfigData.AcceptPromiscuous = FALSE;
- UdpConfigData.AcceptAnyPort = FALSE;
- UdpConfigData.AllowDuplicatePort = TRUE;
- UdpConfigData.TypeOfService = 0;
- UdpConfigData.TimeToLive = 64;
- UdpConfigData.DoNotFragment = FALSE;
- UdpConfigData.ReceiveTimeout = 1;
- UdpConfigData.TransmitTimeout = 0;
-
- UdpConfigData.UseDefaultAddress = FALSE;
- UdpConfigData.StationPort = DHCP_CLIENT_PORT;
- UdpConfigData.RemotePort = DHCP_SERVER_PORT;
+ EFI_UDP4_CONFIG_DATA UdpConfigData;
+ EFI_IPv4_ADDRESS Subnet;
+ EFI_IPv4_ADDRESS Gateway;
+ DHCP_SERVICE *DhcpSb;
+ EFI_STATUS Status;
+ IP4_ADDR Ip;
+
+ DhcpSb = (DHCP_SERVICE *)Context;
+
+ UdpConfigData.AcceptBroadcast = FALSE;
+ UdpConfigData.AcceptPromiscuous = FALSE;
+ UdpConfigData.AcceptAnyPort = FALSE;
+ UdpConfigData.AllowDuplicatePort = TRUE;
+ UdpConfigData.TypeOfService = 0;
+ UdpConfigData.TimeToLive = 64;
+ UdpConfigData.DoNotFragment = FALSE;
+ UdpConfigData.ReceiveTimeout = 1;
+ UdpConfigData.TransmitTimeout = 0;
+
+ UdpConfigData.UseDefaultAddress = FALSE;
+ UdpConfigData.StationPort = DHCP_CLIENT_PORT;
+ UdpConfigData.RemotePort = DHCP_SERVER_PORT;
Ip = HTONL (DhcpSb->ClientAddr);
CopyMem (&UdpConfigData.StationAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));
@@ -370,7 +359,6 @@ DhcpConfigLeaseIoPort (
return EFI_SUCCESS;
}
-
/**
Update the lease states when a new lease is acquired. It will not only
save the acquired the address and lease time, it will also create a UDP
@@ -384,14 +372,14 @@ DhcpConfigLeaseIoPort (
**/
EFI_STATUS
DhcpLeaseAcquired (
- IN OUT DHCP_SERVICE *DhcpSb
+ IN OUT DHCP_SERVICE *DhcpSb
)
{
DhcpSb->ClientAddr = EFI_NTOHL (DhcpSb->Selected->Dhcp4.Header.YourAddr);
if (DhcpSb->Para != NULL) {
- DhcpSb->Netmask = DhcpSb->Para->NetMask;
- DhcpSb->ServerAddr = DhcpSb->Para->ServerId;
+ DhcpSb->Netmask = DhcpSb->Para->NetMask;
+ DhcpSb->ServerAddr = DhcpSb->Para->ServerId;
}
if (DhcpSb->Netmask == 0) {
@@ -426,7 +414,6 @@ DhcpLeaseAcquired (
return DhcpSetState (DhcpSb, Dhcp4Bound, TRUE);
}
-
/**
Clean up the DHCP related states, IoStatus isn't reset.
@@ -435,14 +422,14 @@ DhcpLeaseAcquired (
**/
VOID
DhcpCleanLease (
- IN DHCP_SERVICE *DhcpSb
+ IN DHCP_SERVICE *DhcpSb
)
{
- DhcpSb->DhcpState = Dhcp4Init;
- DhcpSb->Xid = DhcpSb->Xid + 1;
- DhcpSb->ClientAddr = 0;
- DhcpSb->Netmask = 0;
- DhcpSb->ServerAddr = 0;
+ DhcpSb->DhcpState = Dhcp4Init;
+ DhcpSb->Xid = DhcpSb->Xid + 1;
+ DhcpSb->ClientAddr = 0;
+ DhcpSb->Netmask = 0;
+ DhcpSb->ServerAddr = 0;
if (DhcpSb->LastOffer != NULL) {
FreePool (DhcpSb->LastOffer);
@@ -459,10 +446,10 @@ DhcpCleanLease (
DhcpSb->Para = NULL;
}
- DhcpSb->Lease = 0;
- DhcpSb->T1 = 0;
- DhcpSb->T2 = 0;
- DhcpSb->ExtraRefresh = FALSE;
+ DhcpSb->Lease = 0;
+ DhcpSb->T1 = 0;
+ DhcpSb->T2 = 0;
+ DhcpSb->ExtraRefresh = FALSE;
if (DhcpSb->LeaseIoPort != NULL) {
UdpIoFreeIo (DhcpSb->LeaseIoPort);
@@ -474,11 +461,11 @@ DhcpCleanLease (
DhcpSb->LastPacket = NULL;
}
- DhcpSb->PacketToLive = 0;
- DhcpSb->LastTimeout = 0;
- DhcpSb->CurRetry = 0;
- DhcpSb->MaxRetries = 0;
- DhcpSb->LeaseLife = 0;
+ DhcpSb->PacketToLive = 0;
+ DhcpSb->LastTimeout = 0;
+ DhcpSb->CurRetry = 0;
+ DhcpSb->MaxRetries = 0;
+ DhcpSb->LeaseLife = 0;
//
// Clean active config data.
@@ -486,7 +473,6 @@ DhcpCleanLease (
DhcpCleanConfigure (&DhcpSb->ActiveConfig);
}
-
/**
Select a offer among all the offers collected. If the offer selected is
of BOOTP, the lease is recorded and user notified. If the offer is of
@@ -499,13 +485,13 @@ DhcpCleanLease (
**/
EFI_STATUS
DhcpChooseOffer (
- IN DHCP_SERVICE *DhcpSb
+ IN DHCP_SERVICE *DhcpSb
)
{
- EFI_DHCP4_PACKET *Selected;
- EFI_DHCP4_PACKET *NewPacket;
- EFI_DHCP4_PACKET *TempPacket;
- EFI_STATUS Status;
+ EFI_DHCP4_PACKET *Selected;
+ EFI_DHCP4_PACKET *NewPacket;
+ EFI_DHCP4_PACKET *TempPacket;
+ EFI_STATUS Status;
ASSERT (DhcpSb->LastOffer != NULL);
@@ -524,7 +510,7 @@ DhcpChooseOffer (
Selected = DhcpSb->LastOffer;
if ((NewPacket != NULL) && !EFI_ERROR (DhcpValidateOptions (NewPacket, NULL))) {
- TempPacket = (EFI_DHCP4_PACKET *) AllocatePool (NewPacket->Size);
+ TempPacket = (EFI_DHCP4_PACKET *)AllocatePool (NewPacket->Size);
if (TempPacket != NULL) {
CopyMem (TempPacket, NewPacket, NewPacket->Size);
FreePool (Selected);
@@ -565,7 +551,6 @@ DhcpChooseOffer (
return DhcpSendMessage (DhcpSb, Selected, DhcpSb->Para, DHCP_MSG_REQUEST, NULL);
}
-
/**
Terminate the current address acquire. All the allocated resources
are released. Be careful when calling this function. A rule related
@@ -578,8 +563,8 @@ DhcpChooseOffer (
**/
VOID
DhcpEndSession (
- IN DHCP_SERVICE *DhcpSb,
- IN EFI_STATUS Status
+ IN DHCP_SERVICE *DhcpSb,
+ IN EFI_STATUS Status
)
{
if (DHCP_CONNECTED (DhcpSb->DhcpState)) {
@@ -594,7 +579,6 @@ DhcpEndSession (
DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_ALL);
}
-
/**
Handle packets in DHCP select state.
@@ -609,12 +593,12 @@ DhcpEndSession (
**/
EFI_STATUS
DhcpHandleSelect (
- IN DHCP_SERVICE *DhcpSb,
- IN EFI_DHCP4_PACKET *Packet,
- IN DHCP_PARAMETER *Para
+ IN DHCP_SERVICE *DhcpSb,
+ IN EFI_DHCP4_PACKET *Packet,
+ IN DHCP_PARAMETER *Para
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
Status = EFI_SUCCESS;
@@ -626,7 +610,8 @@ DhcpHandleSelect (
//
if (!DHCP_IS_BOOTP (Para) &&
((Para->DhcpType != DHCP_MSG_OFFER) || (Para->ServerId == 0))
- ) {
+ )
+ {
goto ON_EXIT;
}
@@ -646,14 +631,12 @@ DhcpHandleSelect (
DhcpSb->LastOffer = Packet;
return DhcpChooseOffer (DhcpSb);
-
} else if (Status == EFI_NOT_READY) {
if (DhcpSb->LastOffer != NULL) {
FreePool (DhcpSb->LastOffer);
}
DhcpSb->LastOffer = Packet;
-
} else if (Status == EFI_ABORTED) {
//
// DhcpInput will end the session upon error return. Remember
@@ -669,7 +652,6 @@ ON_EXIT:
return Status;
}
-
/**
Handle packets in DHCP request state.
@@ -684,20 +666,20 @@ ON_EXIT:
**/
EFI_STATUS
DhcpHandleRequest (
- IN DHCP_SERVICE *DhcpSb,
- IN EFI_DHCP4_PACKET *Packet,
- IN DHCP_PARAMETER *Para
+ IN DHCP_SERVICE *DhcpSb,
+ IN EFI_DHCP4_PACKET *Packet,
+ IN DHCP_PARAMETER *Para
)
{
- EFI_DHCP4_HEADER *Head;
- EFI_DHCP4_HEADER *Selected;
- EFI_STATUS Status;
- UINT8 *Message;
+ EFI_DHCP4_HEADER *Head;
+ EFI_DHCP4_HEADER *Selected;
+ EFI_STATUS Status;
+ UINT8 *Message;
ASSERT (!DHCP_IS_BOOTP (DhcpSb->Para));
- Head = &Packet->Dhcp4.Header;
- Selected = &DhcpSb->Selected->Dhcp4.Header;
+ Head = &Packet->Dhcp4.Header;
+ Selected = &DhcpSb->Selected->Dhcp4.Header;
//
// Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK.
@@ -705,8 +687,8 @@ DhcpHandleRequest (
if (DHCP_IS_BOOTP (Para) ||
(Para->ServerId != DhcpSb->Para->ServerId) ||
((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))
- ) {
-
+ )
+ {
Status = EFI_SUCCESS;
goto ON_EXIT;
}
@@ -727,14 +709,14 @@ DhcpHandleRequest (
Message = NULL;
if (!EFI_IP4_EQUAL (&Head->YourAddr, &Selected->YourAddr)) {
- Message = (UINT8 *) "Lease confirmed isn't the same as that in the offer";
+ Message = (UINT8 *)"Lease confirmed isn't the same as that in the offer";
goto REJECT;
}
Status = DhcpCallUser (DhcpSb, Dhcp4RcvdAck, Packet, NULL);
if (EFI_ERROR (Status)) {
- Message = (UINT8 *) "Lease is denied upon received ACK";
+ Message = (UINT8 *)"Lease is denied upon received ACK";
goto REJECT;
}
@@ -744,7 +726,7 @@ DhcpHandleRequest (
Status = DhcpLeaseAcquired (DhcpSb);
if (EFI_ERROR (Status)) {
- Message = (UINT8 *) "Lease is denied upon entering bound";
+ Message = (UINT8 *)"Lease is denied upon entering bound";
goto REJECT;
}
@@ -762,7 +744,6 @@ ON_EXIT:
return Status;
}
-
/**
Handle packets in DHCP renew/rebound state.
@@ -777,19 +758,19 @@ ON_EXIT:
**/
EFI_STATUS
DhcpHandleRenewRebind (
- IN DHCP_SERVICE *DhcpSb,
- IN EFI_DHCP4_PACKET *Packet,
- IN DHCP_PARAMETER *Para
+ IN DHCP_SERVICE *DhcpSb,
+ IN EFI_DHCP4_PACKET *Packet,
+ IN DHCP_PARAMETER *Para
)
{
- EFI_DHCP4_HEADER *Head;
- EFI_DHCP4_HEADER *Selected;
- EFI_STATUS Status;
+ EFI_DHCP4_HEADER *Head;
+ EFI_DHCP4_HEADER *Selected;
+ EFI_STATUS Status;
ASSERT (!DHCP_IS_BOOTP (DhcpSb->Para));
- Head = &Packet->Dhcp4.Header;
- Selected = &DhcpSb->Selected->Dhcp4.Header;
+ Head = &Packet->Dhcp4.Header;
+ Selected = &DhcpSb->Selected->Dhcp4.Header;
//
// Ignore the BOOTP message and DHCP messages other than DHCP ACK/NACK
@@ -797,8 +778,8 @@ DhcpHandleRenewRebind (
if (DHCP_IS_BOOTP (Para) ||
(Para->ServerId != DhcpSb->Para->ServerId) ||
((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))
- ) {
-
+ )
+ {
Status = EFI_SUCCESS;
goto ON_EXIT;
}
@@ -835,9 +816,9 @@ DhcpHandleRenewRebind (
DhcpSetState (DhcpSb, Dhcp4Bound, TRUE);
if (DhcpSb->ExtraRefresh != 0) {
- DhcpSb->ExtraRefresh = FALSE;
+ DhcpSb->ExtraRefresh = FALSE;
- DhcpSb->IoStatus = EFI_SUCCESS;
+ DhcpSb->IoStatus = EFI_SUCCESS;
DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_RENEWREBIND);
}
@@ -846,7 +827,6 @@ ON_EXIT:
return Status;
}
-
/**
Handle packets in DHCP reboot state.
@@ -861,13 +841,13 @@ ON_EXIT:
**/
EFI_STATUS
DhcpHandleReboot (
- IN DHCP_SERVICE *DhcpSb,
- IN EFI_DHCP4_PACKET *Packet,
- IN DHCP_PARAMETER *Para
+ IN DHCP_SERVICE *DhcpSb,
+ IN EFI_DHCP4_PACKET *Packet,
+ IN DHCP_PARAMETER *Para
)
{
- EFI_DHCP4_HEADER *Head;
- EFI_STATUS Status;
+ EFI_DHCP4_HEADER *Head;
+ EFI_STATUS Status;
Head = &Packet->Dhcp4.Header;
@@ -876,8 +856,8 @@ DhcpHandleReboot (
//
if (DHCP_IS_BOOTP (Para) ||
((Para->DhcpType != DHCP_MSG_ACK) && (Para->DhcpType != DHCP_MSG_NAK))
- ) {
-
+ )
+ {
Status = EFI_SUCCESS;
goto ON_EXIT;
}
@@ -888,10 +868,10 @@ DhcpHandleReboot (
if (Para->DhcpType == DHCP_MSG_NAK) {
DhcpCallUser (DhcpSb, Dhcp4RcvdNak, Packet, NULL);
- DhcpSb->ClientAddr = 0;
- DhcpSb->DhcpState = Dhcp4Init;
+ DhcpSb->ClientAddr = 0;
+ DhcpSb->DhcpState = Dhcp4Init;
- Status = DhcpInitRequest (DhcpSb);
+ Status = DhcpInitRequest (DhcpSb);
goto ON_EXIT;
}
@@ -917,8 +897,8 @@ DhcpHandleReboot (
goto ON_EXIT;
}
- DhcpSb->Selected = Packet;
- Status = DhcpLeaseAcquired (DhcpSb);
+ DhcpSb->Selected = Packet;
+ Status = DhcpLeaseAcquired (DhcpSb);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -932,7 +912,6 @@ ON_EXIT:
return Status;
}
-
/**
Handle the received DHCP packets. This function drives the DHCP
state machine.
@@ -946,30 +925,30 @@ ON_EXIT:
VOID
EFIAPI
DhcpInput (
- NET_BUF *UdpPacket,
- UDP_END_POINT *EndPoint,
- EFI_STATUS IoStatus,
- VOID *Context
+ NET_BUF *UdpPacket,
+ UDP_END_POINT *EndPoint,
+ EFI_STATUS IoStatus,
+ VOID *Context
)
{
- DHCP_SERVICE *DhcpSb;
- EFI_DHCP4_HEADER *Head;
- EFI_DHCP4_PACKET *Packet;
- DHCP_PARAMETER *Para;
- EFI_STATUS Status;
- UINT32 Len;
+ DHCP_SERVICE *DhcpSb;
+ EFI_DHCP4_HEADER *Head;
+ EFI_DHCP4_PACKET *Packet;
+ DHCP_PARAMETER *Para;
+ EFI_STATUS Status;
+ UINT32 Len;
- Packet = NULL;
- DhcpSb = (DHCP_SERVICE *) Context;
+ Packet = NULL;
+ DhcpSb = (DHCP_SERVICE *)Context;
//
// Don't restart receive if error occurs or DHCP is destroyed.
//
if (EFI_ERROR (IoStatus)) {
- return ;
+ return;
} else if (DhcpSb->ServiceState == DHCP_DESTROY) {
NetbufFree (UdpPacket);
- return ;
+ return;
}
ASSERT (UdpPacket != NULL);
@@ -988,16 +967,16 @@ DhcpInput (
//
// Copy the DHCP message to a continuous memory block
//
- Len = sizeof (EFI_DHCP4_PACKET) + UdpPacket->TotalSize - sizeof (EFI_DHCP4_HEADER);
- Packet = (EFI_DHCP4_PACKET *) AllocatePool (Len);
+ Len = sizeof (EFI_DHCP4_PACKET) + UdpPacket->TotalSize - sizeof (EFI_DHCP4_HEADER);
+ Packet = (EFI_DHCP4_PACKET *)AllocatePool (Len);
if (Packet == NULL) {
goto RESTART;
}
- Packet->Size = Len;
- Head = &Packet->Dhcp4.Header;
- Packet->Length = NetbufCopy (UdpPacket, 0, UdpPacket->TotalSize, (UINT8 *) Head);
+ Packet->Size = Len;
+ Head = &Packet->Dhcp4.Header;
+ Packet->Length = NetbufCopy (UdpPacket, 0, UdpPacket->TotalSize, (UINT8 *)Head);
if (Packet->Length != UdpPacket->TotalSize) {
goto RESTART;
@@ -1008,7 +987,8 @@ DhcpInput (
//
if ((Head->OpCode != BOOTP_REPLY) ||
(NTOHL (Head->Xid) != DhcpSb->Xid) ||
- (CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0)) {
+ (CompareMem (DhcpSb->ClientAddressSendOut, Head->ClientHwAddr, Head->HwAddrLen) != 0))
+ {
goto RESTART;
}
@@ -1018,8 +998,8 @@ DhcpInput (
Para = NULL;
if ((Packet->Length > sizeof (EFI_DHCP4_HEADER) + sizeof (UINT32)) &&
(Packet->Dhcp4.Magik == DHCP_OPTION_MAGIC) &&
- EFI_ERROR (DhcpValidateOptions (Packet, &Para))) {
-
+ EFI_ERROR (DhcpValidateOptions (Packet, &Para)))
+ {
goto RESTART;
}
@@ -1035,32 +1015,32 @@ DhcpInput (
Status = EFI_SUCCESS;
switch (DhcpSb->DhcpState) {
- case Dhcp4Selecting:
- Status = DhcpHandleSelect (DhcpSb, Packet, Para);
- break;
+ case Dhcp4Selecting:
+ Status = DhcpHandleSelect (DhcpSb, Packet, Para);
+ break;
- case Dhcp4Requesting:
- Status = DhcpHandleRequest (DhcpSb, Packet, Para);
- break;
+ case Dhcp4Requesting:
+ Status = DhcpHandleRequest (DhcpSb, Packet, Para);
+ break;
- case Dhcp4InitReboot:
- case Dhcp4Init:
- case Dhcp4Bound:
- //
- // Ignore the packet in INITREBOOT, INIT and BOUND states
- //
- FreePool (Packet);
- Status = EFI_SUCCESS;
- break;
+ case Dhcp4InitReboot:
+ case Dhcp4Init:
+ case Dhcp4Bound:
+ //
+ // Ignore the packet in INITREBOOT, INIT and BOUND states
+ //
+ FreePool (Packet);
+ Status = EFI_SUCCESS;
+ break;
- case Dhcp4Renewing:
- case Dhcp4Rebinding:
- Status = DhcpHandleRenewRebind (DhcpSb, Packet, Para);
- break;
+ case Dhcp4Renewing:
+ case Dhcp4Rebinding:
+ Status = DhcpHandleRenewRebind (DhcpSb, Packet, Para);
+ break;
- case Dhcp4Rebooting:
- Status = DhcpHandleReboot (DhcpSb, Packet, Para);
- break;
+ case Dhcp4Rebooting:
+ Status = DhcpHandleReboot (DhcpSb, Packet, Para);
+ break;
}
if (Para != NULL) {
@@ -1073,7 +1053,7 @@ DhcpInput (
NetbufFree (UdpPacket);
UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);
DhcpEndSession (DhcpSb, Status);
- return ;
+ return;
}
RESTART:
@@ -1102,17 +1082,15 @@ RESTART:
VOID
EFIAPI
DhcpOnPacketSent (
- NET_BUF *Packet,
- UDP_END_POINT *EndPoint,
- EFI_STATUS IoStatus,
- VOID *Context
+ NET_BUF *Packet,
+ UDP_END_POINT *EndPoint,
+ EFI_STATUS IoStatus,
+ VOID *Context
)
{
NetbufFree (Packet);
}
-
-
/**
Build and transmit a DHCP message according to the current states.
This function implement the Table 5. of RFC 2131. Always transits
@@ -1134,28 +1112,28 @@ DhcpOnPacketSent (
**/
EFI_STATUS
DhcpSendMessage (
- IN DHCP_SERVICE *DhcpSb,
- IN EFI_DHCP4_PACKET *Seed,
- IN DHCP_PARAMETER *Para,
- IN UINT8 Type,
- IN UINT8 *Msg
+ IN DHCP_SERVICE *DhcpSb,
+ IN EFI_DHCP4_PACKET *Seed,
+ IN DHCP_PARAMETER *Para,
+ IN UINT8 Type,
+ IN UINT8 *Msg
)
{
- EFI_DHCP4_CONFIG_DATA *Config;
- EFI_DHCP4_PACKET *Packet;
- EFI_DHCP4_PACKET *NewPacket;
- EFI_DHCP4_HEADER *Head;
- EFI_DHCP4_HEADER *SeedHead;
- UDP_IO *UdpIo;
- UDP_END_POINT EndPoint;
- NET_BUF *Wrap;
- NET_FRAGMENT Frag;
- EFI_STATUS Status;
- IP4_ADDR IpAddr;
- UINT8 *Buf;
- UINT16 MaxMsg;
- UINT32 Len;
- UINT32 Index;
+ EFI_DHCP4_CONFIG_DATA *Config;
+ EFI_DHCP4_PACKET *Packet;
+ EFI_DHCP4_PACKET *NewPacket;
+ EFI_DHCP4_HEADER *Head;
+ EFI_DHCP4_HEADER *SeedHead;
+ UDP_IO *UdpIo;
+ UDP_END_POINT EndPoint;
+ NET_BUF *Wrap;
+ NET_FRAGMENT Frag;
+ EFI_STATUS Status;
+ IP4_ADDR IpAddr;
+ UINT8 *Buf;
+ UINT16 MaxMsg;
+ UINT32 Len;
+ UINT32 Index;
//
// Allocate a big enough memory block to hold the DHCP packet
@@ -1163,7 +1141,7 @@ DhcpSendMessage (
Len = sizeof (EFI_DHCP4_PACKET) + 128 + DhcpSb->UserOptionLen;
if (Msg != NULL) {
- Len += (UINT32)AsciiStrLen ((CHAR8 *) Msg);
+ Len += (UINT32)AsciiStrLen ((CHAR8 *)Msg);
}
Packet = AllocatePool (Len);
@@ -1172,14 +1150,14 @@ DhcpSendMessage (
return EFI_OUT_OF_RESOURCES;
}
- Packet->Size = Len;
- Packet->Length = sizeof (EFI_DHCP4_HEADER) + sizeof (UINT32);
+ Packet->Size = Len;
+ Packet->Length = sizeof (EFI_DHCP4_HEADER) + sizeof (UINT32);
//
// Fill in the DHCP header fields
//
- Config = &DhcpSb->ActiveConfig;
- SeedHead = NULL;
+ Config = &DhcpSb->ActiveConfig;
+ SeedHead = NULL;
if (Seed != NULL) {
SeedHead = &Seed->Dhcp4.Header;
@@ -1188,11 +1166,11 @@ DhcpSendMessage (
Head = &Packet->Dhcp4.Header;
ZeroMem (Head, sizeof (EFI_DHCP4_HEADER));
- Head->OpCode = BOOTP_REQUEST;
- Head->HwType = DhcpSb->HwType;
- Head->HwAddrLen = DhcpSb->HwLen;
- Head->Xid = HTONL (DhcpSb->Xid);
- Head->Reserved = HTONS (0x8000); //Server, broadcast the message please.
+ Head->OpCode = BOOTP_REQUEST;
+ Head->HwType = DhcpSb->HwType;
+ Head->HwAddrLen = DhcpSb->HwLen;
+ Head->Xid = HTONL (DhcpSb->Xid);
+ Head->Reserved = HTONS (0x8000); // Server, broadcast the message please.
EFI_IP4 (Head->ClientAddr) = HTONL (DhcpSb->ClientAddr);
CopyMem (Head->ClientHwAddr, DhcpSb->Mac.Addr, DhcpSb->HwLen);
@@ -1205,7 +1183,7 @@ DhcpSendMessage (
//
Head->Seconds = DhcpSb->LastPacket->Dhcp4.Header.Seconds;
} else {
- SetElapsedTime(&Head->Seconds, DhcpSb->ActiveChild);
+ SetElapsedTime (&Head->Seconds, DhcpSb->ActiveChild);
}
//
@@ -1223,12 +1201,12 @@ DhcpSendMessage (
//
if ((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE) ||
((Type == DHCP_MSG_REQUEST) && (DhcpSb->DhcpState == Dhcp4Requesting))
- ) {
-
+ )
+ {
ASSERT ((Para != NULL) && (Para->ServerId != 0));
- IpAddr = HTONL (Para->ServerId);
- Buf = DhcpAppendOption (Buf, DHCP4_TAG_SERVER_ID, 4, (UINT8 *) &IpAddr);
+ IpAddr = HTONL (Para->ServerId);
+ Buf = DhcpAppendOption (Buf, DHCP4_TAG_SERVER_ID, 4, (UINT8 *)&IpAddr);
}
//
@@ -1242,19 +1220,17 @@ DhcpSendMessage (
if (Type == DHCP_MSG_REQUEST) {
if (DhcpSb->DhcpState == Dhcp4Rebooting) {
IpAddr = EFI_IP4 (Config->ClientAddress);
-
} else if (DhcpSb->DhcpState == Dhcp4Requesting) {
ASSERT (SeedHead != NULL);
IpAddr = EFI_IP4 (SeedHead->YourAddr);
}
-
} else if (Type == DHCP_MSG_DECLINE) {
ASSERT (SeedHead != NULL);
IpAddr = EFI_IP4 (SeedHead->YourAddr);
}
if (IpAddr != 0) {
- Buf = DhcpAppendOption (Buf, DHCP4_TAG_REQUEST_IP, 4, (UINT8 *) &IpAddr);
+ Buf = DhcpAppendOption (Buf, DHCP4_TAG_REQUEST_IP, 4, (UINT8 *)&IpAddr);
}
//
@@ -1263,16 +1239,16 @@ DhcpSendMessage (
// override the BOOTFILE and SERVER fields in the message head.
//
if ((Type != DHCP_MSG_DECLINE) && (Type != DHCP_MSG_RELEASE)) {
- MaxMsg = HTONS (0xFF00);
- Buf = DhcpAppendOption (Buf, DHCP4_TAG_MAXMSG, 2, (UINT8 *) &MaxMsg);
+ MaxMsg = HTONS (0xFF00);
+ Buf = DhcpAppendOption (Buf, DHCP4_TAG_MAXMSG, 2, (UINT8 *)&MaxMsg);
}
//
// Append the user's message if it isn't NULL
//
if (Msg != NULL) {
- Len = MIN ((UINT32) AsciiStrLen ((CHAR8 *) Msg), 255);
- Buf = DhcpAppendOption (Buf, DHCP4_TAG_MESSAGE, (UINT16) Len, Msg);
+ Len = MIN ((UINT32)AsciiStrLen ((CHAR8 *)Msg), 255);
+ Buf = DhcpAppendOption (Buf, DHCP4_TAG_MESSAGE, (UINT16)Len, Msg);
}
//
@@ -1285,7 +1261,8 @@ DhcpSendMessage (
// if it is a DHCP decline or DHCP release .
//
if (((Type == DHCP_MSG_DECLINE) || (Type == DHCP_MSG_RELEASE)) &&
- (Config->OptionList[Index]->OpCode != DHCP4_TAG_CLIENT_ID)) {
+ (Config->OptionList[Index]->OpCode != DHCP4_TAG_CLIENT_ID))
+ {
continue;
}
@@ -1298,8 +1275,8 @@ DhcpSendMessage (
}
}
- *(Buf++) = DHCP4_TAG_EOP;
- Packet->Length += (UINT32) (Buf - Packet->Dhcp4.Option);
+ *(Buf++) = DHCP4_TAG_EOP;
+ Packet->Length += (UINT32)(Buf - Packet->Dhcp4.Option);
//
// OK, the message is built, call the user to override it.
@@ -1309,10 +1286,8 @@ DhcpSendMessage (
if (Type == DHCP_MSG_DISCOVER) {
Status = DhcpCallUser (DhcpSb, Dhcp4SendDiscover, Packet, &NewPacket);
-
} else if (Type == DHCP_MSG_REQUEST) {
Status = DhcpCallUser (DhcpSb, Dhcp4SendRequest, Packet, &NewPacket);
-
} else if (Type == DHCP_MSG_DECLINE) {
Status = DhcpCallUser (DhcpSb, Dhcp4SendDecline, Packet, &NewPacket);
}
@@ -1339,7 +1314,7 @@ DhcpSendMessage (
//
// Wrap it into a netbuf then send it.
//
- Frag.Bulk = (UINT8 *) &Packet->Dhcp4.Header;
+ Frag.Bulk = (UINT8 *)&Packet->Dhcp4.Header;
Frag.Len = Packet->Length;
Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);
@@ -1393,7 +1368,6 @@ DhcpSendMessage (
return EFI_SUCCESS;
}
-
/**
Retransmit a saved packet. Only DISCOVER and REQUEST messages
will be retransmitted.
@@ -1406,14 +1380,14 @@ DhcpSendMessage (
**/
EFI_STATUS
DhcpRetransmit (
- IN DHCP_SERVICE *DhcpSb
+ IN DHCP_SERVICE *DhcpSb
)
{
- UDP_IO *UdpIo;
- UDP_END_POINT EndPoint;
- NET_BUF *Wrap;
- NET_FRAGMENT Frag;
- EFI_STATUS Status;
+ UDP_IO *UdpIo;
+ UDP_END_POINT EndPoint;
+ NET_BUF *Wrap;
+ NET_FRAGMENT Frag;
+ EFI_STATUS Status;
ASSERT (DhcpSb->LastPacket != NULL);
@@ -1421,13 +1395,13 @@ DhcpRetransmit (
// For REQUEST message in Dhcp4Requesting state, do not change the secs fields.
//
if (DhcpSb->DhcpState != Dhcp4Requesting) {
- SetElapsedTime(&DhcpSb->LastPacket->Dhcp4.Header.Seconds, DhcpSb->ActiveChild);
+ SetElapsedTime (&DhcpSb->LastPacket->Dhcp4.Header.Seconds, DhcpSb->ActiveChild);
}
//
// Wrap it into a netbuf then send it.
//
- Frag.Bulk = (UINT8 *) &DhcpSb->LastPacket->Dhcp4.Header;
+ Frag.Bulk = (UINT8 *)&DhcpSb->LastPacket->Dhcp4.Header;
Frag.Len = DhcpSb->LastPacket->Length;
Wrap = NetbufFromExt (&Frag, 1, 0, 0, DhcpDummyExtFree, NULL);
@@ -1469,7 +1443,6 @@ DhcpRetransmit (
return EFI_SUCCESS;
}
-
/**
Each DHCP service has three timer. Two of them are count down timer.
One for the packet retransmission. The other is to collect the offers.
@@ -1484,23 +1457,23 @@ DhcpRetransmit (
VOID
EFIAPI
DhcpOnTimerTick (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- LIST_ENTRY *Entry;
- LIST_ENTRY *Next;
- DHCP_SERVICE *DhcpSb;
- DHCP_PROTOCOL *Instance;
- EFI_STATUS Status;
+ LIST_ENTRY *Entry;
+ LIST_ENTRY *Next;
+ DHCP_SERVICE *DhcpSb;
+ DHCP_PROTOCOL *Instance;
+ EFI_STATUS Status;
- DhcpSb = (DHCP_SERVICE *) Context;
+ 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) {
+ if ((Instance != NULL) && (Instance->ElaspedTime < 0xffff)) {
Instance->ElaspedTime++;
}
@@ -1508,15 +1481,13 @@ DhcpOnTimerTick (
// Check the retransmit timer
//
if ((DhcpSb->PacketToLive > 0) && (--DhcpSb->PacketToLive == 0)) {
-
//
// Select offer at each timeout if any offer received.
//
- if (DhcpSb->DhcpState == Dhcp4Selecting && DhcpSb->LastOffer != NULL) {
-
+ if ((DhcpSb->DhcpState == Dhcp4Selecting) && (DhcpSb->LastOffer != NULL)) {
Status = DhcpChooseOffer (DhcpSb);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
if (DhcpSb->LastOffer != NULL) {
FreePool (DhcpSb->LastOffer);
DhcpSb->LastOffer = NULL;
@@ -1532,9 +1503,7 @@ DhcpOnTimerTick (
//
DhcpRetransmit (DhcpSb);
DhcpSetTransmitTimer (DhcpSb);
-
} else if (DHCP_CONNECTED (DhcpSb->DhcpState)) {
-
//
// Retransmission failed, if the DHCP request is initiated by
// user, adjust the current state according to the lease life.
@@ -1545,16 +1514,12 @@ DhcpOnTimerTick (
if (DhcpSb->LeaseLife < DhcpSb->T1) {
Status = DhcpSetState (DhcpSb, Dhcp4Bound, FALSE);
-
} else if (DhcpSb->LeaseLife < DhcpSb->T2) {
Status = DhcpSetState (DhcpSb, Dhcp4Renewing, FALSE);
-
} else if (DhcpSb->LeaseLife < DhcpSb->Lease) {
Status = DhcpSetState (DhcpSb, Dhcp4Rebinding, FALSE);
-
} else {
goto END_SESSION;
-
}
DhcpSb->IoStatus = EFI_TIMEOUT;
@@ -1577,7 +1542,7 @@ DhcpOnTimerTick (
// requesting extra renew/rebind. Adjust the state after that.
//
if (DhcpSb->ExtraRefresh != 0) {
- return ;
+ return;
}
if (DhcpSb->LeaseLife == DhcpSb->Lease) {
@@ -1585,7 +1550,6 @@ DhcpOnTimerTick (
// Lease expires, end the session
//
goto END_SESSION;
-
} else if (DhcpSb->LeaseLife == DhcpSb->T2) {
//
// T2 expires, transit to rebinding then send a REQUEST to any server
@@ -1595,7 +1559,7 @@ DhcpOnTimerTick (
}
if (Instance != NULL) {
- Instance->ElaspedTime= 0;
+ Instance->ElaspedTime = 0;
}
Status = DhcpSendMessage (
@@ -1609,7 +1573,6 @@ DhcpOnTimerTick (
if (EFI_ERROR (Status)) {
goto END_SESSION;
}
-
} else if (DhcpSb->LeaseLife == DhcpSb->T1) {
//
// T1 expires, transit to renewing, then send a REQUEST to the server
@@ -1619,7 +1582,7 @@ DhcpOnTimerTick (
}
if (Instance != NULL) {
- Instance->ElaspedTime= 0;
+ Instance->ElaspedTime = 0;
}
Status = DhcpSendMessage (
@@ -1643,15 +1606,15 @@ ON_EXIT:
NET_LIST_FOR_EACH_SAFE (Entry, Next, &DhcpSb->Children) {
Instance = NET_LIST_USER_STRUCT (Entry, DHCP_PROTOCOL, Link);
Instance->Timeout--;
- if (Instance->Timeout == 0 && Instance->Token != NULL) {
+ if ((Instance->Timeout == 0) && (Instance->Token != NULL)) {
PxeDhcpDone (Instance);
}
}
- return ;
+ return;
END_SESSION:
DhcpEndSession (DhcpSb, EFI_TIMEOUT);
- return ;
+ return;
}