2007-09-30 05:08:02 +02:00
|
|
|
/** @file
|
2009-01-16 01:09:52 +01:00
|
|
|
The DHCP4 protocol implementation.
|
2018-06-27 15:08:52 +02:00
|
|
|
|
|
|
|
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:05:13 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2007-09-30 05:08:02 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef __EFI_DHCP4_IO_H__
|
|
|
|
#define __EFI_DHCP4_IO_H__
|
|
|
|
|
2009-02-09 03:59:07 +01:00
|
|
|
#include <Uefi.h>
|
2007-09-30 05:08:02 +02:00
|
|
|
|
|
|
|
#include <Protocol/ServiceBinding.h>
|
|
|
|
|
|
|
|
#include <Library/NetLib.h>
|
|
|
|
#include <Library/UdpIoLib.h>
|
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/MemoryAllocationLib.h>
|
|
|
|
|
2021-12-05 23:54:07 +01:00
|
|
|
#define DHCP_WAIT_OFFER 3 // Time to wait the offers
|
2008-11-14 10:16:11 +01:00
|
|
|
#define DHCP_DEFAULT_LEASE 7 * 24 * 60 * 60 // Seven days as default.
|
2021-12-05 23:54:07 +01:00
|
|
|
#define DHCP_SERVER_PORT 67
|
|
|
|
#define DHCP_CLIENT_PORT 68
|
2008-06-30 09:20:33 +02:00
|
|
|
|
2009-11-04 09:18:34 +01:00
|
|
|
//
|
|
|
|
// BOOTP header "op" field
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
#define BOOTP_REQUEST 1
|
|
|
|
#define BOOTP_REPLY 2
|
2007-09-30 05:08:02 +02:00
|
|
|
|
2009-11-04 09:18:34 +01:00
|
|
|
//
|
|
|
|
// DHCP message types
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
#define DHCP_MSG_DISCOVER 1
|
|
|
|
#define DHCP_MSG_OFFER 2
|
|
|
|
#define DHCP_MSG_REQUEST 3
|
|
|
|
#define DHCP_MSG_DECLINE 4
|
|
|
|
#define DHCP_MSG_ACK 5
|
|
|
|
#define DHCP_MSG_NAK 6
|
|
|
|
#define DHCP_MSG_RELEASE 7
|
|
|
|
#define DHCP_MSG_INFORM 8
|
2007-09-30 05:08:02 +02:00
|
|
|
|
2009-11-04 09:18:34 +01:00
|
|
|
//
|
|
|
|
// DHCP notify user type
|
|
|
|
//
|
2021-12-05 23:54:07 +01:00
|
|
|
#define DHCP_NOTIFY_COMPLETION 1
|
|
|
|
#define DHCP_NOTIFY_RENEWREBIND 2
|
|
|
|
#define DHCP_NOTIFY_ALL 3
|
2007-09-30 05:08:02 +02:00
|
|
|
|
|
|
|
#define DHCP_IS_BOOTP(Parameter) (((Parameter) == NULL) || ((Parameter)->DhcpType == 0))
|
|
|
|
|
|
|
|
#define DHCP_CONNECTED(State) \
|
|
|
|
(((State) == Dhcp4Bound) || ((State) == (Dhcp4Renewing)) || ((State) == Dhcp4Rebinding))
|
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
/**
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param DhcpSb The DHCP service instance
|
|
|
|
@param State The new DHCP state to change to
|
|
|
|
@param CallUser Whether we need to call user
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The state is changed
|
|
|
|
@retval EFI_ABORTED The user asks to abort the DHCP process.
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
EFI_STATUS
|
|
|
|
DhcpSetState (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN OUT DHCP_SERVICE *DhcpSb,
|
|
|
|
IN INTN State,
|
|
|
|
IN BOOLEAN CallUser
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
/**
|
|
|
|
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.
|
|
|
|
|
2009-01-16 01:09:52 +01:00
|
|
|
@param[in] DhcpSb The DHCP service instance
|
|
|
|
@param[in] Seed The seed packet which the new packet is based on
|
|
|
|
@param[in] Para The DHCP parameter of the Seed packet
|
|
|
|
@param[in] Type The message type to send
|
|
|
|
@param[in] Msg The human readable message to include in the packet
|
|
|
|
sent.
|
2008-06-30 09:20:33 +02:00
|
|
|
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate resources for the packet
|
|
|
|
@retval EFI_ACCESS_DENIED Failed to transmit the packet through UDP
|
|
|
|
@retval EFI_SUCCESS The message is sent
|
2008-11-18 15:30:46 +01:00
|
|
|
@retval other Other error occurs
|
2008-06-30 09:20:33 +02:00
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
EFI_STATUS
|
|
|
|
DhcpSendMessage (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN DHCP_SERVICE *DhcpSb,
|
|
|
|
IN EFI_DHCP4_PACKET *Seed,
|
|
|
|
IN DHCP_PARAMETER *Para,
|
|
|
|
IN UINT8 Type,
|
|
|
|
IN UINT8 *Msg
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
/**
|
|
|
|
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.
|
2020-02-07 02:07:44 +01:00
|
|
|
The third timer increments the lease life which is compared to T1, T2,
|
2008-06-30 09:20:33 +02:00
|
|
|
and lease to determine the time to renew and rebind the lease.
|
|
|
|
DhcpOnTimerTick will be called once every second.
|
|
|
|
|
2009-01-16 01:09:52 +01:00
|
|
|
@param[in] Event The timer event
|
|
|
|
@param[in] Context The context, which is the DHCP service instance.
|
2008-06-30 09:20:33 +02:00
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
DhcpOnTimerTick (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
/**
|
2008-11-18 15:30:46 +01:00
|
|
|
Handle the received DHCP packets. This function drives the DHCP
|
2008-06-30 09:20:33 +02:00
|
|
|
state machine.
|
|
|
|
|
|
|
|
@param UdpPacket The UDP packets received.
|
2009-10-30 06:11:38 +01:00
|
|
|
@param EndPoint The local/remote UDP access point
|
2008-06-30 09:20:33 +02:00
|
|
|
@param IoStatus The status of the UDP receive
|
|
|
|
@param Context The opaque parameter to the function.
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
VOID
|
2010-04-17 01:24:45 +02:00
|
|
|
EFIAPI
|
2007-09-30 05:08:02 +02:00
|
|
|
DhcpInput (
|
2021-12-05 23:54:07 +01:00
|
|
|
NET_BUF *UdpPacket,
|
|
|
|
UDP_END_POINT *EndPoint,
|
|
|
|
EFI_STATUS IoStatus,
|
|
|
|
VOID *Context
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
/**
|
|
|
|
Send an initial DISCOVER or REQUEST message according to the
|
|
|
|
DHCP service's current state.
|
|
|
|
|
2009-01-16 01:09:52 +01:00
|
|
|
@param[in] DhcpSb The DHCP service instance
|
2008-06-30 09:20:33 +02:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS The request has been sent
|
2008-11-18 15:30:46 +01:00
|
|
|
@retval other Some error occurs when sending the request.
|
2008-06-30 09:20:33 +02:00
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
EFI_STATUS
|
|
|
|
DhcpInitRequest (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN DHCP_SERVICE *DhcpSb
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
/**
|
|
|
|
Clean up the DHCP related states, IoStatus isn't reset.
|
|
|
|
|
|
|
|
@param DhcpSb The DHCP instance service.
|
|
|
|
|
|
|
|
**/
|
2007-09-30 05:08:02 +02:00
|
|
|
VOID
|
|
|
|
DhcpCleanLease (
|
2021-12-05 23:54:07 +01:00
|
|
|
IN DHCP_SERVICE *DhcpSb
|
2007-09-30 05:08:02 +02:00
|
|
|
);
|
|
|
|
|
2008-06-30 09:20:33 +02:00
|
|
|
/**
|
|
|
|
Release the net buffer when packet is sent.
|
|
|
|
|
|
|
|
@param UdpPacket The UDP packets received.
|
2009-10-30 06:11:38 +01:00
|
|
|
@param EndPoint The local/remote UDP access point
|
2008-06-30 09:20:33 +02:00
|
|
|
@param IoStatus The status of the UDP receive
|
|
|
|
@param Context The opaque parameter to the function.
|
|
|
|
|
|
|
|
**/
|
2007-12-18 08:01:23 +01:00
|
|
|
VOID
|
2010-04-17 01:24:45 +02:00
|
|
|
EFIAPI
|
2007-12-18 08:01:23 +01:00
|
|
|
DhcpOnPacketSent (
|
2021-12-05 23:54:07 +01:00
|
|
|
NET_BUF *Packet,
|
|
|
|
UDP_END_POINT *EndPoint,
|
|
|
|
EFI_STATUS IoStatus,
|
|
|
|
VOID *Context
|
2007-12-18 08:01:23 +01:00
|
|
|
);
|
|
|
|
|
2007-09-30 05:08:02 +02:00
|
|
|
#endif
|