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