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