]>
Commit | Line | Data |
---|---|---|
83cbd279 | 1 | /** @file\r |
6c585b52 | 2 | Ip4 internal functions and type definitions.\r |
d1102dba | 3 | \r |
018432f0 | 4 | Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>\r |
c79de074 SEHM |
5 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r |
6 | \r | |
9d510e61 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
83cbd279 | 8 | \r |
83cbd279 | 9 | **/\r |
10 | \r | |
11 | #ifndef __EFI_IP4_IMPL_H__\r | |
12 | #define __EFI_IP4_IMPL_H__\r | |
13 | \r | |
2517435c | 14 | #include <Uefi.h>\r |
772db4bb | 15 | \r |
a1503a32 | 16 | #include <Protocol/IpSec.h>\r |
5f778b1f | 17 | #include <Protocol/Ip4.h>\r |
1f6729ff | 18 | #include <Protocol/Ip4Config2.h>\r |
772db4bb | 19 | #include <Protocol/Arp.h>\r |
20 | #include <Protocol/ManagedNetwork.h>\r | |
1f6729ff | 21 | #include <Protocol/Dhcp4.h>\r |
22 | #include <Protocol/HiiConfigRouting.h>\r | |
23 | #include <Protocol/HiiConfigAccess.h>\r | |
772db4bb | 24 | \r |
ac6c3d90 ZL |
25 | #include <IndustryStandard/Dhcp.h>\r |
26 | \r | |
772db4bb | 27 | #include <Library/DebugLib.h>\r |
28 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
29 | #include <Library/UefiDriverEntryPoint.h>\r | |
30 | #include <Library/UefiBootServicesTableLib.h>\r | |
31 | #include <Library/BaseLib.h>\r | |
83cbd279 | 32 | #include <Library/UefiLib.h>\r |
33 | #include <Library/NetLib.h>\r | |
34 | #include <Library/BaseMemoryLib.h>\r | |
35 | #include <Library/MemoryAllocationLib.h>\r | |
d8d26fb2 | 36 | #include <Library/DpcLib.h>\r |
216f7970 | 37 | #include <Library/PrintLib.h>\r |
1f6729ff | 38 | #include <Library/DevicePathLib.h>\r |
39 | #include <Library/HiiLib.h>\r | |
40 | #include <Library/UefiHiiServicesLib.h>\r | |
83cbd279 | 41 | \r |
42 | #include "Ip4Common.h"\r | |
43 | #include "Ip4Driver.h"\r | |
44 | #include "Ip4If.h"\r | |
45 | #include "Ip4Icmp.h"\r | |
46 | #include "Ip4Option.h"\r | |
47 | #include "Ip4Igmp.h"\r | |
48 | #include "Ip4Route.h"\r | |
49 | #include "Ip4Input.h"\r | |
50 | #include "Ip4Output.h"\r | |
1f6729ff | 51 | #include "Ip4Config2Impl.h"\r |
52 | #include "Ip4Config2Nv.h"\r | |
53 | #include "Ip4NvData.h"\r | |
83cbd279 | 54 | \r |
f6b7393c | 55 | #define IP4_PROTOCOL_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'P')\r |
56 | #define IP4_SERVICE_SIGNATURE SIGNATURE_32 ('I', 'P', '4', 'S')\r | |
c6bc765f | 57 | \r |
f6b7393c | 58 | //\r |
59 | // The state of IP4 protocol. It starts from UNCONFIGED. if it is\r | |
60 | // successfully configured, it goes to CONFIGED. if configure NULL\r | |
4bb89650 | 61 | // is called, it becomes UNCONFIGED again.\r |
f6b7393c | 62 | //\r |
d1050b9d MK |
63 | #define IP4_STATE_UNCONFIGED 0\r |
64 | #define IP4_STATE_CONFIGED 1\r | |
c6bc765f | 65 | \r |
f6b7393c | 66 | //\r |
67 | // The state of IP4 service. It starts from UNSTARTED. It transits\r | |
68 | // to STARTED if autoconfigure is started. If default address is\r | |
75dce340 | 69 | // configured, it becomes CONFIGED. and if partly destroyed, it goes\r |
70 | // to DESTROY.\r | |
f6b7393c | 71 | //\r |
d1050b9d MK |
72 | #define IP4_SERVICE_UNSTARTED 0\r |
73 | #define IP4_SERVICE_STARTED 1\r | |
74 | #define IP4_SERVICE_CONFIGED 2\r | |
75 | #define IP4_SERVICE_DESTROY 3\r | |
83cbd279 | 76 | \r |
96e1079f | 77 | ///\r |
78 | /// IP4_TXTOKEN_WRAP wraps the upper layer's transmit token.\r | |
79 | /// The user's data is kept in the Packet. When fragment is\r | |
80 | /// needed, each fragment of the Packet has a reference to the\r | |
81 | /// Packet, no data is actually copied. The Packet will be\r | |
82 | /// released when all the fragments of it have been recycled by\r | |
83 | /// MNP. Upon then, the IP4_TXTOKEN_WRAP will be released, and\r | |
84 | /// user's event signalled.\r | |
85 | ///\r | |
83cbd279 | 86 | typedef struct {\r |
d1050b9d MK |
87 | IP4_PROTOCOL *IpInstance;\r |
88 | EFI_IP4_COMPLETION_TOKEN *Token;\r | |
89 | EFI_EVENT IpSecRecycleSignal;\r | |
90 | NET_BUF *Packet;\r | |
91 | BOOLEAN Sent;\r | |
92 | INTN Life;\r | |
83cbd279 | 93 | } IP4_TXTOKEN_WRAP;\r |
94 | \r | |
a1503a32 | 95 | ///\r |
96 | /// IP4_IPSEC_WRAP wraps the packet received from MNP layer. The packet\r | |
97 | /// will be released after it has been processed by the receiver. Upon then,\r | |
98 | /// the IP4_IPSEC_WRAP will be released, and the IpSecRecycleSignal will be signaled\r | |
99 | /// to notice IPsec to free the resources.\r | |
100 | ///\r | |
101 | typedef struct {\r | |
d1050b9d MK |
102 | EFI_EVENT IpSecRecycleSignal;\r |
103 | NET_BUF *Packet;\r | |
a1503a32 | 104 | } IP4_IPSEC_WRAP;\r |
105 | \r | |
96e1079f | 106 | ///\r |
107 | /// IP4_RXDATA_WRAP wraps the data IP4 child delivers to the\r | |
108 | /// upper layers. The received packet is kept in the Packet.\r | |
109 | /// The Packet itself may be constructured from some fragments.\r | |
110 | /// All the fragments of the Packet is organized by a\r | |
111 | /// IP4_ASSEMBLE_ENTRY structure. If the Packet is recycled by\r | |
112 | /// the upper layer, the assemble entry and its associated\r | |
113 | /// fragments will be freed at last.\r | |
114 | ///\r | |
83cbd279 | 115 | typedef struct {\r |
d1050b9d MK |
116 | LIST_ENTRY Link;\r |
117 | IP4_PROTOCOL *IpInstance;\r | |
118 | NET_BUF *Packet;\r | |
119 | EFI_IP4_RECEIVE_DATA RxData;\r | |
83cbd279 | 120 | } IP4_RXDATA_WRAP;\r |
121 | \r | |
c6bc765f | 122 | struct _IP4_PROTOCOL {\r |
d1050b9d | 123 | UINT32 Signature;\r |
83cbd279 | 124 | \r |
d1050b9d MK |
125 | EFI_IP4_PROTOCOL Ip4Proto;\r |
126 | EFI_HANDLE Handle;\r | |
127 | INTN State;\r | |
83cbd279 | 128 | \r |
d1050b9d | 129 | BOOLEAN InDestroy;\r |
4bb89650 | 130 | \r |
d1050b9d MK |
131 | IP4_SERVICE *Service;\r |
132 | LIST_ENTRY Link; // Link to all the IP protocol from the service\r | |
83cbd279 | 133 | \r |
134 | //\r | |
6c585b52 | 135 | // User's transmit/receive tokens, and received/delivered packets\r |
83cbd279 | 136 | //\r |
d1050b9d MK |
137 | NET_MAP RxTokens;\r |
138 | NET_MAP TxTokens; // map between (User's Token, IP4_TXTOKE_WRAP)\r | |
139 | LIST_ENTRY Received; // Received but not delivered packet\r | |
140 | LIST_ENTRY Delivered; // Delivered and to be recycled packets\r | |
141 | EFI_LOCK RecycleLock;\r | |
83cbd279 | 142 | \r |
143 | //\r | |
144 | // Instance's address and route tables. There are two route tables.\r | |
145 | // RouteTable is used by the IP4 driver to route packet. EfiRouteTable\r | |
146 | // is used to communicate the current route info to the upper layer.\r | |
147 | //\r | |
d1050b9d MK |
148 | IP4_INTERFACE *Interface;\r |
149 | LIST_ENTRY AddrLink; // Ip instances with the same IP address.\r | |
150 | IP4_ROUTE_TABLE *RouteTable;\r | |
83cbd279 | 151 | \r |
d1050b9d MK |
152 | EFI_IP4_ROUTE_TABLE *EfiRouteTable;\r |
153 | UINT32 EfiRouteCount;\r | |
83cbd279 | 154 | \r |
155 | //\r | |
156 | // IGMP data for this instance\r | |
157 | //\r | |
d1050b9d MK |
158 | IP4_ADDR *Groups; // stored in network byte order\r |
159 | UINT32 GroupCount;\r | |
83cbd279 | 160 | \r |
d1050b9d | 161 | EFI_IP4_CONFIG_DATA ConfigData;\r |
c6bc765f | 162 | };\r |
83cbd279 | 163 | \r |
c6bc765f | 164 | struct _IP4_SERVICE {\r |
d1050b9d MK |
165 | UINT32 Signature;\r |
166 | EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;\r | |
167 | INTN State;\r | |
83cbd279 | 168 | \r |
169 | //\r | |
170 | // List of all the IP instances and interfaces, and default\r | |
171 | // interface and route table and caches.\r | |
172 | //\r | |
d1050b9d MK |
173 | UINTN NumChildren;\r |
174 | LIST_ENTRY Children;\r | |
83cbd279 | 175 | \r |
d1050b9d | 176 | LIST_ENTRY Interfaces;\r |
83cbd279 | 177 | \r |
d1050b9d MK |
178 | IP4_INTERFACE *DefaultInterface;\r |
179 | IP4_ROUTE_TABLE *DefaultRouteTable;\r | |
83cbd279 | 180 | \r |
181 | //\r | |
182 | // Ip reassemble utilities, and IGMP data\r | |
183 | //\r | |
d1050b9d MK |
184 | IP4_ASSEMBLE_TABLE Assemble;\r |
185 | IGMP_SERVICE_DATA IgmpCtrl;\r | |
83cbd279 | 186 | \r |
187 | //\r | |
188 | // Low level protocol used by this service instance\r | |
189 | //\r | |
d1050b9d MK |
190 | EFI_HANDLE Image;\r |
191 | EFI_HANDLE Controller;\r | |
83cbd279 | 192 | \r |
d1050b9d MK |
193 | EFI_HANDLE MnpChildHandle;\r |
194 | EFI_MANAGED_NETWORK_PROTOCOL *Mnp;\r | |
83cbd279 | 195 | \r |
d1050b9d MK |
196 | EFI_MANAGED_NETWORK_CONFIG_DATA MnpConfigData;\r |
197 | EFI_SIMPLE_NETWORK_MODE SnpMode;\r | |
83cbd279 | 198 | \r |
d1050b9d MK |
199 | EFI_EVENT Timer;\r |
200 | EFI_EVENT ReconfigCheckTimer;\r | |
201 | EFI_EVENT ReconfigEvent;\r | |
2c320007 | 202 | \r |
d1050b9d | 203 | BOOLEAN Reconfig;\r |
e371cc14 | 204 | \r |
2c320007 | 205 | //\r |
d1102dba | 206 | // Underlying media present status.\r |
2c320007 | 207 | //\r |
d1050b9d | 208 | BOOLEAN MediaPresent;\r |
2c320007 | 209 | \r |
83cbd279 | 210 | //\r |
1f6729ff | 211 | // IPv4 Configuration II Protocol instance\r |
83cbd279 | 212 | //\r |
d1050b9d | 213 | IP4_CONFIG2_INSTANCE Ip4Config2Instance;\r |
1f6729ff | 214 | \r |
d1050b9d | 215 | CHAR16 *MacString;\r |
83cbd279 | 216 | \r |
d1050b9d MK |
217 | UINT32 MaxPacketSize;\r |
218 | UINT32 OldMaxPacketSize; ///< The MTU before IPsec enable.\r | |
c6bc765f | 219 | };\r |
83cbd279 | 220 | \r |
221 | #define IP4_INSTANCE_FROM_PROTOCOL(Ip4) \\r | |
222 | CR ((Ip4), IP4_PROTOCOL, Ip4Proto, IP4_PROTOCOL_SIGNATURE)\r | |
223 | \r | |
224 | #define IP4_SERVICE_FROM_PROTOCOL(Sb) \\r | |
225 | CR ((Sb), IP4_SERVICE, ServiceBinding, IP4_SERVICE_SIGNATURE)\r | |
226 | \r | |
1f6729ff | 227 | #define IP4_SERVICE_FROM_CONFIG2_INSTANCE(This) \\r |
228 | CR (This, IP4_SERVICE, Ip4Config2Instance, IP4_SERVICE_SIGNATURE)\r | |
229 | \r | |
d1050b9d | 230 | #define IP4_NO_MAPPING(IpInstance) (!(IpInstance)->Interface->Configured)\r |
1f6729ff | 231 | \r |
d1050b9d | 232 | extern EFI_IP4_PROTOCOL mEfiIp4ProtocolTemplete;\r |
83cbd279 | 233 | \r |
2ff29212 | 234 | /**\r |
235 | Config the MNP parameter used by IP. The IP driver use one MNP\r | |
236 | child to transmit/receive frames. By default, it configures MNP\r | |
237 | to receive unicast/multicast/broadcast. And it will enable/disable\r | |
238 | the promiscous receive according to whether there is IP child\r | |
239 | enable that or not. If Force is FALSE, it will iterate through\r | |
240 | all the IP children to check whether the promiscuous receive\r | |
241 | setting has been changed. If it hasn't been changed, it won't\r | |
242 | reconfigure the MNP. If Force is TRUE, the MNP is configured no\r | |
243 | matter whether that is changed or not.\r | |
244 | \r | |
3e8c18da | 245 | @param[in] IpSb The IP4 service instance that is to be changed.\r |
246 | @param[in] Force Force the configuration or not.\r | |
2ff29212 | 247 | \r |
248 | @retval EFI_SUCCESS The MNP is successfully configured/reconfigured.\r | |
249 | @retval Others Configuration failed.\r | |
250 | \r | |
251 | **/\r | |
83cbd279 | 252 | EFI_STATUS\r |
253 | Ip4ServiceConfigMnp (\r | |
d1050b9d MK |
254 | IN IP4_SERVICE *IpSb,\r |
255 | IN BOOLEAN Force\r | |
83cbd279 | 256 | );\r |
257 | \r | |
2ff29212 | 258 | /**\r |
6c585b52 | 259 | Initialize the IP4_PROTOCOL structure to the unconfigured states.\r |
2ff29212 | 260 | \r |
261 | @param IpSb The IP4 service instance.\r | |
262 | @param IpInstance The IP4 child instance.\r | |
263 | \r | |
2ff29212 | 264 | **/\r |
83cbd279 | 265 | VOID\r |
266 | Ip4InitProtocol (\r | |
d1050b9d MK |
267 | IN IP4_SERVICE *IpSb,\r |
268 | IN OUT IP4_PROTOCOL *IpInstance\r | |
83cbd279 | 269 | );\r |
270 | \r | |
2ff29212 | 271 | /**\r |
272 | Clean up the IP4 child, release all the resources used by it.\r | |
273 | \r | |
3e8c18da | 274 | @param[in] IpInstance The IP4 child to clean up.\r |
2ff29212 | 275 | \r |
1f6729ff | 276 | @retval EFI_SUCCESS The IP4 child is cleaned up.\r |
277 | @retval EFI_DEVICE_ERROR Some resources failed to be released.\r | |
2ff29212 | 278 | \r |
279 | **/\r | |
83cbd279 | 280 | EFI_STATUS\r |
281 | Ip4CleanProtocol (\r | |
d1050b9d | 282 | IN IP4_PROTOCOL *IpInstance\r |
83cbd279 | 283 | );\r |
284 | \r | |
2ff29212 | 285 | /**\r |
286 | Cancel the user's receive/transmit request.\r | |
287 | \r | |
1f6729ff | 288 | @param[in] IpInstance The IP4 child.\r |
3e8c18da | 289 | @param[in] Token The token to cancel. If NULL, all token will be\r |
2ff29212 | 290 | cancelled.\r |
291 | \r | |
1f6729ff | 292 | @retval EFI_SUCCESS The token is cancelled.\r |
2ff29212 | 293 | @retval EFI_NOT_FOUND The token isn't found on either the\r |
1f6729ff | 294 | transmit/receive queue.\r |
2ff29212 | 295 | @retval EFI_DEVICE_ERROR Not all token is cancelled when Token is NULL.\r |
296 | \r | |
297 | **/\r | |
83cbd279 | 298 | EFI_STATUS\r |
299 | Ip4Cancel (\r | |
d1050b9d MK |
300 | IN IP4_PROTOCOL *IpInstance,\r |
301 | IN EFI_IP4_COMPLETION_TOKEN *Token OPTIONAL\r | |
83cbd279 | 302 | );\r |
303 | \r | |
2ff29212 | 304 | /**\r |
305 | Change the IP4 child's multicast setting. The caller\r | |
306 | should make sure that the parameters is valid.\r | |
307 | \r | |
3e8c18da | 308 | @param[in] IpInstance The IP4 child to change the setting.\r |
309 | @param[in] JoinFlag TRUE to join the group, otherwise leave it\r | |
310 | @param[in] GroupAddress The target group address\r | |
2ff29212 | 311 | \r |
312 | @retval EFI_ALREADY_STARTED Want to join the group, but already a member of it\r | |
313 | @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.\r | |
6c585b52 | 314 | @retval EFI_DEVICE_ERROR Failed to set the group configuration\r |
2ff29212 | 315 | @retval EFI_SUCCESS Successfully updated the group setting.\r |
316 | @retval EFI_NOT_FOUND Try to leave the group which it isn't a member.\r | |
317 | \r | |
318 | **/\r | |
83cbd279 | 319 | EFI_STATUS\r |
320 | Ip4Groups (\r | |
d1050b9d MK |
321 | IN IP4_PROTOCOL *IpInstance,\r |
322 | IN BOOLEAN JoinFlag,\r | |
323 | IN EFI_IPv4_ADDRESS *GroupAddress OPTIONAL\r | |
83cbd279 | 324 | );\r |
325 | \r | |
2ff29212 | 326 | /**\r |
d1102dba LG |
327 | This heart beat timer of IP4 service instance times out all of its IP4 children's\r |
328 | received-but-not-delivered and transmitted-but-not-recycle packets, and provides\r | |
018432f0 | 329 | time input for its IGMP protocol.\r |
2ff29212 | 330 | \r |
3e8c18da | 331 | @param[in] Event The IP4 service instance's heart beat timer.\r |
332 | @param[in] Context The IP4 service instance.\r | |
2ff29212 | 333 | \r |
334 | **/\r | |
83cbd279 | 335 | VOID\r |
336 | EFIAPI\r | |
337 | Ip4TimerTicking (\r | |
d1050b9d MK |
338 | IN EFI_EVENT Event,\r |
339 | IN VOID *Context\r | |
83cbd279 | 340 | );\r |
341 | \r | |
018432f0 | 342 | /**\r |
d1102dba LG |
343 | This dedicated timer is used to poll underlying network media status. In case\r |
344 | of cable swap or wireless network switch, a new round auto configuration will\r | |
345 | be initiated. The timer will signal the IP4 to run DHCP configuration again.\r | |
346 | IP4 driver will free old IP address related resource, such as route table and\r | |
347 | Interface, then initiate a DHCP process to acquire new IP, eventually create\r | |
018432f0 WF |
348 | route table for new IP address.\r |
349 | \r | |
350 | @param[in] Event The IP4 service instance's heart beat timer.\r | |
351 | @param[in] Context The IP4 service instance.\r | |
352 | \r | |
353 | **/\r | |
354 | VOID\r | |
355 | EFIAPI\r | |
356 | Ip4TimerReconfigChecking (\r | |
d1050b9d MK |
357 | IN EFI_EVENT Event,\r |
358 | IN VOID *Context\r | |
018432f0 WF |
359 | );\r |
360 | \r | |
2ff29212 | 361 | /**\r |
362 | Decrease the life of the transmitted packets. If it is\r | |
363 | decreased to zero, cancel the packet. This function is\r | |
364 | called by Ip4PacketTimerTicking which time out both the\r | |
365 | received-but-not-delivered and transmitted-but-not-recycle\r | |
366 | packets.\r | |
367 | \r | |
3e8c18da | 368 | @param[in] Map The IP4 child's transmit map.\r |
1f6729ff | 369 | @param[in] Item Current transmitted packet.\r |
3e8c18da | 370 | @param[in] Context Not used.\r |
2ff29212 | 371 | \r |
1f6729ff | 372 | @retval EFI_SUCCESS Always returns EFI_SUCCESS.\r |
2ff29212 | 373 | \r |
374 | **/\r | |
83cbd279 | 375 | EFI_STATUS\r |
e798cd87 | 376 | EFIAPI\r |
83cbd279 | 377 | Ip4SentPacketTicking (\r |
d1050b9d MK |
378 | IN NET_MAP *Map,\r |
379 | IN NET_MAP_ITEM *Item,\r | |
380 | IN VOID *Context\r | |
83cbd279 | 381 | );\r |
a1503a32 | 382 | \r |
383 | /**\r | |
384 | The callback function for the net buffer which wraps the user's\r | |
385 | transmit token. Although it seems this function is pretty simple,\r | |
386 | there are some subtle things.\r | |
387 | When user requests the IP to transmit a packet by passing it a\r | |
388 | token, the token is wrapped in an IP4_TXTOKEN_WRAP and the data\r | |
389 | is wrapped in an net buffer. the net buffer's Free function is\r | |
390 | set to Ip4FreeTxToken. The Token and token wrap are added to the\r | |
391 | IP child's TxToken map. Then the buffer is passed to Ip4Output for\r | |
392 | transmission. If something error happened before that, the buffer\r | |
393 | is freed, which in turn will free the token wrap. The wrap may\r | |
394 | have been added to the TxToken map or not, and the user's event\r | |
395 | shouldn't be fired because we are still in the EfiIp4Transmit. If\r | |
396 | the buffer has been sent by Ip4Output, it should be removed from\r | |
397 | the TxToken map and user's event signaled. The token wrap and buffer\r | |
398 | are bound together. Check the comments in Ip4Output for information\r | |
399 | about IP fragmentation.\r | |
400 | \r | |
1f6729ff | 401 | @param[in] Context The token's wrap.\r |
a1503a32 | 402 | \r |
403 | **/\r | |
404 | VOID\r | |
e798cd87 | 405 | EFIAPI\r |
a1503a32 | 406 | Ip4FreeTxToken (\r |
d1050b9d | 407 | IN VOID *Context\r |
a1503a32 | 408 | );\r |
409 | \r | |
d1050b9d MK |
410 | extern EFI_IPSEC2_PROTOCOL *mIpSec;\r |
411 | extern BOOLEAN mIpSec2Installed;\r | |
a1503a32 | 412 | \r |
83cbd279 | 413 | #endif\r |