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