TianoCore EDK2 master
Loading...
Searching...
No Matches
Dhcp4Io.c File Reference
#include "Dhcp4Impl.h"

Go to the source code of this file.

Functions

EFI_STATUS DhcpInitRequest (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)
 
VOID DhcpNotifyUser (IN DHCP_SERVICE *DhcpSb, IN INTN Which)
 
EFI_STATUS DhcpSetState (IN OUT DHCP_SERVICE *DhcpSb, IN INTN State, IN BOOLEAN CallUser)
 
VOID DhcpSetTransmitTimer (IN OUT DHCP_SERVICE *DhcpSb)
 
VOID DhcpComputeLease (IN OUT DHCP_SERVICE *DhcpSb, IN DHCP_PARAMETER *Para)
 
EFI_STATUS EFIAPI DhcpConfigLeaseIoPort (IN UDP_IO *UdpIo, IN VOID *Context)
 
EFI_STATUS DhcpLeaseAcquired (IN OUT DHCP_SERVICE *DhcpSb)
 
VOID DhcpCleanLease (IN DHCP_SERVICE *DhcpSb)
 
EFI_STATUS DhcpChooseOffer (IN DHCP_SERVICE *DhcpSb)
 
VOID DhcpEndSession (IN DHCP_SERVICE *DhcpSb, IN EFI_STATUS Status)
 
EFI_STATUS DhcpHandleSelect (IN DHCP_SERVICE *DhcpSb, IN EFI_DHCP4_PACKET *Packet, IN DHCP_PARAMETER *Para)
 
EFI_STATUS DhcpHandleRequest (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)
 
EFI_STATUS DhcpHandleReboot (IN DHCP_SERVICE *DhcpSb, IN EFI_DHCP4_PACKET *Packet, IN DHCP_PARAMETER *Para)
 
VOID EFIAPI DhcpInput (NET_BUF *UdpPacket, UDP_END_POINT *EndPoint, EFI_STATUS IoStatus, VOID *Context)
 
VOID EFIAPI DhcpOnPacketSent (NET_BUF *Packet, UDP_END_POINT *EndPoint, EFI_STATUS IoStatus, VOID *Context)
 
EFI_STATUS DhcpSendMessage (IN DHCP_SERVICE *DhcpSb, IN EFI_DHCP4_PACKET *Seed, IN DHCP_PARAMETER *Para, IN UINT8 Type, IN UINT8 *Msg)
 
EFI_STATUS DhcpRetransmit (IN DHCP_SERVICE *DhcpSb)
 
VOID EFIAPI DhcpOnTimerTick (IN EFI_EVENT Event, IN VOID *Context)
 

Variables

UINT32 mDhcp4DefaultTimeout [4] = { 4, 8, 16, 32 }
 

Detailed Description

EFI DHCP protocol implementation.

Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Dhcp4Io.c.

Function Documentation

◆ DhcpCallUser()

EFI_STATUS DhcpCallUser ( IN DHCP_SERVICE DhcpSb,
IN EFI_DHCP4_EVENT  Event,
IN EFI_DHCP4_PACKET *Packet  OPTIONAL,
OUT EFI_DHCP4_PACKET **NewPacket  OPTIONAL 
)

Call user provided callback function, and return the value the function returns. If the user doesn't provide a callback, a proper return value is selected to let the caller continue the normal process.

Parameters
[in]DhcpSbThe DHCP service instance
[in]EventThe event as defined in the spec
[in]PacketThe current packet trigger the event
[out]NewPacketThe user's return new packet
Return values
EFI_NOT_READYDirect the caller to continue collecting the offer.
EFI_SUCCESSThe user function returns success.
EFI_ABORTEDThe user function ask it to abort.

Definition at line 75 of file Dhcp4Io.c.

◆ DhcpChooseOffer()

EFI_STATUS DhcpChooseOffer ( IN DHCP_SERVICE DhcpSb)

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 DHCP, it will request the offer from the server.

Parameters
[in]DhcpSbThe DHCP service instance.
Return values
EFI_SUCCESSOne of the offer is selected.

Definition at line 487 of file Dhcp4Io.c.

◆ DhcpCleanLease()

VOID DhcpCleanLease ( IN DHCP_SERVICE DhcpSb)

Clean up the DHCP related states, IoStatus isn't reset.

Parameters
DhcpSbThe DHCP instance service.

Definition at line 424 of file Dhcp4Io.c.

◆ DhcpComputeLease()

VOID DhcpComputeLease ( IN OUT DHCP_SERVICE DhcpSb,
IN DHCP_PARAMETER Para 
)

Compute the lease. If the server grants a permanent lease, just process it as a normal timeout value since the lease will last more than 100 years.

Parameters
DhcpSbThe DHCP service instance
ParaThe DHCP parameter extracted from the server's response.

Definition at line 267 of file Dhcp4Io.c.

◆ DhcpConfigLeaseIoPort()

EFI_STATUS EFIAPI DhcpConfigLeaseIoPort ( IN UDP_IO UdpIo,
IN VOID *  Context 
)

Configure a UDP IO port to use the acquired lease address. DHCP driver needs this port to unicast packet to the server such as DHCP release.

Parameters
[in]UdpIoThe UDP IO to configure
[in]ContextDhcp service instance.
Return values
EFI_SUCCESSThe UDP IO port is successfully configured.
OthersIt failed to configure the port.

Definition at line 305 of file Dhcp4Io.c.

◆ DhcpEndSession()

VOID DhcpEndSession ( IN DHCP_SERVICE DhcpSb,
IN EFI_STATUS  Status 
)

Terminate the current address acquire. All the allocated resources are released. Be careful when calling this function. A rule related to this is: only call DhcpEndSession at the highest level, such as DhcpInput, DhcpOnTimerTick...At the other level, just return error.

Parameters
[in]DhcpSbThe DHCP service instance
[in]StatusThe result of the DHCP process.

Definition at line 565 of file Dhcp4Io.c.

◆ DhcpHandleReboot()

EFI_STATUS DhcpHandleReboot ( IN DHCP_SERVICE DhcpSb,
IN EFI_DHCP4_PACKET Packet,
IN DHCP_PARAMETER Para 
)

Handle packets in DHCP reboot state.

Parameters
[in]DhcpSbThe DHCP service instance
[in]PacketThe DHCP packet received
[in]ParaThe DHCP parameter extracted from the packet. That is, all the option value that we care.
Return values
EFI_SUCCESSThe packet is successfully processed.
OthersSome error occurred.

Definition at line 843 of file Dhcp4Io.c.

◆ DhcpHandleRenewRebind()

EFI_STATUS DhcpHandleRenewRebind ( IN DHCP_SERVICE DhcpSb,
IN EFI_DHCP4_PACKET Packet,
IN DHCP_PARAMETER Para 
)

Handle packets in DHCP renew/rebound state.

Parameters
[in]DhcpSbThe DHCP service instance
[in]PacketThe DHCP packet received
[in]ParaThe DHCP parameter extracted from the packet. That is, all the option value that we care.
Return values
EFI_SUCCESSThe packet is successfully processed.
OthersSome error occurred.

Definition at line 760 of file Dhcp4Io.c.

◆ DhcpHandleRequest()

EFI_STATUS DhcpHandleRequest ( IN DHCP_SERVICE DhcpSb,
IN EFI_DHCP4_PACKET Packet,
IN DHCP_PARAMETER Para 
)

Handle packets in DHCP request state.

Parameters
[in]DhcpSbThe DHCP service instance
[in]PacketThe DHCP packet received
[in]ParaThe DHCP parameter extracted from the packet. That is, all the option value that we care.
Return values
EFI_SUCCESSThe packet is successfully processed.
OthersSome error occurred.

Definition at line 668 of file Dhcp4Io.c.

◆ DhcpHandleSelect()

EFI_STATUS DhcpHandleSelect ( IN DHCP_SERVICE DhcpSb,
IN EFI_DHCP4_PACKET Packet,
IN DHCP_PARAMETER Para 
)

Handle packets in DHCP select state.

Parameters
[in]DhcpSbThe DHCP service instance
[in]PacketThe DHCP packet received
[in]ParaThe DHCP parameter extracted from the packet. That is, all the option value that we care.
Return values
EFI_SUCCESSThe packet is successfully processed.
OthersSome error occurred.

Definition at line 595 of file Dhcp4Io.c.

◆ DhcpInitRequest()

EFI_STATUS DhcpInitRequest ( IN DHCP_SERVICE DhcpSb)

Send an initial DISCOVER or REQUEST message according to the DHCP service's current state.

Parameters
[in]DhcpSbThe DHCP service instance
Return values
EFI_SUCCESSThe request has been sent
otherSome error occurs when sending the request.

Definition at line 24 of file Dhcp4Io.c.

◆ DhcpInput()

VOID EFIAPI DhcpInput ( NET_BUF UdpPacket,
UDP_END_POINT EndPoint,
EFI_STATUS  IoStatus,
VOID *  Context 
)

Handle the received DHCP packets. This function drives the DHCP state machine.

Parameters
UdpPacketThe UDP packets received.
EndPointThe local/remote UDP access point
IoStatusThe status of the UDP receive
ContextThe opaque parameter to the function.

Definition at line 927 of file Dhcp4Io.c.

◆ DhcpLeaseAcquired()

EFI_STATUS DhcpLeaseAcquired ( IN OUT DHCP_SERVICE DhcpSb)

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 child to provide address resolution for the address.

Parameters
DhcpSbThe DHCP service instance
Return values
EFI_OUT_OF_RESOURCESFailed to allocate resources.
EFI_SUCCESSThe lease is recorded.

Definition at line 374 of file Dhcp4Io.c.

◆ DhcpNotifyUser()

VOID DhcpNotifyUser ( IN DHCP_SERVICE DhcpSb,
IN INTN  Which 
)

Notify the user about the operation result.

Parameters
DhcpSbDHCP service instance
WhichWhich notify function to signal

Definition at line 135 of file Dhcp4Io.c.

◆ DhcpOnPacketSent()

VOID EFIAPI DhcpOnPacketSent ( NET_BUF Packet,
UDP_END_POINT EndPoint,
EFI_STATUS  IoStatus,
VOID *  Context 
)

Release the net buffer when packet is sent.

Parameters
UdpPacketThe UDP packets received.
EndPointThe local/remote UDP access point
IoStatusThe status of the UDP receive
ContextThe opaque parameter to the function.

Definition at line 1084 of file Dhcp4Io.c.

◆ DhcpOnTimerTick()

VOID EFIAPI DhcpOnTimerTick ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

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. The third timer increments the lease life which is compared to T1, T2, and lease to determine the time to renew and rebind the lease. DhcpOnTimerTick will be called once every second.

Parameters
[in]EventThe timer event
[in]ContextThe context, which is the DHCP service instance.

Definition at line 1459 of file Dhcp4Io.c.

◆ DhcpRetransmit()

EFI_STATUS DhcpRetransmit ( IN DHCP_SERVICE DhcpSb)

Retransmit a saved packet. Only DISCOVER and REQUEST messages will be retransmitted.

Parameters
[in]DhcpSbThe DHCP service instance
Return values
EFI_ACCESS_DENIEDFailed to transmit packet through UDP port
EFI_SUCCESSThe packet is retransmitted.

Definition at line 1382 of file Dhcp4Io.c.

◆ DhcpSendMessage()

EFI_STATUS DhcpSendMessage ( IN DHCP_SERVICE DhcpSb,
IN EFI_DHCP4_PACKET Seed,
IN DHCP_PARAMETER Para,
IN UINT8  Type,
IN UINT8 *  Msg 
)

Build and transmit a DHCP message according to the current states. This function implement the Table 5. of RFC 2131. Always transits the state (as defined in Figure 5. of the same RFC) before sending a DHCP message. The table is adjusted accordingly.

Parameters
[in]DhcpSbThe DHCP service instance
[in]SeedThe seed packet which the new packet is based on
[in]ParaThe DHCP parameter of the Seed packet
[in]TypeThe message type to send
[in]MsgThe human readable message to include in the packet sent.
Return values
EFI_OUT_OF_RESOURCESFailed to allocate resources for the packet
EFI_ACCESS_DENIEDFailed to transmit the packet through UDP
EFI_SUCCESSThe message is sent
otherOther error occurs

Definition at line 1114 of file Dhcp4Io.c.

◆ DhcpSetState()

EFI_STATUS DhcpSetState ( IN OUT DHCP_SERVICE DhcpSb,
IN INTN  State,
IN BOOLEAN  CallUser 
)

Set the DHCP state. If CallUser is true, it will try to notify the user before change the state by DhcpNotifyUser. It returns EFI_ABORTED if the user return EFI_ABORTED, otherwise, it returns EFI_SUCCESS. If CallUser is FALSE, it isn't necessary to test the return value of this function.

Parameters
DhcpSbThe DHCP service instance
StateThe new DHCP state to change to
CallUserWhether we need to call user
Return values
EFI_SUCCESSThe state is changed
EFI_ABORTEDThe user asks to abort the DHCP process.

Definition at line 179 of file Dhcp4Io.c.

◆ DhcpSetTransmitTimer()

VOID DhcpSetTransmitTimer ( IN OUT DHCP_SERVICE DhcpSb)

Set the retransmit timer for the packet. It will select from either the discover timeouts/request timeouts or the default timeout values.

Parameters
DhcpSbThe DHCP service instance.

Definition at line 233 of file Dhcp4Io.c.

Variable Documentation

◆ mDhcp4DefaultTimeout

UINT32 mDhcp4DefaultTimeout[4] = { 4, 8, 16, 32 }

Definition at line 11 of file Dhcp4Io.c.