]> git.proxmox.com Git - mirror_edk2.git/blob - NetworkPkg/Dhcp4Dxe/Dhcp4Io.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / Dhcp4Dxe / Dhcp4Io.h
1 /** @file
2 The DHCP4 protocol implementation.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef __EFI_DHCP4_IO_H__
10 #define __EFI_DHCP4_IO_H__
11
12 #include <Uefi.h>
13
14 #include <Protocol/ServiceBinding.h>
15
16 #include <Library/NetLib.h>
17 #include <Library/UdpIoLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/MemoryAllocationLib.h>
20
21 #define DHCP_WAIT_OFFER 3 // Time to wait the offers
22 #define DHCP_DEFAULT_LEASE 7 * 24 * 60 * 60 // Seven days as default.
23 #define DHCP_SERVER_PORT 67
24 #define DHCP_CLIENT_PORT 68
25
26 //
27 // BOOTP header "op" field
28 //
29 #define BOOTP_REQUEST 1
30 #define BOOTP_REPLY 2
31
32 //
33 // DHCP message types
34 //
35 #define DHCP_MSG_DISCOVER 1
36 #define DHCP_MSG_OFFER 2
37 #define DHCP_MSG_REQUEST 3
38 #define DHCP_MSG_DECLINE 4
39 #define DHCP_MSG_ACK 5
40 #define DHCP_MSG_NAK 6
41 #define DHCP_MSG_RELEASE 7
42 #define DHCP_MSG_INFORM 8
43
44 //
45 // DHCP notify user type
46 //
47 #define DHCP_NOTIFY_COMPLETION 1
48 #define DHCP_NOTIFY_RENEWREBIND 2
49 #define DHCP_NOTIFY_ALL 3
50
51 #define DHCP_IS_BOOTP(Parameter) (((Parameter) == NULL) || ((Parameter)->DhcpType == 0))
52
53 #define DHCP_CONNECTED(State) \
54 (((State) == Dhcp4Bound) || ((State) == (Dhcp4Renewing)) || ((State) == Dhcp4Rebinding))
55
56 /**
57 Set the DHCP state. If CallUser is true, it will try to notify
58 the user before change the state by DhcpNotifyUser. It returns
59 EFI_ABORTED if the user return EFI_ABORTED, otherwise, it returns
60 EFI_SUCCESS. If CallUser is FALSE, it isn't necessary to test
61 the return value of this function.
62
63 @param DhcpSb The DHCP service instance
64 @param State The new DHCP state to change to
65 @param CallUser Whether we need to call user
66
67 @retval EFI_SUCCESS The state is changed
68 @retval EFI_ABORTED The user asks to abort the DHCP process.
69
70 **/
71 EFI_STATUS
72 DhcpSetState (
73 IN OUT DHCP_SERVICE *DhcpSb,
74 IN INTN State,
75 IN BOOLEAN CallUser
76 );
77
78 /**
79 Build and transmit a DHCP message according to the current states.
80 This function implement the Table 5. of RFC 2131. Always transits
81 the state (as defined in Figure 5. of the same RFC) before sending
82 a DHCP message. The table is adjusted accordingly.
83
84 @param[in] DhcpSb The DHCP service instance
85 @param[in] Seed The seed packet which the new packet is based on
86 @param[in] Para The DHCP parameter of the Seed packet
87 @param[in] Type The message type to send
88 @param[in] Msg The human readable message to include in the packet
89 sent.
90
91 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources for the packet
92 @retval EFI_ACCESS_DENIED Failed to transmit the packet through UDP
93 @retval EFI_SUCCESS The message is sent
94 @retval other Other error occurs
95
96 **/
97 EFI_STATUS
98 DhcpSendMessage (
99 IN DHCP_SERVICE *DhcpSb,
100 IN EFI_DHCP4_PACKET *Seed,
101 IN DHCP_PARAMETER *Para,
102 IN UINT8 Type,
103 IN UINT8 *Msg
104 );
105
106 /**
107 Each DHCP service has three timer. Two of them are count down timer.
108 One for the packet retransmission. The other is to collect the offers.
109 The third timer increments the lease life which is compared to T1, T2,
110 and lease to determine the time to renew and rebind the lease.
111 DhcpOnTimerTick will be called once every second.
112
113 @param[in] Event The timer event
114 @param[in] Context The context, which is the DHCP service instance.
115
116 **/
117 VOID
118 EFIAPI
119 DhcpOnTimerTick (
120 IN EFI_EVENT Event,
121 IN VOID *Context
122 );
123
124 /**
125 Handle the received DHCP packets. This function drives the DHCP
126 state machine.
127
128 @param UdpPacket The UDP packets received.
129 @param EndPoint The local/remote UDP access point
130 @param IoStatus The status of the UDP receive
131 @param Context The opaque parameter to the function.
132
133 **/
134 VOID
135 EFIAPI
136 DhcpInput (
137 NET_BUF *UdpPacket,
138 UDP_END_POINT *EndPoint,
139 EFI_STATUS IoStatus,
140 VOID *Context
141 );
142
143 /**
144 Send an initial DISCOVER or REQUEST message according to the
145 DHCP service's current state.
146
147 @param[in] DhcpSb The DHCP service instance
148
149 @retval EFI_SUCCESS The request has been sent
150 @retval other Some error occurs when sending the request.
151
152 **/
153 EFI_STATUS
154 DhcpInitRequest (
155 IN DHCP_SERVICE *DhcpSb
156 );
157
158 /**
159 Clean up the DHCP related states, IoStatus isn't reset.
160
161 @param DhcpSb The DHCP instance service.
162
163 **/
164 VOID
165 DhcpCleanLease (
166 IN DHCP_SERVICE *DhcpSb
167 );
168
169 /**
170 Release the net buffer when packet is sent.
171
172 @param UdpPacket The UDP packets received.
173 @param EndPoint The local/remote UDP access point
174 @param IoStatus The status of the UDP receive
175 @param Context The opaque parameter to the function.
176
177 **/
178 VOID
179 EFIAPI
180 DhcpOnPacketSent (
181 NET_BUF *Packet,
182 UDP_END_POINT *EndPoint,
183 EFI_STATUS IoStatus,
184 VOID *Context
185 );
186
187 #endif